12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012 |
- package controllers
-
- import (
- "encoding/json"
- "math"
- "math/rand"
- "reflect"
- "regexp"
- "strconv"
- "strings"
- "time"
-
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "github.com/jinzhu/gorm"
- "github.com/mozillazg/go-pinyin"
-
- "fmt"
-
- "github.com/astaxie/beego"
- )
-
- type PatientApiController struct {
- BaseAuthAPIController
- }
-
- func PatientApiRegistRouters() {
- beego.Router("/api/patients", &PatientApiController{}, "get:GetPatientsList")
- beego.Router("/api/patients/all", &PatientApiController{}, "get:GetPatientsAllList")
- beego.Router("/api/patients/generatedialysisno", &PatientApiController{}, "get:GenerateDialysisNo")
- beego.Router("/api/patients/create", &PatientApiController{}, "Post:CreatePatient")
- beego.Router("/api/patients/total", &PatientApiController{}, "Get:GetPatientTotal")
- beego.Router("/api/patients/get", &PatientApiController{}, "Get:GetPatient")
- beego.Router("/api/patients/edit", &PatientApiController{}, "Put:EditPatient")
- beego.Router("/api/patients/dialysissolution/create", &PatientApiController{}, "Post:CreateDialysisSolution")
- beego.Router("/api/patients/dialysissolution/edit", &PatientApiController{}, "Put:UpdateDialysisSolution")
- beego.Router("/api/patients/dialysissolutions", &PatientApiController{}, "get:GetPatientDialysisSolutionList")
- beego.Router("/api/patients/dialysissolution/detail/edit", &PatientApiController{}, "Put:UpdateDialysisSolutionDetail")
- // beego.Router("/api/patients/dialysissolution/delete", &PatientApiController{}, "Delete:DeleteDialysisSolution")
-
- beego.Router("/api/patients/dryweight/get", &PatientApiController{}, "get:GetDryWeights")
- beego.Router("/api/patients/dryweight/create", &PatientApiController{}, "Post:CreateDryWeights")
-
- beego.Router("/api/patients/advice/create", &PatientApiController{}, "Post:CreateDoctorAdvice")
- beego.Router("/api/patients/advice/edit", &PatientApiController{}, "Put:UpdateDoctorAdvice")
- beego.Router("/api/patients/advice/exec", &PatientApiController{}, "Post:ExecDoctorAdvice")
- beego.Router("/api/patients/advice/check", &PatientApiController{}, "Post:CheckDoctorAdvice")
- beego.Router("/api/patients/advices", &PatientApiController{}, "Get:GetDoctorAdvices")
- beego.Router("/api/patients/advice/stop", &PatientApiController{}, "Post:StopDoctorAdvice")
- beego.Router("/api/patients/advice/delete", &PatientApiController{}, "Delete:DeleteDoctorAdvice")
- beego.Router("/api/patients/advice/creategroup", &PatientApiController{}, "Post:CreateGroupAdvice")
- beego.Router("/api/patients/advice/deletegroup", &PatientApiController{}, "Delete:DeleteGroupAdvice")
- beego.Router("/api/patients/advice/stopgroup", &PatientApiController{}, "Post:StopGroupAdvice")
- beego.Router("/api/patients/advice/execgroup", &PatientApiController{}, "Post:ExecGroupAdvice")
- beego.Router("/api/patients/advice/checkgroup", &PatientApiController{}, "Post:CheckGroupAdvice")
-
- beego.Router("/api/patients/schedules", &PatientApiController{}, "Get:GetPatientSchedules")
- beego.Router("/api/patients/dialysisrecords", &PatientApiController{}, "Get:GetPatientDialysisRecords")
- beego.Router("/api/patients/proeducation", &PatientApiController{}, "Get:ProEducation")
- beego.Router("/api/patients/lapseto/edit", &PatientApiController{}, "Post:EditLapseto")
-
- beego.Router("/api/patients/search", &PatientApiController{}, "Post:GetPatientsByKeyWord")
-
- beego.Router("/api/patients/querypatientbyId", &PatientApiController{}, "Get:QueryPatientById")
-
- beego.Router("/api/infectious/remind", &PatientApiController{}, "Get:GetRemindPatientList")
-
- beego.Router("/api/remind/is_open", &PatientApiController{}, "Post:PostIsOpenRemind")
- beego.Router("/api/patients/advices/getpatientschedules", &PatientApiController{}, "Get:GetPatientScheduleOne")
-
- beego.Router("/api/patients/export", &PatientApiController{}, "Post:ExportPatients")
-
- beego.Router("/api/patients/advices/saveditadvices", &PatientApiController{}, "Get:SaveEditAdvices")
-
- beego.Router("/api/patients/dialysis_no", &PatientApiController{}, "Get:GetMaxDialysisNo")
-
- beego.Router("/api/patients/banner", &PatientApiController{}, "Get:GetBanner")
-
- //长期医嘱新接口
- beego.Router("/api/patient/findepatientdialysislongsolutions", &PatientApiController{}, "Get:GetPatientDialysisLongSolution")
- beego.Router("/api/patient/getdialysissolutiondetaillist", &PatientApiController{}, "Get:GetDialysisSolutionDetailList")
-
- beego.Router("/api/patient/getexportlist", &PatientApiController{}, "Get:GetExportList")
-
- beego.Router("/api/patient/savefalloutbedprint", &PatientApiController{}, "Post:SaveFallOutBedPrint")
-
- beego.Router("/api/patient/getfalloutbedprintlist", &PatientApiController{}, "Get:GetFallOutBedPrintList")
-
- beego.Router("/api/patient/savefilterinformed", &PatientApiController{}, "Post:SaveFilterInformed")
-
- beego.Router("/api/patient/getfilterinformed", &PatientApiController{}, "Get:GetFilterInformed")
-
- beego.Router("/api/patient/saveprofundainformed", &PatientApiController{}, "Post:SaveProfundaInformed")
-
- beego.Router("/api/patient/getprofundainformed", &PatientApiController{}, "Get:GetProfundaInformed")
-
- beego.Router("/api/patient/arterovenous", &PatientApiController{}, "Post:SaveArterOvenous")
-
- beego.Router("/api/patient/getarterovernous", &PatientApiController{}, "Get:GetArterOverNous")
-
- beego.Router("/api/patient/savehighrikinformed", &PatientApiController{}, "Post:SaveHighRikInformed")
-
- beego.Router("/api/patient/gethighriskinformed", &PatientApiController{}, "Get:GetHighRiskInformed")
-
- beego.Router("/api/patient/saveanticoagulation", &PatientApiController{}, "Post:SaveAnticoagulation")
-
- beego.Router("/api/patient/getanticoagulationInformed", &PatientApiController{}, "Get:GetAnticoagulationInformed")
-
- beego.Router("/api/patient/savecriticalinfomed", &PatientApiController{}, "Post:SaveCriticalInfomed")
-
- beego.Router("/api/patient/getcriticalinformed", &PatientApiController{}, "Get:GetCriticalInformed")
-
- beego.Router("/api/patient/savehemoperfusioninformed", &PatientApiController{}, "Post:SaveHemoperfusionInformed")
-
- beego.Router("/api/patient/gethemoperfusioninformed", &PatientApiController{}, "Get:GetHemoperfusionInformed")
-
- beego.Router("/api/patient/savebringinformed", &PatientApiController{}, "Post:SaveBringInformed")
-
- beego.Router("/api/patient/getinformedcontsent", &PatientApiController{}, "Get:GetInformedContsent")
-
- beego.Router("/api/patient/savecatheterization", &PatientApiController{}, "Post:SaveCatheterization")
-
- beego.Router("/api/patient/getcatheterization", &PatientApiController{}, "Get:GetCatheterization")
-
- beego.Router("/api/patient/savedialyzerInformed", &PatientApiController{}, "Post:SaveDialyzerInformed")
-
- beego.Router("/api/patient/getdialyzerinformed", &PatientApiController{}, "Get:GetDialyzerInformed")
-
- beego.Router("/api/patient/savetheapyinformed", &PatientApiController{}, "Post:SaveTheapyInformed")
-
- beego.Router("/api/patient/savetreamentplan", &PatientApiController{}, "Post:SaveTreatmentPlan")
-
- beego.Router("api/patient/gettherapyinformed", &PatientApiController{}, "Get:GetTherapyInformed")
-
- beego.Router("/api/patient/savemedicalhistory", &PatientApiController{}, "Post:SaveMedicalHistory")
-
- beego.Router("/api/patient/savepatientcritaicalinformed", &PatientApiController{}, "Post:SavePatientCritaicalInformed")
-
- beego.Router("/api/patient/getPatientCriticalList", &PatientApiController{}, "Get:GetPatientCriticalList")
-
- beego.Router("/api/patient/savepatientcriticalcalinformedone", &PatientApiController{}, "Post:SavePatientCriticalInformedOne")
-
- beego.Router("/api/patient/getpatientcriticalonelist", &PatientApiController{}, "Get:GetPatientCriticalOneList")
-
- beego.Router("/api/patient/deletesolution", &PatientApiController{}, "Get:DeleteSolution")
-
- beego.Router("/api/patient/gettreamentplan", &PatientApiController{}, "Get:GetTreatMentPlanList")
-
- beego.Router("/api/patient/getpatientbypatientid", &PatientApiController{}, "Get:GetPatientByPatientId")
-
- beego.Router("/api/patient/savepatientlapse", &PatientApiController{}, "Post:SavePatientLapse")
-
- beego.Router("/api/patient/getpatientlapsorecord", &PatientApiController{}, "Get:GetPatientLapsorecord")
-
- beego.Router("/api/patient/getpatientlapserecord", &DialysisApiController{}, "Get:GetPatientLapseRecord")
-
- beego.Router("/api/patient/updatepatientlapserecord", &DialysisApiController{}, "Post:UpdatePatientLapseRecord")
-
- beego.Router("/api/patient/deletepatientlapsorecord", &DialysisApiController{}, "Get:DeletePatientLapseRecord")
-
- beego.Router("/api/patient/getpatientlapeso", &DialysisApiController{}, "Get:GetPatientLapseList")
-
- }
- func (c *PatientApiController) GetExportList() {
- startTime := c.GetString("start_time")
- endTime := c.GetString("end_time")
- schedulType, _ := c.GetInt64("schedul_type", 0)
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- adminUserInfo := c.GetAdminUserInfo()
- var theStartTIme int64
- if len(startTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- theStartTIme = theTime.Unix()
- }
-
- var theEndtTIme int64
- if len(endTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- theEndtTIme = theTime.Unix()
- }
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
- schedule, _ := service.GetPatientScheudleListTwenty(adminUserInfo.CurrentOrgId, schedulType, theStartTIme, theEndtTIme, timeNewDate.Unix())
- fmt.Println("schedule23333333333333333", schedule)
- patientsList, _ := service.GetAllpatient(adminUserInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "schedule": schedule,
- "patientsList": patientsList,
- })
- return
- }
-
- // GetPatientsList 取患者列表
- func (c *PatientApiController) GetPatientsList() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
- }
- }()
- page, _ := c.GetInt64("page", 1)
- limit, _ := c.GetInt64("limit", 10)
- schedulType, _ := c.GetInt64("schedul_type", 0)
- bindingState, _ := c.GetInt64("binding_state", 0)
- lapseto, _ := c.GetInt64("lapseto", 0)
- source, _ := c.GetInt64("source", 0)
- startTime := c.GetString("start_time", "")
- endTime := c.GetString("end_time", "")
- keywords := c.GetString("keywords", "")
- contagion, _ := c.GetInt64("contagion", 0)
- reimbursement_way, _ := c.GetInt64("reimbursement_way", 0)
- isscheduling, _ := c.GetInt64("isscheduling", 0)
- isprescription, _ := c.GetInt64("isprescription", 0)
- patientSoureType, _ := c.GetInt64("patientSoureType")
- nurse, _ := c.GetInt64("nurse")
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var isStartTime bool
- var theStartTIme int64
- if len(startTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- isStartTime = true
- theStartTIme = theTime.Unix()
- }
- var isEndTime bool
- var theEndtTIme int64
- if len(endTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- isEndTime = true
- theEndtTIme = theTime.Unix()
- }
-
- var patients []*models.Patients
- var total int64
- 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)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": patients,
- "total": total,
- })
- return
-
- }
-
- // GetPatientTotal
- func (c *PatientApiController) GetPatientTotal() {
- adminUserInfo := c.GetAdminUserInfo()
-
- total := service.GetPatientCount(adminUserInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- })
- return
- }
-
- func (c *PatientApiController) GetPatientsAllList() {
-
- adminUserInfo := c.GetAdminUserInfo()
-
- patients, total, _ := service.GetAllPatientList(adminUserInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": patients,
- "total": total,
- })
- return
- }
-
- // GenerateDialysisNo 生成透析号
- func (c *PatientApiController) GenerateDialysisNo() {
- adminUserInfo := c.GetAdminUserInfo()
-
- dialysisNo := service.ChechLastDialysisNo(adminUserInfo.CurrentOrgId)
- if dialysisNo == 0 {
- dialysisNo = 1
- } else {
- dialysisNo++
- }
- no := strconv.FormatInt(dialysisNo, 10)
-
- rep := 3 - len(no)
-
- if rep > 0 {
- no = strings.Repeat("0", rep) + no
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "no": no,
- })
- return
- }
-
- // CreatePatient 创建患者
- func (c *PatientApiController) CreatePatient() {
- record_date := c.GetString("record_date")
- is_infectious, _ := c.GetInt64("is_infectious")
- remind_cycle, _ := c.GetInt64("remind_cycle")
-
- adminUserInfo := c.GetAdminUserInfo()
- //patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
-
- //subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
- //if subscibes.State == 2 && patientTotal >= 20 { //免费试用版,不过期,限制患者数20
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
- // return
- //} else if subscibes.State == 1 && patientTotal >= 60 { //标准版,不过期,限制患者数60
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
- // return
- //}
-
- var patient models.Patients
- contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "create")
-
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- thisPatient, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
- if thisPatient.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
- return
- }
-
- thisPatient, _ = service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
- if thisPatient.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
- return
- }
-
- thisPatient, _ = service.FindPatientByMobile(adminUserInfo.CurrentOrgId, patient.Phone)
- if thisPatient.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientPhoneUsed)
- return
- }
-
- patient.RemindCycle = remind_cycle
- patient.IsInfectious = is_infectious
- patient.RegistrarsId = adminUserInfo.AdminUser.Id
- patient.Status = 1
- patient.CreatedTime = time.Now().Unix()
- patient.UserOrgId = adminUserInfo.CurrentOrgId
- patient.UpdatedTime = time.Now().Unix()
- patient.BindingState = 2
- // patient.Lapseto = 1
-
- hans := patient.Name // 要转换的汉字字符串
- // 创建一个拼音转换器
- p := pinyin.NewArgs()
-
- // 将汉字转为拼音
- pinyinSlice := pinyin.Pinyin(hans, p)
-
- // 获取首字母
- firstLetter := ""
- for _, py := range pinyinSlice {
- if len(py) > 0 {
- firstLetter += string(py[0][0])
- }
- }
-
- patient.FirstLetter = firstLetter
-
- err := service.CreatePatient(&patient, contagions, diseases)
-
- fmt.Println("创建病人失败err")
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePatient)
- return
- }
-
- //获取老表的最后一条数据
- patients, err := service.GetLastPatientData(adminUserInfo.CurrentOrgId)
- creater := adminUserInfo.AdminUser.Id
- record := models.XtPatientLaspseRecord{
- PatientId: patients.ID,
- RecordDate: time.Now().Unix(),
- LapseDate: time.Now().Unix(),
- LapseType: 1,
- LapseClass: 0,
- LapseReason: "",
- AdminUserId: creater,
- Remark: "",
- UserOrgId: 0,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- LapseTypeName: "转入",
- HisType: 0,
- HisZone: "",
- HisBed: "",
- }
- service.CreatePatientRecord(record)
-
- patientsNew := models.XtPatientsNew{
- UserOrgId: adminUserInfo.CurrentOrgId,
- UserId: 0,
- Avatar: patients.Avatar,
- PatientType: patients.PatientType,
- DialysisNo: patients.DialysisNo,
- AdmissionNumber: patients.AdmissionNumber,
- Source: patients.Source,
- Lapseto: patients.Lapseto,
- PartitionId: patients.PartitionId,
- BedId: patients.BedId,
- Name: patients.Name,
- Alias: patients.Alias,
- Gender: patients.Gender,
- MaritalStatus: patients.MaritalStatus,
- IdCardNo: patients.IdCardNo,
- Birthday: patients.Birthday,
- ReimbursementWayId: patients.ReimbursementWayId,
- HealthCareType: patients.HealthCareType,
- HealthCareNo: patients.HealthCareNo,
- HealthCareDueDate: patients.HealthCareDueDate,
- Height: patients.Height,
- BloodType: patients.BloodType,
- Rh: patients.Rh,
- HealthCareDueAlertDate: patients.HealthCareDueAlertDate,
- EducationLevel: patients.EducationLevel,
- Profession: patients.Profession,
- Phone: patients.Phone,
- HomeTelephone: patients.HomeTelephone,
- RelativePhone: patients.RelativePhone,
- RelativeRelations: patients.RelativeRelations,
- HomeAddress: patients.HomeAddress,
- WorkUnit: patients.WorkUnit,
- UnitAddress: patients.UnitAddress,
- Children: patients.Children,
- ReceivingDate: patients.ReceivingDate,
- IsHospitalFirstDialysis: patients.IsHospitalFirstDialysis,
- FirstDialysisDate: patients.FirstDialysisDate,
- FirstDialysisHospital: patients.FirstDialysisHospital,
- PredialysisCondition: patients.PredialysisCondition,
- PreHospitalDialysisFrequency: patients.PreHospitalDialysisFrequency,
- PreHospitalDialysisTimes: patients.PreHospitalDialysisTimes,
- HospitalFirstDialysisDate: patients.HospitalFirstDialysisDate,
- InductionPeriod: patients.InductionPeriod,
- InitialDialysis: patients.InitialDialysis,
- TotalDialysis: patients.TotalDialysis,
- AttendingDoctorId: patients.AttendingDoctorId,
- HeadNurseId: patients.HeadNurseId,
- Evaluate: patients.Evaluate,
- Diagnose: patients.Diagnose,
- Remark: patients.Remark,
- RegistrarsId: patients.RegistrarsId,
- Registrars: patients.Registrars,
- QrCode: patients.QrCode,
- BindingState: patients.BindingState,
- PatientComplains: patients.PatientComplains,
- PresentHistory: patients.PresentHistory,
- PastHistory: patients.PresentHistory,
- Temperature: patients.Temperature,
- Pulse: patients.Pulse,
- Respiratory: patients.Respiratory,
- Sbp: patients.SBP,
- Dbp: patients.DBP,
- Status: patients.Status,
- CreatedTime: patients.CreatedTime,
- UpdatedTime: patients.UpdatedTime,
- Nation: patients.Nation,
- NativePlace: patients.NativePlace,
- Age: patients.Age,
- InfectiousNextRecordTime: patients.InfectiousNextRecordTime,
- IsInfectious: patients.IsInfectious,
- RemindCycle: patients.RemindCycle,
- ResponseResult: patients.ResponseResult,
- IsOpenRemind: patients.IsOpenRemind,
- FirstTreatmentDate: patients.FirstTreatmentDate,
- DialysisAge: patients.DialysisAge,
- ExpenseKind: patients.ExpenseKind,
- TellPhone: patients.TellPhone,
- ContactName: patients.ContactName,
- BloodPatients: 1,
- SlowPatients: 0,
- MemberPatients: 0,
- EcommerPatients: "",
- BloodId: patients.ID,
- SlowId: 0,
- MemberId: 0,
- MemberFistdate: 0,
- MemberPatienttype: 0,
- MemberTreatement: 0,
- EquitmentId: "",
- UserSysBeforeCount: patient.UserSysBeforeCount,
- TrobleShoot: patient.TrobleShoot,
- TreatmentPlan: patient.TreatmentPlan,
- Doctor: patient.Doctor,
- RecordNumber: patient.RecordNumber,
- PatientSource: patient.PatientSource,
- PatientEndTime: patient.PatientEndTime,
- PatientStartTime: patient.PatientStartTime,
- InfectiousRemark: patient.InfectiousRemark,
- AllergicHistory: patient.AllergicHistory,
- PatientAddress: patient.PatientAddress,
- PrintDate: patient.PrintDate,
- }
- patientsNew.FirstLetter = firstLetter
-
- err = service.CreatePatientsNew(&patientsNew)
- fmt.Print("创建失败", err)
-
- allergic := models.XtPatientAllergic{
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: patient.ID,
- StartTime: patient.PatientStartTime,
- EndTime: patient.PatientEndTime,
- PatientSource: patient.PatientSource,
- PatientAddress: patient.PatientAddress,
- Remake: patient.Remark,
- Status: 1,
- Ctime: time.Now().Unix(),
- }
-
- if len(patient.PatientAddress) > 0 {
- service.CreateAllergic(allergic)
- }
-
- if len(record_date) > 0 {
- var recordTime int64
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordTime = theTime.Unix()
- inspections := make([]models.Inspection, 0)
- for _, item := range formItems {
- var inspection models.Inspection
- inspection.OrgId = adminUserInfo.CurrentOrgId
- inspection.PatientId = patient.ID
- inspection.ProjectId = item.ProjectId
- inspection.ItemId = item.ItemId
- inspection.ItemName = item.ItemName
- inspection.ProjectName = item.ProjectName
- inspection.InspectType = item.RangeType
- inspection.InspectValue = item.Value
- inspection.InspectDate = recordTime
- inspection.Status = 1
- inspection.CreatedTime = time.Now().Unix()
- inspection.UpdatedTime = time.Now().Unix()
- inspections = append(inspections, inspection)
- }
- err = service.CreatePatientInspection(inspections)
-
- infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
- var record_time int64
- switch remind_cycle {
- case 1: //1个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 1, 0).Unix()
-
- break
- case 2: //2个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 2, 0).Unix()
- break
- case 3: //3个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 3, 0).Unix()
- break
- case 4: //6个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 6, 0).Unix()
- break
- case 5: //12个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 12, 0).Unix()
- break
- }
-
- errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
- if errs != nil {
- utils.ErrorLog("更新日期出错:%v", errs)
- }
-
- }
-
- redis := service.RedisClient()
- defer redis.Close()
- redis.SAdd("sgj_patient:new_user_set", patient.UserId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- // EditPatient 修改
- func (c *PatientApiController) EditPatient() {
- id, _ := c.GetInt64("id", 0)
-
- record_date := c.GetString("record_date")
- is_infectious, _ := c.GetInt64("is_infectious")
- remind_cycle, _ := c.GetInt64("remind_cycle")
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "edit")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- thisPatientother, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
- if thisPatientother.ID > 0 && thisPatientother.ID != patient.ID {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
- return
- }
-
- thisPatient, _ := service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
- if thisPatient.ID > 0 && thisPatient.ID != patient.ID {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
- return
- }
-
- patient.UpdatedTime = time.Now().Unix()
- patient.IsInfectious = is_infectious
- patient.RemindCycle = remind_cycle
- err := service.UpdatePatient(&patient, contagions, diseases)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
- return
- }
- ////更新转归状态
- //lapseto := models.PatientLapseto{
- // LapsetoType: patient.Lapseto,
- // LapsetoTime: time.Now().Unix(),
- // UpdatedTime: time.Now().Unix(),
- //}
- //err = service.UpdatePatientLapseto(patient.ID, lapseto)
- //fmt.Println("更新转归失败", err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
- return
- }
- patientsNew := models.XtPatientsNew{
- UserOrgId: patient.UserOrgId,
- UserId: patient.UserId,
- Avatar: patient.Avatar,
- PatientType: patient.PatientType,
- DialysisNo: patient.DialysisNo,
- AdmissionNumber: patient.AdmissionNumber,
- Source: patient.Source,
- PartitionId: patient.PartitionId,
- BedId: patient.BedId,
- Name: patient.Name,
- Alias: patient.Alias,
- Gender: patient.Gender,
- MaritalStatus: patient.MaritalStatus,
- IdCardNo: patient.IdCardNo,
- Birthday: patient.Birthday,
- ReimbursementWayId: patient.ReimbursementWayId,
- HealthCareType: patient.HealthCareType,
- HealthCareNo: patient.HealthCareNo,
- HealthCareDueDate: patient.HealthCareDueDate,
- Height: patient.Height,
- BloodType: patient.BloodType,
- Rh: patient.Rh,
- HealthCareDueAlertDate: patient.HealthCareDueAlertDate,
- EducationLevel: patient.EducationLevel,
- Profession: patient.Profession,
- Phone: patient.Phone,
- HomeTelephone: patient.HomeTelephone,
- RelativePhone: patient.RelativePhone,
- RelativeRelations: patient.RelativeRelations,
- HomeAddress: patient.HomeAddress,
- WorkUnit: patient.WorkUnit,
- UnitAddress: patient.UnitAddress,
- Children: patient.Children,
- ReceivingDate: patient.ReceivingDate,
- IsHospitalFirstDialysis: patient.IsHospitalFirstDialysis,
- FirstDialysisDate: patient.FirstDialysisDate,
- FirstDialysisHospital: patient.FirstDialysisHospital,
- PredialysisCondition: patient.PredialysisCondition,
- PreHospitalDialysisTimes: patient.PreHospitalDialysisTimes,
- HospitalFirstDialysisDate: patient.HospitalFirstDialysisDate,
- InductionPeriod: patient.InductionPeriod,
- InitialDialysis: patient.InitialDialysis,
- TotalDialysis: patient.TotalDialysis,
- AttendingDoctorId: patient.AttendingDoctorId,
- HeadNurseId: patient.HeadNurseId,
- Evaluate: patient.Evaluate,
- Diagnose: patient.Diagnose,
- Remark: patient.Remark,
- RegistrarsId: patient.RegistrarsId,
- Registrars: patient.Registrars,
- QrCode: patient.QrCode,
- BindingState: patient.BindingState,
- PatientComplains: patient.PatientComplains,
- PresentHistory: patient.PresentHistory,
- PastHistory: patient.PastHistory,
- Temperature: patient.Temperature,
- Pulse: patient.Pulse,
- Respiratory: patient.Respiratory,
- Sbp: patient.SBP,
- Dbp: patient.DBP,
- Nation: patient.Nation,
- NativePlace: patient.NativePlace,
- Age: patient.Age,
- InfectiousNextRecordTime: patient.InfectiousNextRecordTime,
- IsInfectious: patient.IsInfectious,
- RemindCycle: patient.RemindCycle,
- ResponseResult: patient.ResponseResult,
- IsOpenRemind: patient.IsOpenRemind,
- FirstTreatmentDate: patient.FirstTreatmentDate,
- DialysisAge: patient.DialysisAge,
- ExpenseKind: patient.ExpenseKind,
- TellPhone: patient.TellPhone,
- ContactName: patient.ContactName,
- UpdatedTime: time.Now().Unix(),
- BloodPatients: 1,
- Lapseto: patient.Lapseto,
- TrobleShoot: patient.TrobleShoot,
- SchRemark: patient.SchRemark,
- TreatmentPlan: patient.TreatmentPlan,
- RecordNumber: patient.RecordNumber,
- PatientSource: patient.PatientSource,
- PatientStartTime: patient.PatientStartTime,
- PatientEndTime: patient.PatientEndTime,
- InfectiousRemark: patient.InfectiousRemark,
- AllergicHistory: patient.AllergicHistory,
- PatientAddress: patient.PatientAddress,
- PrintDate: patient.PrintDate,
- }
- // //更新病人ID获取新表病人ID
- err = service.UpdatepatientTwo(&patientsNew, id)
-
- allergic := models.XtPatientAllergic{
- PatientId: patient.ID,
- UserOrgId: adminUserInfo.CurrentOrgId,
- StartTime: patient.PatientStartTime,
- EndTime: patient.PatientEndTime,
- PatientSource: patient.PatientSource,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Remake: patient.Remark,
- PatientAddress: patient.PatientAddress,
- }
- if len(patient.PatientAddress) > 0 {
- service.CreateAllergic(allergic)
- }
-
- nowTimeUinx := time.Now()
- today := nowTimeUinx.Format("2006-01-02")
-
- redis := service.RedisClient()
- defer redis.Close()
- key := "scheduals_" + today + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
- redis.Set(key, "", time.Second*60*60*18)
-
- keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":patient_info"
- redis.Set(keyOne, "", time.Second*60*60*18)
- if len(record_date) > 0 {
- var recordTime int64
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordTime = theTime.Unix()
- inspections := make([]models.Inspection, 0)
- for _, item := range formItems {
- var inspection models.Inspection
- inspection.OrgId = adminUserInfo.CurrentOrgId
- inspection.PatientId = patient.ID
- inspection.ProjectId = item.ProjectId
- inspection.ItemId = item.ItemId
- inspection.ItemName = item.ItemName
- inspection.ProjectName = item.ProjectName
- inspection.InspectType = item.RangeType
- inspection.InspectValue = item.Value
- inspection.InspectDate = recordTime
- inspection.Status = 1
- inspection.CreatedTime = time.Now().Unix()
- inspection.UpdatedTime = time.Now().Unix()
- inspections = append(inspections, inspection)
- }
- err = service.CreatePatientInspection(inspections)
-
- infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
- var record_time int64
- switch remind_cycle {
- case 1: //1个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 1, 0).Unix()
-
- break
- case 2: //2个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 2, 0).Unix()
- break
- case 3: //3个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 3, 0).Unix()
- break
- case 4: //6个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 6, 0).Unix()
- break
- case 5: //12个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 12, 0).Unix()
- break
- }
-
- errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
- if errs != nil {
- utils.ErrorLog("更新日期出错:%v", errs)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
-
- }
-
- func (c *PatientApiController) EditLapseto() {
- id, _ := c.GetInt64("id", 0)
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- start_time := c.GetString("start_time")
-
- end_time := c.GetString("end_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- patient_address := c.GetString("patient_address")
-
- adminUserInfo := c.GetAdminUserInfo()
-
- patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- patientBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &patientBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- var lapseto models.PatientLapseto
- lapseto.PatientId = patient.ID
-
- if patientBody["lapseto_type"] == nil || reflect.TypeOf(patientBody["lapseto_type"]).String() != "float64" {
- utils.ErrorLog("lapseto_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- lapsetoType := int64(patientBody["lapseto_type"].(float64))
-
- lapseto.LapsetoType = lapsetoType
-
- if patientBody["lapseto_time"] == nil || reflect.TypeOf(patientBody["lapseto_time"]).String() != "string" {
- utils.ErrorLog("lapseto_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoType)
- return
- }
- lapsetoTime, _ := patientBody["lapseto_time"].(string)
-
- //if len(lapsetoTime) == 0 {
- // utils.ErrorLog("len(lapsetoTime) == 0")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
- // return
- //}
-
- out_reason, _ := patientBody["out_reason"].(string)
-
- //if len(out_reason) == 0 {
- // utils.ErrorLog("len(out_reason) == 0")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
- // return
- //}
-
- lapsetoTimeUnix, err := time.ParseInLocation(timeLayout, lapsetoTime, loc)
-
- //if err != nil {
- // utils.ErrorLog("lapsetoTimeUnix")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
- // return
- //}
- lapseto.LapsetoTime = lapsetoTimeUnix.Unix()
- lapseto.UpdatedTime = time.Now().Unix()
- lapseto.CreatedTime = time.Now().Unix()
- lapseto.Status = 1
- patient.Lapseto = lapseto.LapsetoType
- patient.OutReason = out_reason
- patient.DeathTime = lapsetoTimeUnix.Unix()
-
- patient.PatientStartTime = startTime
- patient.PatientEndTime = endTime
- patient.PatientAddress = patient_address
-
- //if patient.Lapseto == 1 {
- // patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
- // subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
- // if subscibes.State == 2 && patientTotal >= 100 { //免费试用版,不过期,限制患者数20
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
- // return
- // } else if subscibes.State == 1 && patientTotal >= 200 { //标准版,不过期,限制患者数60
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
- // return
- // }
- //}
-
- err = service.EditPatientLapseto(&patient, &lapseto)
-
- if lapseto.LapsetoType == 3 || lapseto.LapsetoType == 2 {
- fmt.Println("lapsetoTimeUnix.Unix()", lapsetoTimeUnix.Unix())
- if adminUserInfo.CurrentOrgId == 10340 {
- service.UpdateScheduleByDeathTime(id, lapsetoTimeUnix.Unix())
- service.UpdateScheduleItemByPatientId(id)
- } else {
- timeStr := time.Now().Format("2006-01-02")
- timeLayout := "2006-01-02 15:04:05"
- timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
- timenow := timeStringToTime.Unix()
- service.UpdateScheduleByDeathTime(id, timenow)
- service.UpdateScheduleItemByPatientId(id)
- }
- }
-
- allergic := models.XtPatientAllergic{
- UserOrgId: adminUserInfo.CurrentOrgId,
- PatientId: patient.ID,
- StartTime: patient.PatientStartTime,
- EndTime: patient.PatientEndTime,
- PatientSource: patient.Lapseto,
- PatientAddress: patient.PatientAddress,
- Remake: patient.Remark,
- Status: 1,
- Ctime: time.Now().Unix(),
- }
- if lapseto.LapsetoType == 2 || lapseto.LapsetoType == 3 {
- allergic.StartTime = lapseto.LapsetoTime
- allergic.EndTime = lapseto.LapsetoTime
- }
-
- service.CreateAllergic(allergic)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEditLapsetoFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- func (c *PatientApiController) GetPatient() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
-
- infections, _ := service.GetAllInfectionRecord(infectiousRecord.InspectDate, adminUserInfo.CurrentOrgId, patient.ID, infectiousRecord.ProjectId)
- diseases := service.GetPatientDiseases(patient.ID)
- contagions := service.GetPatientContagions(patient.ID)
- patientVascularAccessOne, _ := service.GetPatientVascularAccessOne(patient.ID)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- "diseases": diseases,
- "contagions": contagions,
- "infections": infections,
- "patientVascularAccessOne": patientVascularAccessOne,
- })
- return
- }
-
- func (c *PatientApiController) CreateDialysisSolution() {
-
- id, _ := c.GetInt64("patient", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- var solution models.DialysisSolution
-
- code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- //thisSolution, _ := service.FindPatientDialysisSolutionByMode(adminUserInfo.CurrentOrgId, id, solution.ModeId)
- //if thisSolution.ID > 0 {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionExist)
- // return
- //}
-
- solution.RegistrarsId = adminUserInfo.AdminUser.Id
- solution.Doctor = adminUserInfo.AdminUser.Id
- solution.Status = 1
- solution.PatientId = id
- solution.CreatedTime = time.Now().Unix()
- solution.UserOrgId = adminUserInfo.CurrentOrgId
- solution.UpdatedTime = time.Now().Unix()
- solution.SubName = ""
- solution.ParentId = 0
- solution.SolutionStatus = 1
-
- //records, _ := service.GetAllSchedules()
-
- schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, id, solution.ModeId)
- for _, sch := range schs {
- var DialysisMachineName string
- if len(solution.DialysisDialyszers) > 0 {
- DialysisMachineName = solution.DialysisDialyszers
- }
- if len(solution.DialyzerPerfusionApparatus) > 0 {
- DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
- }
-
- if len(solution.DialysisIrrigation) > 0 {
- DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
- }
-
- if len(solution.DialysisStrainer) > 0 {
- DialysisMachineName = DialysisMachineName + "," + solution.DialysisStrainer
- }
- sch.DialysisMachineName = DialysisMachineName
- service.UpdateSch(sch)
- }
-
- err := service.CreatePatientDialysisSolution(&solution)
-
- //获取最新1条
- dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.CurrentOrgId)
-
- //更新状态
- service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "solution": solution,
- })
- return
- }
-
- func (c *PatientApiController) UpdateDialysisSolution() {
- patient, _ := c.GetInt64("patient", 0)
- id, _ := c.GetInt64("id", 0)
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
- if solution.ID == 0 || solution.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
- return
- }
-
- code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- solution.UpdatedTime = time.Now().Unix()
-
- err := service.UpdatePatientDialysisSolution(&solution)
-
- nowTimeUinx := time.Now()
- today := nowTimeUinx.Format("2006-01-02")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- todayTime, err := time.ParseInLocation(timeLayout, today, loc)
-
- if adminUserInfo.CurrentOrgId == 9538 || adminUserInfo.CurrentOrgId == 10164 {
- prescription := models.DialysisPrescription{
- Dialyzer: solution.Dialyzer,
- Anticoagulant: solution.Anticoagulant,
- AnticoagulantShouji: solution.AnticoagulantShouji,
- AnticoagulantWeichi: solution.AnticoagulantWeichi,
- AnticoagulantZongliang: solution.AnticoagulantZongliang,
- ModeId: solution.ModeId,
- DialysisDurationHour: solution.DialysisDurationHour,
- Kalium: solution.Kalium,
- Sodium: solution.Sodium,
- Calcium: solution.Calcium,
- TargetUltrafiltration: solution.TargetUltrafiltration,
- DialyzerPerfusionApparatus: solution.DialyzerPerfusionApparatus,
- BloodAccess: solution.BloodAccess,
- DialysateFlow: solution.DialysateFlow,
- DialysateTemperature: solution.DialysateTemperature,
- DialysisIrrigation: solution.DialysisIrrigation,
- DialysisDialyszers: solution.DialysisDialyszers,
- PlasmaSeparator: solution.PlasmaSeparator,
- BilirubinAdsorptionColumn: solution.BilirubinAdsorptionColumn,
- OxygenUptake: solution.OxygenUptake,
- OxygenFlow: solution.OxygenFlow,
- OxygenTime: solution.OxygenTime,
- MaxUltrafiltrationRate: solution.MaxUltrafiltrationRate,
- Amylaceum: solution.Amylaceum,
- DialysisStrainer: solution.DialysisStrainer,
- Chaptalization: solution.Chaptalization,
- BloodAccessPartId: solution.BloodAccessPartId,
- }
- service.UpdatePatientDialysisSolutionOne(solution.PatientId, adminUserInfo.CurrentOrgId, &prescription, todayTime.Unix())
- }
-
- schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, solution.PatientId, solution.ModeId)
- for _, sch := range schs {
- var DialysisMachineName string
- if len(solution.DialysisDialyszers) > 0 {
- DialysisMachineName = solution.DialysisDialyszers
- }
- if len(solution.DialyzerPerfusionApparatus) > 0 {
- DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
- }
-
- if len(solution.DialysisIrrigation) > 0 {
- DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
- }
-
- if len(solution.DialysisStrainer) > 0 {
- DialysisMachineName = DialysisMachineName + "," + solution.DialysisStrainer
- }
- sch.DialysisMachineName = DialysisMachineName
- service.UpdateSch(sch)
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "solution": solution,
- })
- return
- }
-
- func (c *PatientApiController) UpdateDialysisSolutionDetail() {
- patient, _ := c.GetInt64("patient", 0)
- id, _ := c.GetInt64("id", 0)
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
- if solution.ID == 0 || solution.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
- return
- }
-
- code := solutionFormData(&solution, c.Ctx.Input.RequestBody)
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- solution.UpdatedTime = time.Now().Unix()
- solution.AffirmState = 1
-
- err := service.UpdatePatientDialysisSolution(&solution)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "solution": solution,
- })
- return
- }
-
- func (c *PatientApiController) GetPatientDialysisSolutionList() {
- id, _ := c.GetInt64("id", 0)
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- if id <= 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "solutions": nil,
- })
- return
- }
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- solutions, total, _ := service.GetPatientDialysisSolutionList(adminUserInfo.CurrentOrgId, id, page, limit)
- stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "solutions": solutions,
- "total": total,
- "stockType": stockType,
- })
- return
- }
- func (c *PatientApiController) DeleteDialysisSolution() {
-
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
- if solution.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
- return
- }
-
- if solution.UseState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUsed)
- return
- }
-
- solution.UpdatedTime = time.Now().Unix()
- solution.Status = 0
-
- err := service.DeleteSolution(&solution)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionDelete)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- // GetDryWeights 取患者干体重调整铺
- func (c *PatientApiController) GetDryWeights() {
- page, _ := c.GetInt64("page", 1)
- limit, _ := c.GetInt64("limit", 10)
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- weights, total, _ := service.GetPatientDryWeightAdjustList(adminUserInfo.CurrentOrgId, id, page, limit)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "weights": weights,
- "total": total,
- })
- return
-
- }
-
- func (c *PatientApiController) CreateDryWeights() {
- patient, _ := c.GetInt64("id", 0)
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- var theWeight models.DryWeightAdjust
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["weight"] == nil || reflect.TypeOf(dataBody["weight"]).String() != "string" {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- weight, _ := strconv.ParseFloat(dataBody["weight"].(string), 64)
- theWeight.Weight = weight
-
- // if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // doctor := int64(dataBody["doctor"].(float64))
- // theWeight.Doctor = doctor
-
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark, _ := dataBody["remark"].(string)
- theWeight.Remark = remark
- }
-
- theWeight.CreatedTime = time.Now().Unix()
- theWeight.UpdatedTime = time.Now().Unix()
- theWeight.Status = 1
- theWeight.RegistrarsId = adminUserInfo.AdminUser.Id
- theWeight.UserOrgId = adminUserInfo.CurrentOrgId
- theWeight.PatientId = patient
- theWeight.Doctor = adminUserInfo.AdminUser.Id
-
- old, _ := service.FindPatientLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient)
- if old.ID > 0 {
- theWeight.AdjustedValue = theWeight.Weight - old.Weight
- }
-
- err = service.CreateDryWeightAdjust(&theWeight)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDryWeightFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "weight": theWeight,
- })
- return
- }
-
- func (c *PatientApiController) CreateGroupAdvice() {
- var err error
- defer func() {
- if rec := recover(); rec != nil {
- err = fmt.Errorf("程序异常:%v", rec)
- }
- if err != nil {
- service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
- }
- }()
- patient, _ := c.GetInt64("id", 0)
- groupNo, _ := c.GetInt64("groupno", 0)
-
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- var patientInfo models.Patients
- patientInfo, err = service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- dataBody := make(map[string]interface{}, 0)
- err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- utils.ErrorLog("%v", dataBody)
-
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- if appRole.UserType == 3 {
- headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- if getPermissionErr != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if headNursePermission == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
- return
- }
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
- utils.ErrorLog("advice_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceType := int64(dataBody["advice_type"].(float64))
- if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
- utils.ErrorLog("advice_type != 1&&2")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- startTime2, _ := dataBody["start_time"].(string)
-
- time_arr := strings.Split(startTime2, " ")
-
- if len(time_arr) > 0 {
- startTime2 = time_arr[0]
- }
-
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceDate := startTime2
- if len(adviceDate) == 0 {
- utils.ErrorLog("len(adviceDate) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- AdviceDate := theTime.Unix()
- RecordDate := theTime.Unix()
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime, _ := dataBody["start_time"].(string)
- if len(startTime) == 0 {
- utils.ErrorLog("len(start_time) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err = time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- StartTime := theTime.Unix()
-
- Remark := ""
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark, _ := dataBody["remark"].(string)
-
- Remark = remark
- }
- var advices []*models.GroupAdvice
- if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
- utils.ErrorLog("adviceNames")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceNames := dataBody["adviceNames"].([]interface{})
- for _, adviceNameMap := range adviceNames {
-
- adviceNameM := adviceNameMap.(map[string]interface{})
- var advice models.GroupAdvice
- advice.Remark = Remark
- advice.AdviceType = adviceType
- advice.StartTime = StartTime
- advice.AdviceDate = AdviceDate
-
- advice.RecordDate = RecordDate
- advice.Status = 1
- advice.CreatedTime = time.Now().Unix()
- advice.UpdatedTime = time.Now().Unix()
- advice.StopState = 2
- advice.ExecutionState = 2
- advice.UserOrgId = adminUserInfo.CurrentOrgId
- advice.PatientId = patientInfo.ID
- advice.AdviceDoctor = adminUserInfo.AdminUser.Id
- advice.IsSettle = 2
-
- //创建步骤表
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 4,
- RecordDate: advice.RecordDate,
- Sourse: 1,
- PatientId: patient,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, advice.RecordDate, 4, patient)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= advice.AdviceDate {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
-
- if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
- utils.ErrorLog("advice_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceName, _ := adviceNameM["advice_name"].(string)
-
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice.AdviceName = adviceName
-
- if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
-
- if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
- adviceDesc, _ := adviceNameM["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
- }
-
- if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
-
- template_id, _ := adviceNameM["template_id"].(string)
- advice.TemplateId = template_id
- }
-
- if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
- drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
-
- if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
- if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
- singleDose := adviceNameM["single_dose"].(float64)
- advice.SingleDose = singleDose
- }
-
- if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
- if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
- tmp := adviceNameM["single_dose_unit"].(float64)
- singleDoseUnit := service.TypeConversion(tmp)
- advice.SingleDoseUnit = singleDoseUnit
- }
-
- if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
- if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
- prescribingNumber := adviceNameM["prescribing_number"].(float64)
- advice.PrescribingNumber = prescribingNumber
- }
-
- if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
- if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
- deliveryWay, _ := adviceNameM["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
-
- if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
- executionFrequency, _ := adviceNameM["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if adviceNameM["way"] != nil && reflect.TypeOf(adviceNameM["way"]).String() == "string" {
- way, _ := strconv.ParseFloat(adviceNameM["way"].(string), 64)
- advice.Way = int64(way)
- }
- if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
- way := int64(adviceNameM["way"].(float64))
- advice.Way = way
- }
-
- if adviceNameM["drug_id"] != nil && reflect.TypeOf(adviceNameM["drug_id"]).String() == "string" {
- drug_id, _ := strconv.ParseFloat(adviceNameM["drug_id"].(string), 64)
- advice.DrugId = int64(drug_id)
- }
- if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
- drug_id := int64(adviceNameM["drug_id"].(float64))
- advice.DrugId = drug_id
- }
-
- if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
- drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
- advice.DrugNameId = drug_name_id
- }
-
- remark, _ := adviceNameM["remark"].(string)
-
- advice.Remark = remark
-
- if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
- if advice.PrescribingNumber == 0 {
- advice.PrescribingNumber = 1
- }
- //查询该患者今日有没有双人核对
- check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, advice.AdviceDate)
- fmt.Println("chek", check)
- if check.ID > 0 {
- advice.Checker = check.Modifier
- advice.CheckState = 1
- advice.CheckTime = time.Now().Unix()
- }
- }
- if adviceType == 1 {
-
- if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
- frequency_type := int64(adviceNameM["frequency_type"].(float64))
- advice.FrequencyType = frequency_type
- }
-
- if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "string" {
- day_count, _ := strconv.ParseInt(adviceNameM["day_count"].(string), 10, 64)
- advice.DayCount = day_count
- }
-
- if adviceNameM["week_days"] != nil && reflect.TypeOf(adviceNameM["week_days"]).String() == "string" {
- week_day, _ := adviceNameM["week_days"].(string)
- advice.WeekDay = week_day
- }
-
- if adviceNameM["push_start_time"] != nil && reflect.TypeOf(adviceNameM["push_start_time"]).String() == "string" {
- push_start_time, _ := adviceNameM["push_start_time"].(string)
- var startTime int64
- if len(push_start_time) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
-
- startTime = theTime.Unix()
- }
- advice.PushStartTime = startTime
- }
-
- }
-
- //针对康桥
- if adminUserInfo.CurrentOrgId == 10702 {
- if adviceType == 3 {
- adviceType = 2
- }
-
- }
-
- if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "string" {
- executionFrequency, _ := adviceNameM["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "[]interface {}" {
- children := adviceNameM["children"].([]interface{})
- if len(children) > 0 {
- for _, childrenMap := range children {
- childMap := childrenMap.(map[string]interface{})
- var child models.GroupAdvice
- child.Remark = Remark
- child.AdviceType = adviceType
- child.StartTime = StartTime
- child.AdviceDate = AdviceDate
- child.RecordDate = RecordDate
- child.Status = 1
- child.CreatedTime = time.Now().Unix()
- child.UpdatedTime = time.Now().Unix()
- child.StopState = 2
- child.ExecutionState = 2
- child.UserOrgId = adminUserInfo.CurrentOrgId
- child.PatientId = patientInfo.ID
- child.AdviceDoctor = adminUserInfo.AdminUser.Id
- child.IsSettle = 2
-
- if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
- utils.ErrorLog("child advice_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- childAdviceName, _ := childMap["advice_name"].(string)
- if len(childAdviceName) == 0 {
- utils.ErrorLog("len(child advice_name) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- child.AdviceName = childAdviceName
-
- if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
- childAdviceDesc, _ := childMap["advice_desc"].(string)
- child.AdviceDesc = childAdviceDesc
- }
-
- if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
- childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
- child.DrugSpec = childDrugSpec
- }
-
- if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
- childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
- child.DrugSpecUnit = childDrugSpecUnit
- }
-
- if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
- childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
- child.SingleDose = childSingleDose
- }
-
- if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
- childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
- child.SingleDoseUnit = childSingleDoseUnit
- }
-
- if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
- childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
- child.PrescribingNumber = childPrescribingNumber
- }
-
- if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
- childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
- child.PrescribingNumberUnit = childPrescribingNumberUnit
- }
-
- if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
- drug_id := int64(childMap["drug_id"].(float64))
- child.DrugId = drug_id
- }
-
- if childMap["way"] != nil && reflect.TypeOf(childMap["way"]).String() == "float64" {
- way := int64(childMap["way"].(float64))
- child.Way = way
- }
-
- if childMap["drug_name_id"] != nil && reflect.TypeOf(childMap["drug_name_id"]).String() == "float64" {
- drug_name_id := int64(childMap["drug_name_id"].(float64))
- child.DrugNameId = drug_name_id
- }
-
- child.DeliveryWay = advice.DeliveryWay
- child.ExecutionFrequency = advice.ExecutionFrequency
-
- if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
- if child.PrescribingNumber == 0 {
- child.PrescribingNumber = 1
- }
- //查询该患者今日有没有双人核对
- check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, child.AdviceDate)
-
- if check.ID > 0 {
- child.Checker = check.Modifier
- child.CheckState = 1
- child.CheckTime = time.Now().Unix()
- }
- }
- advice.Children = append(advice.Children, &child)
- }
- }
- }
-
- advices = append(advices, &advice)
- }
-
- list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
-
- for _, item := range advices {
- //记录日志
- byterequest, _ := json.Marshal(item)
- adviceLog := models.XtDoctorAdviceLog{
- UserOrgId: item.UserOrgId,
- PatientId: item.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 1,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电导端批量插入医嘱",
- RecordDate: item.AdviceDate,
- }
- service.CreateDoctorAdviceLog(adviceLog)
- }
-
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
-
- redis := service.RedisClient()
- defer redis.Close()
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advices": list,
- })
-
- return
- }
-
- func (c *PatientApiController) CreateDoctorAdvice() {
- patient, _ := c.GetInt64("id", 0)
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
-
- if appRole.UserType == 3 {
- headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- if getPermissionErr != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if headNursePermission == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
- return
- }
- }
-
- var advice models.DoctorAdvice
- code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- if advice.ParentId > 0 {
-
- old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
- if old.ID == 0 || old.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
- return
- }
-
- if old.StopState == 1 || old.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
- return
- }
-
- if old.ParentId > 0 {
- advice.ParentId = old.ParentId
- }
- advice.StartTime = old.StartTime
- advice.AdviceDoctor = old.AdviceDoctor
- advice.DeliveryWay = old.DeliveryWay
- advice.ExecutionFrequency = old.ExecutionFrequency
- advice.GroupNo = old.GroupNo
-
- }
-
- advice.Status = 1
- advice.CreatedTime = time.Now().Unix()
- advice.UpdatedTime = time.Now().Unix()
- advice.StopState = 2
- advice.ExecutionState = 2
- advice.UserOrgId = adminUserInfo.CurrentOrgId
- advice.PatientId = patient
- advice.AdviceDoctor = adminUserInfo.AdminUser.Id
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= advice.AdviceDate {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
-
- if advice.UserOrgId == 3877 || advice.UserOrgId == 10340 || advice.UserOrgId == 9671 {
- if advice.PrescribingNumber == 0 {
- advice.PrescribingNumber = 1
- }
- //查询该患者今日有没有双人核对
- check, _ := service.MobileGetDoubleCheckSix(advice.UserOrgId, patientInfo.ID, advice.AdviceDate)
-
- if check.ID > 0 {
- advice.Checker = check.Modifier
- advice.CheckState = 1
- advice.CheckTime = time.Now().Unix()
- }
- }
- err := service.CreateDoctorAdvice(&advice)
-
- //记录日志
- byterequest, _ := json.Marshal(advice)
- adviceLog := models.XtDoctorAdviceLog{
- UserOrgId: advice.UserOrgId,
- PatientId: advice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 1,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑新增医嘱",
- RecordDate: advice.RecordDate,
- }
-
- service.CreateDoctorAdviceLog(adviceLog)
-
- //创建步骤表
- finish := models.XtDialysisFinish{
- IsFinish: 1,
- UserOrgId: adminUserInfo.CurrentOrgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Module: 4,
- RecordDate: advice.AdviceDate,
- Sourse: 1,
- PatientId: patient,
- }
-
- dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, advice.AdviceDate, 4, patient)
- if dialysisFinish.ID == 0 {
- service.CreateDialysisFinish(finish)
- }
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- defer redis.Close()
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
-
- func (c *PatientApiController) ExecGroupAdvice() {
- groupNo, _ := c.GetInt64("groupno", 0)
- executionTime := c.GetString("execution_time")
-
- if groupNo <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(executionTime) <= 0 {
- utils.ErrorLog("execution_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- if advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
- return
- }
-
- executionStaff := adminUserInfo.AdminUser.Id
- // checker := adminUserInfo.AdminUser.Id
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if advice.StartTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
- return
- }
-
- exceAdvice := models.DoctorAdvice{
- ExecutionStaff: executionStaff,
- ExecutionTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- err = service.ExceDoctorAdviceByGroupNo(&exceAdvice, groupNo, adminUserInfo.CurrentOrgId)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- //查询自动扣减是否开启
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
- //查询已经执行的医嘱
- advicelist, _ := service.GetExceDoctorAdviceGroupNo(groupNo, adminUserInfo.CurrentOrgId)
-
- if drugStockConfig.IsOpen == 1 {
- for _, item := range advicelist {
- medical, _ := service.GetBaseDrugMedical(advice.DrugId)
- //查询这个患者这个患者这个药已经出库的所有数量
- advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
- drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
- var total_count int64
- var drug_count int64
- for _, it := range advicelist {
- if it.PrescribingNumberUnit == medical.MaxUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
- prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total_count += prenumber * medical.MinNumber
- }
- if it.PrescribingNumberUnit == medical.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
- prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total_count += prenumber
- }
-
- }
-
- for _, its := range drugoutlist {
- if its.CountUnit == medical.MaxUnit {
- drug_count += its.Count * medical.MinNumber
- }
- if its.CountUnit == medical.MinUnit {
- drug_count += its.Count
- }
- }
- if total_count == drug_count {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
-
- var total int64
- var prescribing_number_total int64
-
- //查询默认出库仓库
- houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
-
- //查询该药品在默认仓库是否有库存
- list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
-
- //判断单位是否相等
- if medical.MaxUnit == advice.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //转化为最小单位
- total = list.Count*medical.MinNumber + list.StockMinNumber
- prescribing_number_total = count * medical.MinNumber
- }
-
- if medical.MinUnit == advice.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total = list.Count*medical.MinNumber + list.StockMinNumber
-
- prescribing_number_total = count
-
- }
-
- if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "advice": advice,
- })
- return
- }
- if prescribing_number_total > total {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "advice": advice,
- })
- return
- }
- if prescribing_number_total <= total {
- pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
- if medical.IsUse == 2 {
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
- drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
- if drugOutInfo.ID == 0 {
- if item.UserOrgId != 10644 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
- }
-
- }
-
- }
- if pharmacyConfig.IsOpen != 1 {
- drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
- if drugOutInfo.ID == 0 {
- if item.UserOrgId != 10644 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
- }
-
- }
- }
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
- //查询默认仓库剩余多少库存
- var sum_count int64
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
-
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- break
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
-
- }
-
- if medical.IsUse == 1 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
-
- }
-
- }
- }
-
- advice.ExecutionStaff = executionStaff
- advice.ExecutionTime = theTime.Unix()
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
-
- func (c *PatientApiController) ExecDoctorAdvice() {
-
- origin, _ := c.GetInt64("origin", 0)
-
- patient, _ := c.GetInt64("patient", 0)
- id, _ := c.GetInt64("id", 0)
- executionTime := c.GetString("execution_time")
-
- if origin != 2 {
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(executionTime) <= 0 {
- utils.ErrorLog("execution_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
-
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
-
- //自备药
- selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
-
- if selfPrescriptionOutOpenOne.IsOpen == 1 {
- //查询库存是否
- selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
-
- if selfBasedrug.IsSelfDrug == 1 {
- selfDrugStockCount, _ := service.GetSelfDrugStockCountByPatientId(advice.DrugId, advice.PatientId, advice.UserOrgId)
- var prescribing_number_total_one int64
- //判断单位是否相等
- if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //转化为最小单位
- prescribing_number_total_one = count * selfBasedrug.MinNumber
- }
-
- if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- prescribing_number_total_one = count
-
- }
-
- if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- prescribing_number_total_one = count
- }
-
- //库存不足
- if prescribing_number_total_one > selfDrugStockCount.FlushCount {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "advice": advice,
- })
- return
- }
- }
-
- }
-
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- //医嘱已执行
- if advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
- return
- }
-
- executionStaff := adminUserInfo.AdminUser.Id
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if advice.StartTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- exceAdvice := models.DoctorAdvice{
- ExecutionStaff: executionStaff,
- ExecutionTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= advice.AdviceDate {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
- if advice.ParentId > 0 {
- err = service.ExceDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
- //记录日志
- byterequest, _ := json.Marshal(exceAdvice)
- doctorAdviceLog := models.XtDoctorAdviceLog{
- UserOrgId: exceAdvice.UserOrgId,
- PatientId: exceAdvice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 2,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端执行医嘱",
- RecordDate: exceAdvice.RecordDate,
- }
- service.CreateDoctorAdviceLog(doctorAdviceLog)
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
-
- theTimes := theTime.Format("2006-01-02")
-
- fmt.Println("theTIME", theTime)
- keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
-
- defer redis.Close()
- } else {
- err = service.ExceDoctorAdviceById(&exceAdvice, id, patient)
- //记录日志
- byterequest, _ := json.Marshal(exceAdvice)
- doctorAdviceLog := models.XtDoctorAdviceLog{
- UserOrgId: exceAdvice.UserOrgId,
- PatientId: exceAdvice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 2,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端执行医嘱",
- RecordDate: exceAdvice.RecordDate,
- }
- service.CreateDoctorAdviceLog(doctorAdviceLog)
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
-
- theTimes := theTime.Format("2006-01-02")
-
- fmt.Println("theTIME", theTime)
- keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
-
- defer redis.Close()
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- advice.ExecutionStaff = executionStaff
- advice.ExecutionTime = theTime.Unix()
-
- //处理出库相关逻辑
-
- //1.判断是否启用药品管理和自备药出库功能
-
- //药品管理信息
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
-
- //自备药信息
- privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
-
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
- if drugStockConfig.IsOpen == 1 {
- var total int64
- var prescribing_number_total int64
- advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
- for _, item := range advices {
- houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
- //查询该药品是否有库存
- list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
-
- //查询改药品信息
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- //判断单位是否相等
- if medical.MaxUnit == item.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //转化为最小单位
- total = list.Count*medical.MinNumber + list.StockMinNumber
- prescribing_number_total = count * medical.MinNumber
- }
- if medical.MinUnit == item.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total = list.Count*medical.MinNumber + list.StockMinNumber
- prescribing_number_total = count
- }
-
- if medical.IsUse != 1 {
-
- if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
- service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
- advice.ExecutionState = 2
- advice.ExecutionStaff = 0
- advice.ExecutionTime = 0
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "advice": advice,
- })
- return
- }
- if prescribing_number_total > total {
- service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
- advice.ExecutionState = 2
- advice.ExecutionStaff = 0
- advice.ExecutionTime = 0
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "advice": advice,
- })
- return
- }
- }
-
- if medical.IsUse == 1 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
-
- if prescribing_number_total <= total {
-
- //查询是否门诊处方和临时医嘱同步到透析医嘱的开关是否开启
-
- adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
-
- if adviceSetting.IsAdviceOpen == 1 {
- //查询是否出库按钮开启
- prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
- pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
- if prescriptionConfig.IsOpen == 1 {
-
- if medical.IsUse == 2 {
- //是通过药房发药
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
- //执行出库
-
- drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
- if drugOutInfo.ID == 0 {
- if item.UserOrgId != 10644 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
- }
-
- }
- }
- //不通过药房发药
- if pharmacyConfig.IsOpen != 1 {
- //执行出库
-
- drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
- if drugOutInfo.ID == 0 {
- if item.UserOrgId != 10644 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
- }
-
- }
- }
-
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
- //查询默认仓库剩余多少库存
- var sum_count int64
- //更新字典里面的库存
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
-
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
-
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- break
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
- if medical.IsUse == 1 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
- } else {
- if medical.IsUse == 1 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
- }
-
- } else {
- pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
- if medical.IsUse == 2 {
- //是通过药房发药
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
-
- drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
- if drugOutInfo.ID == 0 {
- if item.UserOrgId != 10644 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
- }
-
- }
- }
- //不通过药房发药
- if pharmacyConfig.IsOpen != 1 {
-
- drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
- if drugOutInfo.ID == 0 {
- if item.UserOrgId != 10644 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
- }
-
- }
- }
- //更新字典里面的库存
- var sum_count int64
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- break
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
- if medical.IsUse == 1 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
- }
- }
- }
- }
-
- //自备药
- selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
-
- if selfPrescriptionOutOpen.IsOpen == 1 {
-
- db := service.XTWriteDB()
- tx := db.Begin()
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
-
- selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
-
- if selfBasedrug.IsSelfDrug == 1 {
-
- //查询是否有库存
- info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
-
- if len(info) > 0 {
- var total_count int64
- var prescribing_number_total int64
- for _, item := range info {
- if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
- }
-
- total_count += item.StockMaxNumber + item.StockMinNumber
- }
-
- //判断单位是否相等
- if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //转化为最小单位
- prescribing_number_total = count * selfBasedrug.MinNumber
- }
-
- if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- prescribing_number_total = count
-
- }
-
- if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- prescribing_number_total = count
-
- }
-
- if prescribing_number_total > total_count {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "advice": advice,
- })
- return
- }
- var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
- //出库
- if prescribing_number_total <= total_count {
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
-
- creater := c.GetAdminUserInfo().AdminUser.Id
- //创建一个出库单
- drugWarehouseOut := models.XtSelfDrugWarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: c.GetAdminUserInfo().CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: advice.AdviceDate,
- Type: 0,
- PatientId: advice.PatientId,
- IsCheck: 1,
- IsSys: 1,
- }
-
- //查询今日是否有出库数据
- lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
-
- if lastWarehouseOut.ID == 0 {
- service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
- }
-
- //查询今日是否有出库数据
- lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
- //出库
- warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
- WarehouseOutId: lastWarehouseOutOne.ID,
- WarehouseOutOrderNumber: warehousing_out_order,
- DrugId: advice.DrugId,
- Count: prescribing_number_total,
- Price: 0,
- TotalPrice: 0,
- Status: 1,
- Ctime: advice.AdviceDate,
- Mtime: advice.AdviceDate,
- Remark: "",
- OrgId: advice.UserOrgId,
- Type: 0,
- Manufacturer: selfBasedrug.Manufacturer,
- Dealer: selfBasedrug.Dealer,
- RetailPrice: 0,
- RetailTotalPrice: 0,
- CountUnit: selfBasedrug.MinUnit,
- ExpiryDate: 0,
- ProductDate: 0,
- Number: "",
- BatchNumber: "",
- IsSys: 0,
- WarehouseInfoId: 0,
- AdminUserId: 0,
- StockCount: "",
- IsCheck: 1,
- SysRecordTime: advice.AdviceDate,
- PatientId: advice.PatientId,
- AdviceId: advice.ID,
- ClassType: "",
- }
- warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
-
- for _, it := range warehousingOutInfo {
-
- medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
- drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
- //出库逻辑
- service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
-
- //查询剩余库存
- stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
- }
- }
-
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "advice": advice,
- })
- return
- }
-
- }
-
- }
-
- advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
- for _, item := range advices {
-
- if item.Way == 2 {
- if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
- if item.ExecutionState == 1 {
- prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- //插入自备药出库单
- outStock := models.XtSelfOutStock{
- DrugName: item.AdviceName,
- DrugNameId: item.DrugId,
- DrugSpec: item.AdviceDesc,
- OutstoreNumber: count,
- AdminUserId: adminUserInfo.AdminUser.Id,
- StorckTime: item.RecordDate,
- UserOrgId: adminUserInfo.CurrentOrgId,
- CreatedTime: time.Now().Unix(),
- Status: 1,
- PatientId: item.PatientId,
- ExitMode: 2,
- MedicId: item.DrugId,
- StockOutNumber: warehousing_out_order,
- }
- service.CreateOutStock(&outStock)
- }
- }
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
-
- } else {
-
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(executionTime) <= 0 {
- utils.ErrorLog("execution_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
-
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
-
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- //医嘱已执行
- if advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
- return
- }
-
- executionStaff := adminUserInfo.AdminUser.Id
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if advice.StartTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- exceAdvice := models.HisDoctorAdviceInfo{
- ExecutionStaff: executionStaff,
- ExecutionTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- if advice.ParentId > 0 {
- err = service.ExceHidDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
- //记录日志
- byterequest, _ := json.Marshal(exceAdvice)
- doctorAdviceLog := models.XtDoctorAdviceLog{
- UserOrgId: exceAdvice.UserOrgId,
- PatientId: exceAdvice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 2,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端执行His医嘱",
- RecordDate: exceAdvice.RecordDate,
- }
- service.CreateDoctorAdviceLog(doctorAdviceLog)
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
-
- theTimes := theTime.Format("2006-01-02")
-
- keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
-
- defer redis.Close()
- } else {
- err = service.ExceHidDoctorAdviceById(&exceAdvice, id, patient)
- //记录日志
- byterequest, _ := json.Marshal(exceAdvice)
- doctorAdviceLog := models.XtDoctorAdviceLog{
- UserOrgId: exceAdvice.UserOrgId,
- PatientId: exceAdvice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 2,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端执行His医嘱",
- RecordDate: exceAdvice.RecordDate,
- }
- service.CreateDoctorAdviceLog(doctorAdviceLog)
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
-
- theTimes := theTime.Format("2006-01-02")
-
- fmt.Println("theTIME", theTime)
- keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
-
- defer redis.Close()
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- advice.ExecutionStaff = executionStaff
- advice.ExecutionTime = theTime.Unix()
-
- //处理出库相关逻辑
-
- //1.判断是否启用药品管理和自备药出库功能
-
- //药品自动出库开关管理信息
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
-
- if drugStockConfig.IsOpen == 1 {
- //查询已经执行的医嘱
- advices, _ := service.GetHisExecutionDoctorsTwo(adminUserInfo.CurrentOrgId, patient, id)
- for _, item := range advices {
- medical, _ := service.GetBaseDrugMedical(advice.DrugId)
-
- var total int64
- var prescribing_number_total int64
- //药品保存处方出库
- config, _ := service.GetDrugOpenConfigOne(adminUserInfo.CurrentOrgId)
- if config.IsOpen != 1 {
- //查询默认出库仓库
- houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
-
- //查询该药品在默认仓库是否有库存
- list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
-
- //判断单位是否相等
- if medical.MaxUnit == advice.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //转化为最小单位
- total = list.Count*medical.MinNumber + list.StockMinNumber
- prescribing_number_total = count * medical.MinNumber
- }
-
- if medical.MinUnit == advice.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total = list.Count*medical.MinNumber + list.StockMinNumber
-
- prescribing_number_total = count
-
- }
-
- if medical.IsUse == 1 {
- drugError := models.XtDrugError{
- UserOrgId: item.UserOrgId,
- DrugId: item.DrugId,
- RecordDate: item.AdviceDate,
- PatientId: item.PatientId,
- Remark: "电脑端零用药品",
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
- Prescribingnumber: item.PrescribingNumber,
- PrescribingNumberUnit: item.PrescribingNumberUnit,
- }
- service.CreateDrugError(drugError)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
- if medical.IsUse != 1 {
- if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
- drugError := models.XtDrugError{
- UserOrgId: item.UserOrgId,
- DrugId: item.DrugId,
- RecordDate: item.AdviceDate,
- PatientId: item.PatientId,
- Remark: "电脑端药品库存不足",
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
- Prescribingnumber: item.PrescribingNumber,
- PrescribingNumberUnit: item.PrescribingNumberUnit,
- }
- service.CreateDrugError(drugError)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "advice": advice,
- })
- return
- }
-
- if prescribing_number_total > total {
- drugError := models.XtDrugError{
- UserOrgId: item.UserOrgId,
- DrugId: item.DrugId,
- RecordDate: item.AdviceDate,
- PatientId: item.PatientId,
- Remark: "电脑端出库数量大于总库存",
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
- Prescribingnumber: item.PrescribingNumber,
- PrescribingNumberUnit: item.PrescribingNumberUnit,
- }
- service.CreateDrugError(drugError)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "advice": advice,
- })
- return
- }
- }
-
- if prescribing_number_total <= total {
- pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
-
- if medical.IsUse == 2 {
- if config.IsOpen != 1 {
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
- // 开始主事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
- creater := c.GetAdminUserInfo().AdminUser.Id
- outListExport, _ := service.GetWarehouseOutListExport(item.DrugId, item.PatientId, item.AdviceDate, item.ID)
- var out_count int64
- if len(outListExport) > 0 {
- for _, item := range outListExport {
- if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- out_count = item.Count * medical.MinNumber
- }
- if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- out_count = item.Count
- }
- if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- out_count = item.Count * medical.MinNumber
- }
-
- }
- }
-
- newadviceInfo := &models.HisDoctorAdviceInfo{
- ID: item.ID,
- UserOrgId: item.UserOrgId,
- PatientId: item.PatientId,
- HisPatientId: item.HisPatientId,
- AdviceType: item.AdviceType,
- AdviceDate: item.AdviceDate,
- StartTime: item.StartTime,
- AdviceName: item.AdviceName,
- AdviceDesc: item.AdviceDesc,
- ReminderDate: item.ReminderDate,
- SingleDose: item.SingleDose,
- SingleDoseUnit: item.SingleDoseUnit,
- PrescribingNumber: item.PrescribingNumber,
- PrescribingNumberUnit: item.PrescribingNumberUnit,
- DeliveryWay: item.DeliveryWay,
- ExecutionFrequency: item.ExecutionFrequency,
- AdviceDoctor: item.AdviceDoctor,
- Status: item.Status,
- CreatedTime: item.CreatedTime,
- UpdatedTime: item.UpdatedTime,
- AdviceAffirm: item.AdviceAffirm,
- Remark: item.Remark,
- StopTime: item.StopTime,
- StopReason: item.StopReason,
- StopDoctor: item.StopDoctor,
- StopState: item.StopState,
- ParentId: item.ParentId,
- ExecutionTime: item.ExecutionTime,
- ExecutionStaff: item.ExecutionStaff,
- ExecutionState: item.ExecutionState,
- Checker: item.Checker,
- RecordDate: item.RecordDate,
- DialysisOrderId: item.DialysisOrderId,
- CheckTime: item.CheckTime,
- CheckState: item.CheckState,
- DrugSpec: item.DrugSpec,
- DrugSpecUnit: item.DrugSpecUnit,
- Groupno: item.Groupno,
- RemindType: item.RemindType,
- FrequencyType: item.FrequencyType,
- DayCount: item.DayCount,
- WeekDay: item.WeekDay,
- TemplateId: item.TemplateId,
- Modifier: item.Modifier,
- DrugId: item.DrugId,
- Price: item.Price,
- PrescriptionId: item.PrescriptionId,
- MedListCodg: item.MedListCodg,
- FeedetlSn: item.FeedetlSn,
- Day: item.DayCount,
- ChildDoctorAdvice: nil,
- Drug: models.Drug{},
- Diagnosis: item.Diagnosis,
- Way: item.Way,
- HospApprFlag: item.HospApprFlag,
- LmtUsedFlag: item.LmtUsedFlag,
- HisOrderInfo: models.HisOrderInfo{},
- IsMedicine: item.IsMedicine,
- ExecutionFrequencyId: item.ExecutionFrequencyId,
- Child: nil,
- IsSettle: item.IsSettle,
- IsMobile: item.IsMobile,
- IsSelfDrug: item.IsSelfDrug,
- DrugWayCount: item.DrugWayCount,
- }
-
- //如果当前医嘱数量大于历史出库数据则需要出库
- if prescribing_number_total > out_count {
-
- //按最小单位出库
- var cha_count = prescribing_number_total - out_count
-
- item.PrescribingNumber = float64(cha_count)
- item.PrescribingNumberUnit = medical.MinUnit
-
- service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
-
- }
-
- //如果当前医嘱数量小于历史出库数据则需要退库
- if prescribing_number_total < out_count {
- var cha_count = out_count - prescribing_number_total
- drug, _ := service.FindBaseDrugLibRecordSeven(item.UserOrgId, item.DrugId)
- service.NewHisDrugCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
- service.NewHisDrugAutoCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
-
- }
-
- if prescribing_number_total == out_count {
- if out_count == 0 {
- service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
- }
-
- }
- //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
-
- if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
- //查询该药品是否有出库记录
- flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
- if len(flowMap) == 0 {
- errs := service.UpdateHisAdviceById(item.ID)
- if errs != nil {
- drugError := models.XtDrugError{
- UserOrgId: item.UserOrgId,
- DrugId: item.DrugId,
- RecordDate: item.AdviceDate,
- PatientId: item.PatientId,
- Remark: "出库记录为空,更新执行人失败",
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
- Prescribingnumber: item.PrescribingNumber,
- PrescribingNumberUnit: item.PrescribingNumberUnit,
- }
- service.CreateDrugError(drugError)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "6",
- "advice": advice,
- })
- return
- }
- }
-
- tx.Commit()
- }
- //不通过药房发药
- if pharmacyConfig.IsOpen != 1 {
- //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
- // 开始主事务
- db := service.XTWriteDB()
- tx := db.Begin()
-
- // 在函数结束时处理事务回滚
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- }
- }()
- creater := c.GetAdminUserInfo().AdminUser.Id
- outListExport, _ := service.GetWarehouseOutListExport(item.DrugId, item.PatientId, item.AdviceDate, item.ID)
- var out_count int64
- if len(outListExport) > 0 {
- for _, item := range outListExport {
- if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
- out_count = item.Count * medical.MinNumber
- }
- if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
- out_count = item.Count
- }
- if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
- out_count = item.Count * medical.MinNumber
- }
-
- }
- }
-
- newadviceInfo := &models.HisDoctorAdviceInfo{
- ID: item.ID,
- UserOrgId: item.UserOrgId,
- PatientId: item.PatientId,
- HisPatientId: item.HisPatientId,
- AdviceType: item.AdviceType,
- AdviceDate: item.AdviceDate,
- StartTime: item.StartTime,
- AdviceName: item.AdviceName,
- AdviceDesc: item.AdviceDesc,
- ReminderDate: item.ReminderDate,
- SingleDose: item.SingleDose,
- SingleDoseUnit: item.SingleDoseUnit,
- PrescribingNumber: item.PrescribingNumber,
- PrescribingNumberUnit: item.PrescribingNumberUnit,
- DeliveryWay: item.DeliveryWay,
- ExecutionFrequency: item.ExecutionFrequency,
- AdviceDoctor: item.AdviceDoctor,
- Status: item.Status,
- CreatedTime: item.CreatedTime,
- UpdatedTime: item.UpdatedTime,
- AdviceAffirm: item.AdviceAffirm,
- Remark: item.Remark,
- StopTime: item.StopTime,
- StopReason: item.StopReason,
- StopDoctor: item.StopDoctor,
- StopState: item.StopState,
- ParentId: item.ParentId,
- ExecutionTime: item.ExecutionTime,
- ExecutionStaff: item.ExecutionStaff,
- ExecutionState: item.ExecutionState,
- Checker: item.Checker,
- RecordDate: item.RecordDate,
- DialysisOrderId: item.DialysisOrderId,
- CheckTime: item.CheckTime,
- CheckState: item.CheckState,
- DrugSpec: item.DrugSpec,
- DrugSpecUnit: item.DrugSpecUnit,
- Groupno: item.Groupno,
- RemindType: item.RemindType,
- FrequencyType: item.FrequencyType,
- DayCount: item.DayCount,
- WeekDay: item.WeekDay,
- TemplateId: item.TemplateId,
- Modifier: item.Modifier,
- DrugId: item.DrugId,
- Price: item.Price,
- PrescriptionId: item.PrescriptionId,
- MedListCodg: item.MedListCodg,
- FeedetlSn: item.FeedetlSn,
- Day: item.DayCount,
- ChildDoctorAdvice: nil,
- Drug: models.Drug{},
- Diagnosis: item.Diagnosis,
- Way: item.Way,
- HospApprFlag: item.HospApprFlag,
- LmtUsedFlag: item.LmtUsedFlag,
- HisOrderInfo: models.HisOrderInfo{},
- IsMedicine: item.IsMedicine,
- ExecutionFrequencyId: item.ExecutionFrequencyId,
- Child: nil,
- IsSettle: item.IsSettle,
- IsMobile: item.IsMobile,
- IsSelfDrug: item.IsSelfDrug,
- DrugWayCount: item.DrugWayCount,
- }
-
- //如果当前医嘱数量大于历史出库数据则需要出库
- if prescribing_number_total > out_count {
-
- //按最小单位出库
- var cha_count = prescribing_number_total - out_count
-
- newadviceInfo.PrescribingNumber = float64(cha_count)
- newadviceInfo.PrescribingNumberUnit = medical.MinUnit
-
- service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
-
- }
-
- //如果当前医嘱数量小于历史出库数据则需要退库
- if prescribing_number_total < out_count {
- var cha_count = out_count - prescribing_number_total
- drug, _ := service.FindBaseDrugLibRecordSeven(item.UserOrgId, item.DrugId)
- service.NewHisDrugCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
- service.NewHisDrugAutoCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
-
- }
-
- if prescribing_number_total == out_count {
- if out_count == 0 {
- service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
- }
-
- }
- //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
-
- tx.Commit()
- if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
- //查询该药品是否有出库记录
- flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
- if len(flowMap) == 0 {
- errs := service.UpdateHisAdviceById(item.ID)
- if errs != nil {
- drugError := models.XtDrugError{
- UserOrgId: item.UserOrgId,
- DrugId: item.DrugId,
- RecordDate: item.AdviceDate,
- PatientId: item.PatientId,
- Remark: "出库记录为空,更新执行人失败",
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
- Prescribingnumber: item.PrescribingNumber,
- PrescribingNumberUnit: item.PrescribingNumberUnit,
- }
- service.CreateDrugError(drugError)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "6",
- "advice": advice,
- })
- return
- }
- }
- }
- //查询默认仓库
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
- //查询默认仓库剩余多少库存
- var sum_count int64
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
-
- //出库数量累加
- //service.AddDrugCount(item.DrugId,item.UserOrgId,storeHouseConfig.DrugStorehouseOut,prescribing_number_total)
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- break
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
- }
-
- if medical.IsUse == 1 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
-
- }
- }
- }
-
- }
-
- //自备药
-
- selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
-
- if selfPrescriptionOutOpen.IsOpen == 1 {
-
- db := service.XTWriteDB()
- tx := db.Begin()
- defer func() {
- if r := recover(); r != nil {
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
-
- selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
-
- if selfBasedrug.IsSelfDrug == 1 {
-
- //查询是否有库存
- info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
-
- if len(info) > 0 {
- var total_count int64
- var prescribing_number_total int64
- for _, item := range info {
- if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
- }
-
- total_count += item.StockMaxNumber + item.StockMinNumber
- }
-
- //判断单位是否相等
- if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //转化为最小单位
- prescribing_number_total = count * selfBasedrug.MinNumber
- }
-
- if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- prescribing_number_total = count
-
- }
-
- if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- prescribing_number_total = count
-
- }
-
- if prescribing_number_total > total_count {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "advice": advice,
- })
- return
- }
- var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
- //出库
- if prescribing_number_total <= total_count {
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
- operation_time := time.Now().Unix()
-
- creater := c.GetAdminUserInfo().AdminUser.Id
- //创建一个出库单
- drugWarehouseOut := models.XtSelfDrugWarehouseOut{
- WarehouseOutOrderNumber: warehousing_out_order,
- OperationTime: operation_time,
- OrgId: c.GetAdminUserInfo().CurrentOrgId,
- Creater: creater,
- Ctime: time.Now().Unix(),
- Status: 1,
- WarehouseOutTime: advice.AdviceDate,
- Type: 0,
- PatientId: advice.PatientId,
- IsCheck: 1,
- IsSys: 1,
- }
-
- //查询今日是否有出库数据
- lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
-
- if lastWarehouseOut.ID == 0 {
- service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
- }
- //查询今日是否有出库数据
- lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
-
- //出库
- warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
- WarehouseOutId: lastWarehouseOutOne.ID,
- WarehouseOutOrderNumber: warehousing_out_order,
- DrugId: advice.DrugId,
- Count: prescribing_number_total,
- Price: 0,
- TotalPrice: 0,
- Status: 1,
- Ctime: advice.AdviceDate,
- Mtime: advice.AdviceDate,
- Remark: "",
- OrgId: advice.UserOrgId,
- Type: 0,
- Manufacturer: selfBasedrug.Manufacturer,
- Dealer: selfBasedrug.Dealer,
- RetailPrice: 0,
- RetailTotalPrice: 0,
- CountUnit: selfBasedrug.MinUnit,
- ExpiryDate: 0,
- ProductDate: 0,
- Number: "",
- BatchNumber: "",
- IsSys: 0,
- WarehouseInfoId: 0,
- AdminUserId: 0,
- StockCount: "",
- IsCheck: 1,
- SysRecordTime: advice.AdviceDate,
- PatientId: advice.PatientId,
- AdviceId: advice.ID,
- ClassType: "",
- }
- warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
-
- for _, it := range warehousingOutInfo {
-
- medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
- drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
- //出库逻辑
- service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
-
- //查询剩余库存
- stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
- }
- }
-
- }
-
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
-
- }
-
- }
-
- func (c *PatientApiController) CheckGroupAdvice() {
- groupno, _ := c.GetInt64("groupno", 0)
-
- if groupno <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- if advice.CheckState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
- return
- }
-
- if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
- return
- }
-
- checker := adminUserInfo.AdminUser.Id
-
- theTime := time.Now()
-
- exceAdvice := models.DoctorAdvice{
- Checker: checker,
- CheckTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- var err error
- err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- advice.Checker = checker
- advice.CheckTime = theTime.Unix()
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
-
- func (c *PatientApiController) CheckDoctorAdvice() {
- patient, _ := c.GetInt64("patient", 0)
- id, _ := c.GetInt64("id", 0)
- origin, _ := c.GetInt64("origin", 0)
-
- if origin != 2 {
- // executionTime := c.GetString("execution_time")
-
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- if advice.CheckState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
- return
- }
-
- if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
- return
- }
-
- // executionStaff := adminUserInfo.AdminUser.Id
- checker := adminUserInfo.AdminUser.Id
-
- // timeLayout := "2006-01-02 15:04:05"
- // loc, _ := time.LoadLocation("Local")
-
- // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
- // if err != nil {
- // utils.ErrorLog(err.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
-
- theTime := time.Now()
-
- if advice.ExecutionTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
- return
- }
- exceAdvice := models.DoctorAdvice{
- Checker: checker,
- CheckTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- var err error
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= advice.AdviceDate {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
- if advice.ParentId > 0 {
- err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
- //记录日志
- byterequest, _ := json.Marshal(exceAdvice)
- adviceLog := models.XtDoctorAdviceLog{
- UserOrgId: exceAdvice.UserOrgId,
- PatientId: exceAdvice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 3,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "核对医嘱",
- RecordDate: exceAdvice.AdviceDate,
- }
-
- service.CreateDoctorAdviceLog(adviceLog)
-
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- } else {
- err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
- //记录日志
- byterequest, _ := json.Marshal(exceAdvice)
- adviceLog := models.XtDoctorAdviceLog{
- UserOrgId: exceAdvice.UserOrgId,
- PatientId: exceAdvice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 3,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "核对医嘱",
- RecordDate: exceAdvice.AdviceDate,
- }
-
- service.CreateDoctorAdviceLog(adviceLog)
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- // advice.ExecutionStaff = executionStaff
- // advice.ExecutionTime = theTime.Unix()
- advice.Checker = checker
- advice.CheckTime = theTime.Unix()
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
-
- } else {
-
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- if advice.CheckState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
- return
- }
-
- if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
- return
- }
- checker := adminUserInfo.AdminUser.Id
- theTime := time.Now()
-
- if advice.ExecutionTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
- return
- }
- exceAdvice := models.HisDoctorAdviceInfo{
- Checker: checker,
- CheckTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- var err error
- if advice.ParentId > 0 {
- err = service.CheckHisDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- } else {
- err = service.CheckHisDoctorAdviceById(&exceAdvice, id, patient)
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- // advice.ExecutionStaff = executionStaff
- // advice.ExecutionTime = theTime.Unix()
- advice.Checker = checker
- advice.CheckTime = theTime.Unix()
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
- }
-
- func (c *PatientApiController) UpdateDoctorAdvice() {
- patient, _ := c.GetInt64("patient", 0)
- id, _ := c.GetInt64("id", 0)
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- //if advice.AdviceType == 1 {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
- // return
- //}
-
- if adminUserInfo.CurrentOrgId != 10612 && adminUserInfo.CurrentOrgId != 10460 {
- if advice.StopState == 1 || advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
- return
- }
- }
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
-
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
- // return
- //}
-
- code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- advice.UpdatedTime = time.Now().Unix()
- advice.Modifier = adminUserInfo.AdminUser.Id
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= advice.AdviceDate {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
-
- err := service.UpdateDoctorAdvice(&advice)
-
- //记录日志
- byterequest, _ := json.Marshal(advice)
- doctorAdviceLog := models.XtDoctorAdviceLog{
- UserOrgId: advice.UserOrgId,
- PatientId: advice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 1,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端修改医嘱",
- RecordDate: advice.AdviceDate,
- }
- service.CreateDoctorAdviceLog(doctorAdviceLog)
- redis := service.RedisClient()
-
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
-
- redis.Set(key, "", time.Second)
-
- keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
-
- func (c *PatientApiController) StopGroupAdvice() {
- groupNo, _ := c.GetInt64("groupno", 0)
- if groupNo <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
- if advice.StopState == 1 || advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
- return
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
- utils.ErrorLog("stop_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- stopTime, _ := dataBody["stop_time"].(string)
- if len(stopTime) == 0 {
- utils.ErrorLog("len(stop_time) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice.StopTime = theTime.Unix()
-
- if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
- stopReason, _ := dataBody["stop_reason"].(string)
- advice.StopReason = stopReason
- }
-
- advice.UpdatedTime = time.Now().Unix()
- advice.StopDoctor = adminUserInfo.AdminUser.Id
- advice.StopState = 1
-
- err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- func (c *PatientApiController) StopDoctorAdvice() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- //
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
- if advice.StopState == 1 || advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
- return
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
- utils.ErrorLog("stop_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- stopTime, _ := dataBody["stop_time"].(string)
- if len(stopTime) == 0 {
- utils.ErrorLog("len(stop_time) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice.StopTime = theTime.Unix()
-
- if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
- stopReason, _ := dataBody["stop_reason"].(string)
- advice.StopReason = stopReason
- }
-
- advice.UpdatedTime = time.Now().Unix()
- advice.StopDoctor = adminUserInfo.AdminUser.Id
- advice.StopState = 1
-
- err = service.StopDoctorAdvice(&advice)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
-
- func (c *PatientApiController) DeleteDoctorAdvice() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- //}
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- //
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- advice.UpdatedTime = time.Now().Unix()
- advice.Status = 0
- advice.Modifier = adminUserInfo.AdminUser.Id
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= advice.AdviceDate {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
- //自备药
- selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
-
- if selfPrescriptionOutOpenOne.IsOpen == 1 {
- //查询库存是否是自备药
- selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
-
- if selfBasedrug.IsSelfDrug == 1 {
- creater := adminUserInfo.AdminUser.Id
- //退库
- service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
- }
- }
-
- err := service.DeleteDoctorAdvice(&advice)
-
- //记录日志
- byterequest, _ := json.Marshal(advice)
- doctorAdviceLog := models.XtDoctorAdviceLog{
- UserOrgId: advice.UserOrgId,
- PatientId: advice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 4,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端删除医嘱",
- RecordDate: advice.RecordDate,
- }
- service.CreateDoctorAdviceLog(doctorAdviceLog)
- redis := service.RedisClient()
- keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
-
- redis.Set(keyOne, "", time.Second)
-
- key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(key, "", time.Second)
- redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- func (c *PatientApiController) DeleteGroupAdvice() {
- groupNo, _ := c.GetInt64("groupno", 0)
- if groupNo <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- //自备药
- selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
-
- if selfPrescriptionOutOpenOne.IsOpen == 1 {
- //查询库存是否是自备药
- selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
-
- if selfBasedrug.IsSelfDrug == 1 {
- creater := adminUserInfo.AdminUser.Id
- //退库
- service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
- }
- }
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- // 查询信息规挡的设置天数
-
- infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
- if infor.ID > 0 && infor.WeekDay > 0 {
-
- var cha_time int64
-
- timeNowStr := time.Now().Format("2006-01-02")
- timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
-
- //今日的日期减去设置的日期
- cha_time = timeNewDate.Unix() - infor.WeekDay*86400
-
- if cha_time >= advice.AdviceDate {
- //查询审核是否允许
- infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
- //申请状态不允许的情况 拒绝修改
- if infor.ApplicationStatus != 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
- return
- }
-
- }
- }
-
- err := service.DeleteGroupAdviceOne(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
-
- byterequest, _ := json.Marshal(advice)
- doctorAdviceLog := models.XtDoctorAdviceLog{
- UserOrgId: advice.UserOrgId,
- PatientId: advice.PatientId,
- AdminUserId: adminUserInfo.AdminUser.Id,
- Module: 4,
- ErrLog: string(byterequest),
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Source: "电脑端批量删除医嘱",
- RecordDate: advice.RecordDate,
- }
- service.CreateDoctorAdviceLog(doctorAdviceLog)
-
- key := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
-
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
-
- defer redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- // GetDoctorAdvices 医嘱列表
- func (c *PatientApiController) GetDoctorAdvices() {
- id, _ := c.GetInt64("id", 0)
- adviceType, _ := c.GetInt64("advice_type", 0)
- stopType, _ := c.GetInt64("stop_state", 0)
- startTime := c.GetString("start_time", "")
- endTime := c.GetString("end_time", "")
- keywords := c.GetString("keywords", "")
- page, _ := c.GetInt64("page")
- limit, _ := c.GetInt64("limit")
- adminUserInfo := c.GetAdminUserInfo()
-
- delivery_way_one := c.GetString("delivery_way_one", "")
- operatorIDs := make([]int64, 0)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTIme int64
- if len(startTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theStartTIme = theTime.Unix()
- }
- var theEndtTIme int64
- if len(endTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theEndtTIme = theTime.Unix()
- }
-
- hisconfig, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
-
- if hisconfig.IsOpen == 1 {
- advices, total, _ := service.GetDoctorAdviceListThree(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit, delivery_way_one)
- advicestwo, _, _ := service.GetDoctorAdviceListFour(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page, delivery_way_one)
-
- if len(advices) > 0 {
- for _, item := range advices {
- if item.AdviceDoctor > 0 {
- operatorIDs = append(operatorIDs, item.AdviceDoctor)
- }
- if item.ExecutionStaff > 0 {
- operatorIDs = append(operatorIDs, item.ExecutionStaff)
- }
- if item.Checker > 0 {
- operatorIDs = append(operatorIDs, item.Checker)
- }
- if item.StopDoctor > 0 {
- operatorIDs = append(operatorIDs, item.StopDoctor)
- }
- }
- }
-
- //相关操作对应的操作人
- operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
-
- //获取长期医嘱
- longAdvice, _, _ := service.GetLongDoctorAdviceList(adminUserInfo.CurrentOrgId, id, 1, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
- c.ServeSuccessJSON(map[string]interface{}{
- "advices": advices,
- "operators": operators,
- "total": total,
- "advicetwo": advicestwo,
- "longAdvice": longAdvice,
- "is_open": hisconfig.IsOpen,
- })
- return
- } else {
- advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit, delivery_way_one)
- advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page, delivery_way_one)
-
- if len(advices) > 0 {
- for _, item := range advices {
- if item.AdviceDoctor > 0 {
- operatorIDs = append(operatorIDs, item.AdviceDoctor)
- }
- if item.ExecutionStaff > 0 {
- operatorIDs = append(operatorIDs, item.ExecutionStaff)
- }
- if item.Checker > 0 {
- operatorIDs = append(operatorIDs, item.Checker)
- }
- if item.StopDoctor > 0 {
- operatorIDs = append(operatorIDs, item.StopDoctor)
- }
- }
- }
-
- //相关操作对应的操作人
- operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "advices": advices,
- "operators": operators,
- "total": total,
- "advicetwo": advicestwo,
- "is_open": hisconfig.IsOpen,
- })
- return
- }
-
- }
-
- func (c *PatientApiController) GetPatientSchedules() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- todayTime := time.Now().Format("2006-01-02")
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTime int64
- theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
- theStartTime = theTime.Unix()
-
- schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
- if len(schedules) > 0 {
- for index, item := range schedules {
- _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
- schedules[index].Week = int64(week)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "schedules": schedules,
- })
- return
- }
-
- func (c *PatientApiController) GetPatientDialysisRecords() {
- patientID, _ := c.GetInt64("patient_id", 0)
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- startTime := c.GetString("start_time", "")
- endTime := c.GetString("end_time", "")
- mode_id, _ := c.GetInt64("mode_id", 0)
-
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- if patientID <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTIme int64
- if len(startTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
- if err != nil {
- theStartTIme = 0
- }
- theStartTIme = theTime.Unix()
- }
- var theEndtTIme int64
- if len(endTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
- if err != nil {
- theEndtTIme = 0
- }
- theEndtTIme = theTime.Unix()
- }
-
- adminInfo := c.GetAdminUserInfo()
- records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
-
- if len(records) == 0 {
- list, _ := service.GetAllDialysisOrder(patientID)
- for _, item := range list {
- schedule, _ := service.GetLastScheduleByUserOrg(item.PatientId, item.DialysisDate, adminInfo.CurrentOrgId, item.BedId, item.ZoneId, item.SchedualType)
- service.UpdateScheduleByOrder(item.PatientId, item.DialysisDate, adminInfo.CurrentOrgId, item.BedId, item.ZoneId, item.SchedualType, schedule.ID)
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "records": records,
- })
- return
- }
-
- func (c *PatientApiController) ProEducation() {
- patientID, _ := c.GetInt64("patient_id", 0)
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- startTime := c.GetString("start_time", "")
- endTime := c.GetString("end_time", "")
-
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- if patientID <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTIme int64
- if len(startTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
- if err != nil {
- theStartTIme = 0
- }
- theStartTIme = theTime.Unix()
- }
- var theEndtTIme int64
- if len(endTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
- if err != nil {
- theEndtTIme = 0
- }
- theEndtTIme = theTime.Unix()
- }
-
- adminInfo := c.GetAdminUserInfo()
- edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "edus": edus,
- })
- return
- }
-
- func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- isChild := false
-
- if action == "create" {
- if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
- utils.ErrorLog("advice_type")
- code = enums.ErrorCodeParamWrong
- return
- }
- adviceType := int64(dataBody["advice_type"].(float64))
- if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
- utils.ErrorLog("advice_type != 1&&2")
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.AdviceType = adviceType
-
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- code = enums.ErrorCodeParamWrong
- return
- }
- adviceDate, _ := dataBody["advice_date"].(string)
- if len(adviceDate) == 0 {
- utils.ErrorLog("len(adviceDate) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.AdviceDate = theTime.Unix()
- advice.RecordDate = theTime.Unix()
-
- if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
- parentId := int64(dataBody["parent_id"].(float64))
- advice.ParentId = parentId
- if parentId > 0 {
- isChild = true
- }
- }
- }
-
- if !isChild {
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- code = enums.ErrorCodeParamWrong
- return
- }
- startTime, _ := dataBody["start_time"].(string)
- if len(startTime) == 0 {
- utils.ErrorLog("len(start_time) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.StartTime = theTime.Unix()
-
- // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
- // utils.ErrorLog("advice_doctor")
- // code = enums.ErrorCodeParamWrong
- // return
- // }
- // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
- // if adviceDoctor <= 0 {
- // utils.ErrorLog("advice_doctor <=0")
- // code = enums.ErrorCodeParamWrong
- // return
- // }
- // advice.AdviceDoctor = adviceDoctor
-
- if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
- deliveryWay, _ := dataBody["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
-
- if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
- executionFrequency, _ := dataBody["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if advice.AdviceType == 1 && advice.ParentId == 0 {
-
- if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
- frequency_type := int64(dataBody["frequency_type"].(float64))
- advice.FrequencyType = frequency_type
- }
-
- if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
- day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
- advice.DayCount = day_count
- }
-
- if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
- week_day, _ := dataBody["week_days"].(string)
- advice.WeekDay = week_day
- }
- }
-
- }
-
- if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
- utils.ErrorLog("advice_name")
- code = enums.ErrorCodeParamWrong
- return
- }
- adviceName, _ := dataBody["advice_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.AdviceName = adviceName
-
- if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
- adviceDsc, _ := dataBody["advice_desc"].(string)
- advice.AdviceDesc = adviceDsc
- }
-
- if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
- dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
- advice.DialysisOrderId = int64(dialysisOrderId)
- }
-
- if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
- if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "float64" {
- singleDose := dataBody["single_dose"].(float64)
- advice.SingleDose = singleDose
- }
-
- if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
- if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "float64" {
- tmp := dataBody["single_dose_unit"].(float64)
- singleDoseUnit := service.TypeConversion(tmp)
- advice.SingleDoseUnit = singleDoseUnit
- }
-
- if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
-
- if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
- drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
-
- if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
- if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "float64" {
- prescribingNumber := dataBody["prescribing_number"].(float64)
- advice.PrescribingNumber = prescribingNumber
- }
-
- if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
-
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark, _ := dataBody["remark"].(string)
- advice.Remark = remark
- }
-
- if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "string" {
- drug_id, _ := dataBody["drug_id"].(string)
- tmpDrugId, _ := strconv.ParseInt(drug_id, 10, 64)
- advice.DrugId = tmpDrugId
- }
- if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
- drug_id, _ := dataBody["drug_id"].(float64)
- advice.DrugId = int64(drug_id)
- }
-
- if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
- drug_name_id, _ := dataBody["drug_name_id"].(float64)
- advice.DrugNameId = int64(drug_name_id)
- }
-
- if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
- way, _ := dataBody["way"].(float64)
- advice.Way = int64(way)
- }
-
- if dataBody["push_start_time"] != nil && reflect.TypeOf(dataBody["push_start_time"]).String() == "string" {
- push_start_time, _ := dataBody["push_start_time"].(string)
- var startTime int64
- if len(push_start_time) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
-
- startTime = theTime.Unix()
- }
- advice.PushStartTime = startTime
- }
-
- return
- }
-
- func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &dataBody)
- utils.InfoLog(string(data))
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
-
- if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
- dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
- solution.DialysisDuration = dialysisDuration
- }
-
- if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
- replacementWay := int64(dataBody["replacement_way"].(float64))
- solution.ReplacementWay = replacementWay
- }
-
- if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
- bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
- solution.BloodFlowVolume = bloodFlowVolume
- }
-
- if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
- hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
- solution.HemodialysisMachine = hemodialysisMachine
- }
-
- if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
- bloodFilter := int64(dataBody["blood_filter"].(float64))
- solution.BloodFilter = bloodFilter
- }
-
- if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
- perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
- solution.PerfusionApparatus = perfusionApparatus
- }
-
- if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
- dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
- solution.DialysateFlow = dialysateFlow
- }
-
- if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
- kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
- solution.Kalium = kalium
- }
-
- if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
- sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
- solution.Sodium = sodium
- }
-
- if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
- calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
- solution.Calcium = calcium
- }
-
- if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
- bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
- solution.Bicarbonate = bicarbonate
- }
-
- if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
- anticoagulant := int64(dataBody["anticoagulant"].(float64))
- solution.Anticoagulant = anticoagulant
- }
-
- if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
- anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
- solution.AnticoagulantShouji = anticoagulantShouji
- }
-
- if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
- anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
- solution.AnticoagulantWeichi = anticoagulantWeichi
- }
-
- if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
- anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
- solution.AnticoagulantZongliang = anticoagulantZongliang
- }
-
- if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
- anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
- solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
- }
-
- if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
- anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
- solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
- }
-
- return
- }
-
- func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &dataBody)
- utils.InfoLog(string(data))
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
-
- if method == "create" {
- if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
- utils.ErrorLog("mode")
- code = enums.ErrorCodeParamWrong
- return
- }
- mode := int64(dataBody["mode"].(float64))
- if mode <= 0 {
- utils.ErrorLog("mode <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.ModeId = mode
-
- if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
- utils.ErrorLog("mode_name")
- code = enums.ErrorCodeParamWrong
- return
- }
- modeName, _ := dataBody["mode_name"].(string)
- if len(modeName) == 0 {
- utils.ErrorLog("len(mode_name) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.ModeName = modeName
- solution.Name = modeName
-
- }
-
- if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
- dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
- solution.DialysisDuration = dialysisDuration
- }
-
- if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
- targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
- solution.TargetUltrafiltration = targetUltrafiltration
- }
-
- if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
- dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
- solution.DialysateFormulation = dialysateFormulation
- }
-
- if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
- dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
- solution.DialysisDurationHour = int64(dialysisDurationHour)
- }
-
- if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
- dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
- solution.DialysisDurationMinute = int64(dialysisDurationMinute)
- }
-
- if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
- hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
- solution.HemodialysisMachine = hemodialysisMachine
- }
- if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
- dialyzer := int64(dataBody["dialyzer"].(float64))
- solution.Dialyzer = dialyzer
- }
-
- if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
- perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
- solution.PerfusionApparatus = perfusionApparatus
- }
-
- if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
- bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
- solution.BloodFlowVolume = bloodFlowVolume
- }
-
- if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
- dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
- solution.Dewater = dewater
- }
-
- if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
- displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
- solution.DisplaceLiqui = displaceLiqui
- }
-
- if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
- replacementWay := int64(dataBody["replacement_way"].(float64))
- solution.ReplacementWay = replacementWay
- }
-
- if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
- anticoagulant := int64(dataBody["anticoagulant"].(float64))
- solution.Anticoagulant = anticoagulant
- }
-
- if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
- anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
- solution.AnticoagulantShouji = anticoagulantShouji
- }
-
- if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
- anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
- solution.AnticoagulantWeichi = anticoagulantWeichi
- }
-
- if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
- anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
- solution.AnticoagulantZongliang = anticoagulantZongliang
- }
-
- if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
- anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
- solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
- }
-
- if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
- anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
- solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
- }
-
- if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
- kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
- solution.Kalium = kalium
- }
-
- if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
- sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
- solution.Sodium = sodium
- }
-
- if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
- calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
- solution.Calcium = calcium
- }
-
- if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
- bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
- solution.Bicarbonate = bicarbonate
- }
-
- if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
- glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
- solution.Glucose = glucose
- }
-
- // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
- // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
- // solution.DryWeight = dryWeight
- // }
-
- if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
- dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
- solution.DialysateFlow = dialysateFlow
- }
-
- if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
- dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
- solution.DialysateTemperature = dialysateTemperature
- }
-
- if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
- conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
- solution.Conductivity = conductivity
- }
-
- if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
- replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
- solution.ReplacementTotal = replacementTotal
- }
-
- if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
- dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
- solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
- }
-
- if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
- body_fluid := int64(dataBody["body_fluid"].(float64))
- solution.BodyFluid = body_fluid
- }
-
- if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
- body_fluid_other := dataBody["body_fluid_other"].(string)
- solution.BodyFluidOther = body_fluid_other
- }
-
- if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
- special_medicine := int64(dataBody["special_medicine"].(float64))
- solution.SpecialMedicine = special_medicine
- }
-
- if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
- special_medicine_other := dataBody["special_medicine_other"].(string)
- solution.SpecialMedicineOther = special_medicine_other
- }
-
- if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
- displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
- solution.DisplaceLiquiPart = displace_liqui_part
- }
- if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
- displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
- solution.DisplaceLiquiValue = displace_liqui_value
- }
- if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
- blood_access := int64(dataBody["blood_access"].(float64))
- solution.BloodAccess = blood_access
- }
-
- if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
- ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
- solution.Ultrafiltration = ultrafiltration
- }
-
- if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
- target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
- solution.TargetKtv = target_ktv
- }
-
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark := dataBody["remark"].(string)
- solution.Remark = remark
- }
-
- if dataBody["hemodialysis_pipelines"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines"]).String() == "string" {
- hemodialysis_pipelines := dataBody["hemodialysis_pipelines"].(string)
- solution.HemodialysisPipelines = hemodialysis_pipelines
- }
-
- if dataBody["hemodialysis_pipelines_count"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines_count"]).String() == "string" {
- hemodialysis_pipelines_count, _ := strconv.ParseFloat(dataBody["hemodialysis_pipelines_count"].(string), 64)
- solution.HemodialysisPipelinesCount = hemodialysis_pipelines_count
- }
-
- if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
- puncture_needle := dataBody["puncture_needle"].(string)
- solution.PunctureNeedle = puncture_needle
- }
-
- if dataBody["puncture_needle_count"] != nil && reflect.TypeOf(dataBody["puncture_needle_count"]).String() == "string" {
- puncture_needle_count, _ := strconv.ParseFloat(dataBody["puncture_needle_count"].(string), 64)
- solution.PunctureNeedleCount = puncture_needle_count
- }
-
- if dataBody["epo"] != nil && reflect.TypeOf(dataBody["epo"]).String() == "string" {
- epo := dataBody["epo"].(string)
- solution.Epo = epo
- }
-
- if dataBody["epo_count"] != nil && reflect.TypeOf(dataBody["epo_count"]).String() == "string" {
- epo_count, _ := strconv.ParseFloat(dataBody["epo_count"].(string), 64)
- solution.EpoCount = epo_count
- }
-
- if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
- created_time := int64(dataBody["created_time"].(float64))
-
- solution.CreatedTime = created_time
- }
-
- if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
- dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
- solution.DialysisDialyszers = dialysisDialyszers
- }
-
- if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
- dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
- solution.DialysisIrrigation = dialysisIrrigation
- }
-
- if dataBody["dialysis_strainer"] != nil && reflect.TypeOf(dataBody["dialysis_strainer"]).String() == "string" {
- dialysis_strainer := dataBody["dialysis_strainer"].(string)
- solution.DialysisStrainer = dialysis_strainer
- }
-
- if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
- plasmaSeparator := dataBody["plasma_separator"].(string)
- solution.PlasmaSeparator = plasmaSeparator
- }
-
- if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
- bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
- solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
- }
-
- if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
- oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
- solution.OxygenUptake = oxygen_uptake
- }
-
- if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
- oxygen_flow := dataBody["oxygen_flow"].(string)
- solution.OxygenFlow = oxygen_flow
- }
-
- if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
- oxygen_time := dataBody["oxygen_time"].(string)
- solution.OxygenTime = oxygen_time
- }
-
- if dataBody["max_ultrafiltration_rate"] != nil && reflect.TypeOf(dataBody["max_ultrafiltration_rate"]).String() == "string" {
- max_ultrafiltration_rate, _ := strconv.ParseFloat(dataBody["max_ultrafiltration_rate"].(string), 64)
- solution.MaxUltrafiltrationRate = max_ultrafiltration_rate
- }
-
- if dataBody["amylaceum"] != nil && reflect.TypeOf(dataBody["amylaceum"]).String() == "string" {
- amylaceum := dataBody["amylaceum"].(string)
- solution.Amylaceum = amylaceum
- }
-
- if dataBody["chaptalization"] != nil && reflect.TypeOf(dataBody["chaptalization"]).String() == "string" {
- chaptalization := dataBody["chaptalization"].(string)
- solution.Chaptalization = chaptalization
- }
-
- if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
- blood_access_part_id := dataBody["blood_access_part_id"].(string)
- solution.BloodAccessPartId = blood_access_part_id
- }
- return
- }
-
- func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &dataBody)
- utils.InfoLog(string(data))
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
-
- if method == "create" {
-
- if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
- utils.ErrorLog("parent_id")
- code = enums.ErrorCodeParamWrong
- return
- }
- parentID := int64(dataBody["parent_id"].(float64))
- if parentID <= 0 {
- utils.ErrorLog("parentID <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.ParentId = parentID
-
- if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
- utils.ErrorLog("sub_name")
- code = enums.ErrorCodeParamWrong
- return
- }
- subName, _ := dataBody["sub_name"].(string)
- if len(subName) == 0 {
- utils.ErrorLog("len(sub_name) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.SubName = subName
- }
-
- if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
- utils.ErrorLog("initiate_mode")
- code = enums.ErrorCodeParamWrong
- return
- }
- initiateMode := int64(dataBody["initiate_mode"].(float64))
- if initiateMode != 1 && initiateMode != 2 {
- utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.InitiateMode = initiateMode
-
- if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
- utils.ErrorLog("doctor")
- code = enums.ErrorCodeParamWrong
- return
- }
- doctor := int64(dataBody["doctor"].(float64))
- if doctor <= 0 {
- utils.ErrorLog("doctor <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.Doctor = doctor
-
- if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
- blood_access_part_id, _ := dataBody["blood_access_part_id"].(string)
- solution.BloodAccessPartId = blood_access_part_id
- }
- return
- }
-
- func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
- patientBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &patientBody)
-
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
-
- if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
- formItem, _ := patientBody["formItem"].([]interface{})
-
- if len(formItem) > 0 {
- for _, item := range formItem {
- items := item.(map[string]interface{})
- project_name, _ := items["project_name"].(string)
- fmt.Println(project_name)
-
- range_type := int64(items["range_type"].(float64))
- fmt.Println(range_type)
-
- project_id := int64(items["project_id"].(float64))
- fmt.Println(project_id)
-
- item_id := int64(items["item_id"].(float64))
- fmt.Println(item_id)
-
- item, _ := items["item"].(string)
-
- fmt.Println(items["item"].(string))
-
- item_name, _ := items["item_name"].(string)
- fmt.Println(item_name)
-
- value, _ := items["value"].(string)
- fmt.Println(items["value"].(string))
-
- var form models.FormItem
- form.ProjectName = project_name
- form.RangeType = range_type
- form.ProjectId = project_id
- form.ItemId = item_id
- form.Item = item
- form.ItemName = item_name
- form.Value = value
- formItems = append(formItems, &form)
- }
- }
- }
- if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
- utils.ErrorLog("avatar")
- code = enums.ErrorCodeParamWrong
- return
- }
- avatar, _ := patientBody["avatar"].(string)
-
- if len(avatar) == 0 {
- utils.ErrorLog("len(avatar) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Avatar = avatar
-
- if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
- utils.ErrorLog("name")
- code = enums.ErrorCodeParamWrong
- return
- }
- name, _ := patientBody["name"].(string)
- if len(name) == 0 {
- utils.ErrorLog("len(name) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Name = name
-
- if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
- alias := patientBody["alias"].(string)
- patient.Alias = alias
- }
-
- if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
- nation := patientBody["nation"].(string)
- patient.Nation = nation
- }
- if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
- native_place := patientBody["native_place"].(string)
- patient.NativePlace = native_place
- }
-
- if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
- utils.ErrorLog("idCardNo")
- code = enums.ErrorCodeParamWrong
- return
- }
- idCardNo, _ := patientBody["idCardNo"].(string)
- if len(idCardNo) == 0 {
- utils.ErrorLog("len(idCardNo) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.IdCardNo = idCardNo
-
- patient.PatientType = 1
-
- if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
- utils.ErrorLog("dialysisNo")
- code = enums.ErrorCodeParamWrong
- return
- }
- dialysisNo, _ := patientBody["dialysisNo"].(string)
- if len(dialysisNo) == 0 {
- utils.ErrorLog("len(dialysisNo) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.DialysisNo = dialysisNo
- // }
-
- if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
- utils.ErrorLog("lapseto")
- code = enums.ErrorCodeParamWrong
- return
- }
- lapseto := int64(patientBody["lapseto"].(float64))
- if lapseto <= 0 {
- utils.ErrorLog("lapseto == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Lapseto = lapseto
-
- if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
- utils.ErrorLog("gender")
- code = enums.ErrorCodeParamWrong
- return
- }
- gender := int64(patientBody["gender"].(float64))
- if gender <= 0 {
- utils.ErrorLog("gender <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Gender = gender
-
- if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
- response_result := patientBody["response_result"].(string)
- patient.ResponseResult = response_result
- }
-
- if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
- utils.ErrorLog("age")
- code = enums.ErrorCodeParamWrong
- return
- }
- age := int64(patientBody["age"].(float64))
- patient.Age = age
-
- if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
- user_sys_before_count := patientBody["user_sys_before_count"].(string)
- count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
- patient.UserSysBeforeCount = count
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
- utils.ErrorLog("birth")
- code = enums.ErrorCodeParamWrong
- return
- }
- birth, _ := patientBody["birth"].(string)
- if len(birth) == 0 {
- utils.ErrorLog("len(birth) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
- if err != nil {
- utils.ErrorLog("birthTime")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Birthday = birthTime.Unix()
-
- if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
- height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
- patient.Height = height
- }
-
- if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
- maritalStatus := int64(patientBody["maritalStatus"].(float64))
- patient.MaritalStatus = maritalStatus
- }
-
- if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
- children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
- patient.Children = children
- }
-
- if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
- admissionNumber, _ := patientBody["admissionNumber"].(string)
- patient.AdmissionNumber = admissionNumber
- }
-
- if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
- reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
- patient.ReimbursementWayId = reimbursementWayID
- }
-
- if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
- healthCareNo := patientBody["healthCareNo"].(string)
- patient.HealthCareNo = healthCareNo
- }
-
- if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
- utils.ErrorLog("phone")
- code = enums.ErrorCodeParamWrong
- return
- }
- phone := patientBody["phone"].(string)
- if len(phone) == 0 {
- utils.ErrorLog("len(phone) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- if !utils.CheckMobile(phone) {
- utils.ErrorLog("!phone")
- code = enums.ErrorCodeMobileFormat
- return
- }
- patient.Phone = phone
-
- if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
- homeTelephone := patientBody["homeTelephone"].(string)
- patient.HomeTelephone = homeTelephone
- }
-
- if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
- relativePhone := patientBody["relative_phone"].(string)
- patient.RelativePhone = relativePhone
- }
-
- if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
- relativeRelations := patientBody["relative_relations"].(string)
- patient.RelativeRelations = relativeRelations
- }
-
- if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
- homeAddress := patientBody["homeAddress"].(string)
- patient.HomeAddress = homeAddress
- }
-
- if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
- work := patientBody["work"].(string)
- patient.WorkUnit = work
- }
-
- if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
- unitAddress := patientBody["unit_address"].(string)
- patient.UnitAddress = unitAddress
- }
-
- if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
- profession := int64(patientBody["profession"].(float64))
- patient.Profession = profession
- }
-
- if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
- education := int64(patientBody["education"].(float64))
- patient.EducationLevel = education
- }
-
- if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
- utils.ErrorLog("source")
- code = enums.ErrorCodeParamWrong
- return
- }
- source := int64(patientBody["source"].(float64))
- if source <= 0 {
- utils.ErrorLog("source <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Source = source
-
- zb_patient_id := patientBody["zb_patient_id"].(string)
- patient.ZbPatientId = zb_patient_id
-
- if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
- isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
- patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
- }
-
- if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
- firstDialysisDate := patientBody["firstDialysisDate"].(string)
- firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
- if err == nil {
- patient.FirstDialysisDate = firstDialysisDateTime.Unix()
- }
- }
-
- if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
- firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
- patient.FirstDialysisHospital = firstDialysisHospital
- }
-
- if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
- thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
- if len(thePredialysisCondition) > 0 {
- conditions := make([]string, 0)
- for _, item := range thePredialysisCondition {
- if reflect.TypeOf(item).String() != "string" {
- continue
- }
- condition := item.(string)
- if len(condition) > 0 {
- conditions = append(conditions, condition)
- }
- }
- patient.PredialysisCondition = strings.Join(conditions, ",")
- }
- }
-
- if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
- preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
- patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
- }
-
- if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
- preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
- patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
- }
- if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
- hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
- hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
- if err == nil {
- patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
- }
- }
-
- if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
- partition := int64(patientBody["partition"].(float64))
- patient.PartitionId = partition
- }
- if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
- bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
- patient.BedId = bed
- }
-
- if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
- healthCareDueDate := patientBody["healthCareDueDate"].(string)
- healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
- if err == nil {
- patient.HealthCareDueDate = healthCareDueDateTime.Unix()
- }
- }
-
- if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
- blood := int64(patientBody["blood"].(float64))
- patient.BloodType = blood
- }
-
- if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
- rh := int64(patientBody["rh"].(float64))
- patient.Rh = rh
- }
-
- if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
- healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
- healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
- if err == nil {
- patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
- }
- }
-
- if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
- receivingDate := patientBody["receivingDate"].(string)
- receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
- if err == nil {
- patient.ReceivingDate = receivingDateTime.Unix()
- }
- }
-
- if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
- induction := int64(patientBody["induction"].(float64))
- patient.InductionPeriod = induction
- }
-
- if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
- initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
- patient.InitialDialysis = initial
- }
-
- if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
- dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
- patient.TotalDialysis = dialysisTotal
- }
-
- if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
- thisContagions, _ := patientBody["contagions"].([]interface{})
- if len(thisContagions) > 0 {
- for _, item := range thisContagions {
- if reflect.TypeOf(item).String() != "float64" {
- continue
- }
- contagion := int64(item.(float64))
- if contagion > 0 {
- contagions = append(contagions, contagion)
- }
- }
- }
- }
-
- if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
- doctor := int64(patientBody["doctor"].(float64))
- patient.AttendingDoctorId = doctor
- }
-
- if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
- nurse := int64(patientBody["nurse"].(float64))
- patient.HeadNurseId = nurse
- }
-
- if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
- assessment := patientBody["assessment"].(string)
- patient.Evaluate = assessment
- }
-
- if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
- thisDiseases, _ := patientBody["diseases"].([]interface{})
- if len(thisDiseases) > 0 {
- for _, item := range thisDiseases {
- if reflect.TypeOf(item).String() != "float64" {
- continue
- }
- disease := int64(item.(float64))
- if disease > 0 {
- diseases = append(diseases, disease)
- }
- }
- }
- }
-
- if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
- diagnose := patientBody["diagnose"].(string)
- patient.Diagnose = diagnose
- }
-
- if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
- remark := patientBody["remark"].(string)
- patient.Remark = remark
- }
-
- if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
- sch_remark := patientBody["sch_remark"].(string)
- patient.SchRemark = sch_remark
- }
-
- if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
- patient_complains := patientBody["patient_complains"].(string)
- patient.PatientComplains = patient_complains
- }
-
- if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
- present_history := patientBody["present_history"].(string)
- patient.PresentHistory = present_history
- }
-
- if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
- past_history := patientBody["past_history"].(string)
- patient.PastHistory = past_history
- }
-
- if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
- temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
- patient.Temperature = temperature
- }
-
- if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
- pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
- patient.Pulse = pulse
- }
-
- if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
- respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
- patient.Respiratory = respiratory
- }
-
- if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
- sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
- patient.SBP = sbp
- }
-
- if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
- dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
- patient.DBP = dbp
- }
-
- if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
- dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
- patient.DialysisAge = dialysis_age
- }
- fmt.Println(patient.DialysisAge)
- if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
- first_treatment_date := patientBody["first_treatment_date"].(string)
- first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
- if err == nil {
- patient.FirstTreatmentDate = first_treatment_time.Unix()
- }
- }
- if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
- expense_kind := int64(patientBody["expense_kind"].(float64))
- patient.ExpenseKind = expense_kind
- }
- fmt.Println(patient.ExpenseKind)
- if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
- tell_phone := patientBody["tell_phone"].(string)
- patient.TellPhone = tell_phone
- }
- if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
- contact_name := patientBody["contact_name"].(string)
- patient.ContactName = contact_name
- }
- if patientBody["troble_shoot"] != nil && reflect.TypeOf(patientBody["troble_shoot"]).String() == "float64" {
- troble_shoot := int64(patientBody["troble_shoot"].(float64))
- patient.TrobleShoot = troble_shoot
- }
-
- if patientBody["treatment_plan"] != nil && reflect.TypeOf(patientBody["treatment_plan"]).String() == "string" {
- treatment_plan := patientBody["treatment_plan"].(string)
- patient.TreatmentPlan = treatment_plan
- }
-
- if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
- doctor := int64(patientBody["doctor"].(float64))
- patient.Doctor = doctor
- }
-
- if patientBody["record_number"] != nil && reflect.TypeOf(patientBody["record_number"]).String() == "string" {
- record_number := patientBody["record_number"].(string)
- patient.RecordNumber = record_number
- }
-
- patient_source := int64(patientBody["patient_source"].(float64))
- if patient_source <= 0 {
- utils.ErrorLog("patient_source <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.PatientSource = patient_source
-
- if patientBody["patient_start_time"] != nil && reflect.TypeOf(patientBody["patient_start_time"]).String() == "string" {
- patient_start_time := patientBody["patient_start_time"].(string)
- var startTime int64
- if len(patient_start_time) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_start_time+" 00:00:00", loc)
-
- startTime = theTime.Unix()
- }
- patient.PatientStartTime = startTime
- }
-
- if patientBody["patient_end_time"] != nil && reflect.TypeOf(patientBody["patient_end_time"]).String() == "string" {
- patient_end_time := patientBody["patient_end_time"].(string)
- var endTime int64
- if len(patient_end_time) > 0 {
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_end_time+" 00:00:00", loc)
-
- endTime = theTime.Unix()
- }
- patient.PatientEndTime = endTime
- }
-
- if patientBody["infectious_remark"] != nil && reflect.TypeOf(patientBody["infectious_remark"]).String() == "string" {
- record_number := patientBody["infectious_remark"].(string)
- patient.InfectiousRemark = record_number
- }
-
- if patientBody["allergic_history"] != nil && reflect.TypeOf(patientBody["allergic_history"]).String() == "string" {
- allergic_history := patientBody["allergic_history"].(string)
- patient.AllergicHistory = allergic_history
- }
-
- if patientBody["patient_address"] != nil && reflect.TypeOf(patientBody["patient_address"]).String() == "string" {
- patient_address := patientBody["patient_address"].(string)
- patient.PatientAddress = patient_address
- }
-
- if patientBody["print_date"] != nil && reflect.TypeOf(patientBody["print_date"]).String() == "string" {
- print_date := patientBody["print_date"].(string)
- printDateTime, err := time.ParseInLocation(timeLayout, print_date, loc)
- if err == nil {
- patient.PrintDate = printDateTime.Unix()
- }
- }
-
- return
-
- }
-
- func (c *PatientApiController) GetPatientsByKeyWord() {
- keyWord := c.GetString("keyword")
- adminUserInfo := c.GetAdminUserInfo()
- patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- })
- }
-
- func (c *PatientApiController) QueryPatientById() {
- id, _ := c.GetInt64("id")
- fmt.Println(id)
- patientInfo := service.QueryPatientById(id)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patientInfo,
- })
- return
- }
-
- func (c *PatientApiController) GetRemindPatientList() {
- page, _ := c.GetInt64("page", 1)
- limit, _ := c.GetInt64("limit", 10)
- adminUserInfo := c.GetAdminUserInfo()
- total, patients, _ := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
- _, errcode := service.GetOrgFollowIsExist(c.GetAdminUserInfo().CurrentOrgId)
- if errcode == gorm.ErrRecordNotFound {
- information, err := service.GetAdminUserRoleInformation(0)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "patients": patients,
- "information": information,
- })
- } else if errcode == nil {
- information, err := service.GetAdminUserRoleInformation(c.GetAdminUserInfo().CurrentOrgId)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "patients": patients,
- "information": information,
- })
- }
- }
-
- func (c *PatientApiController) PostIsOpenRemind() {
- patient_id, _ := c.GetInt64("id", 1)
- is_open_remind, _ := c.GetInt64("is_open_remind", 1)
- adminUserInfo := c.GetAdminUserInfo()
-
- err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "成功",
- "is_open_remind": is_open_remind,
- })
- } else if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- }
- }
-
- func (c *PatientApiController) GetPatientScheduleOne() {
- id, _ := c.GetInt64("id")
- //查询该病人是否当天是排班
- nowDateTime := time.Now()
- nowDate := nowDateTime.Format("2006-01-02")
- nowDate += " 00:00:00"
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
- nowdate := theTime.Unix()
- fmt.Println("nowdate", nowdate)
- adminUser := c.GetAdminUserInfo()
- orgId := adminUser.CurrentOrgId
- fmt.Println("orgid", orgId)
- scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "scheduls": scheduls,
- })
- }
-
- func (c *PatientApiController) ExportPatients() {
- dataBody := make(map[string]interface{}, 0)
-
- all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
-
- //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
-
- org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
-
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- return
- }
- utils.ErrorLog("%v", dataBody)
- export_time := time.Now().Unix()
- var patients []*models.Patients
- var total_patients []interface{}
- if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
- tempPatients := dataBody["patients"].([]interface{})
- total_patients = tempPatients
- for index, patientMap := range tempPatients {
- patientNameM := patientMap.(map[string]interface{})
- var patient models.Patients
-
- if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
- utils.ErrorLog("name")
- return
- }
- name, _ := patientNameM["name"].(string)
- if len(name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- patient.Name = name
-
- if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
- gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
- if gender == 0 { //性别不符合要求则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else {
- patient.Gender = gender
- }
- }
-
- if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
- phone, _ := patientNameM["phone"].(string)
- if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
- if len(phone) == 0 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- } else {
- //var tempPatient *models.Patients
- //for _, item := range all_patient {
- // if item.Phone == phone {
- // tempPatient = item
- // }
- //}
-
- //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
- count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
- if count >= 1 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- patient.Phone = phone
- }
- }
-
- if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
- id_card_no, _ := patientNameM["id_card_no"].(string)
-
- if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
-
- if len(id_card_no) == 0 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码格式不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- }
-
- } else {
- //var tempPatient *models.Patients
- //for _, item := range all_patient {
- // if item.IdCardNo == id_card_no {
- // tempPatient = item
- // }
- //}
- count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
- if count >= 1 {
- //if tempPatient != nil && tempPatient.ID > 0 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- //}
- patient.IdCardNo = id_card_no
- //patient.Birthday = GetBirthDay(id_card_no).Unix()
- if GetBirthDay(id_card_no) == nil {
- patient.Birthday = 0
- } else {
- patient.Birthday = GetBirthDay(id_card_no).Unix()
-
- }
- }
- }
-
- fmt.Println("111112222")
- if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
- first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
- timeLayout := "2006/01/02"
- loc, _ := time.LoadLocation("Local")
- first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
-
- if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
- if len(first_treatment_date) == 0 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- }
-
- } else {
- if len(first_treatment_date) == 0 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else {
-
- if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else {
- patient.FirstDialysisDate = first_dialysis_date.Unix()
- }
-
- }
-
- }
- }
-
- if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
- source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
- if source == 0 { //患者来源不符合要求则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else if source == 3 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else {
- patient.Source = source
- }
- }
-
- if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
- lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
- if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else if lapseto == 3 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else {
- patient.Lapseto = lapseto
- }
- }
-
- if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
- is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
- if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else if is_infectious == 3 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else {
- patient.IsInfectious = is_infectious
- }
- }
-
- if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
- var contagions []int64
- thisContagions, _ := patientNameM["contagions"].([]interface{})
- if len(thisContagions) > 0 {
- for _, item := range thisContagions {
- if reflect.TypeOf(item).String() != "float64" {
- continue
- }
- contagion := int64(item.(float64))
- if contagion > 0 {
- contagions = append(contagions, contagion)
- }
- }
- }
- patient.ContagionIds = contagions
- }
-
- if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
- diagnose, _ := patientNameM["diagnose"].(string)
- patient.Diagnose = diagnose
-
- }
-
- if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
- dialysis_no, _ := patientNameM["dialysis_no"].(string)
- var tempPatient *models.Patients
- for _, item := range all_patient {
- if item.DialysisNo == dialysis_no {
- tempPatient = item
- }
- }
- if tempPatient != nil && tempPatient.ID > 0 {
- patient.DialysisNo = GenerateDialysisNoTwo(patients)
- } else {
- patient.DialysisNo = dialysis_no
- }
- }
-
- if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
- height, _ := patientNameM["height"].(string)
- heights, _ := strconv.ParseFloat(height, 64)
- patient.Height = int64(heights)
- }
-
- if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
- home_address, _ := patientNameM["home_address"].(string)
- patient.HomeAddress = home_address
- }
- if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
- dry_weight, _ := patientNameM["dry_weight"].(string)
- dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
- patient.DryWeight = dry_weights
-
- }
- patient.CreatedTime = time.Now().Unix()
- patient.UpdatedTime = time.Now().Unix()
- patient.Status = 1
- patient.Avatar = "https://images.shengws.com/201809182128111.png"
- patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
- patient.IsExcelExport = 1
- patient.PatientType = 1
- patients = append(patients, &patient)
- }
- }
- errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
-
- if len(patients) > 0 {
- for _, item := range patients {
-
- hans := item.Name // 要转换的汉字字符串
- // 创建一个拼音转换器
- p := pinyin.NewArgs()
-
- // 将汉字转为拼音
- pinyinSlice := pinyin.Pinyin(hans, p)
-
- // 输出拼音
- fmt.Println("Pinyin:", pinyinSlice)
-
- // 获取首字母
- firstLetter := ""
- for _, py := range pinyinSlice {
- if len(py) > 0 {
- firstLetter += string(py[0][0])
- }
- }
-
- item.FirstLetter = firstLetter
- service.CreateExportPatient(item, item.ContagionIds, org.Creator)
- }
-
- log := models.ExportLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_patients)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(patients)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_patients),
- "success_num": len(patients),
- "fail_num": int64(len(errLogs)),
- })
- } else {
- log := models.ExportLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_patients)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(patients)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_patients),
- "success_num": len(patients),
- "fail_num": int64(len(errLogs)),
- })
- }
- }
-
- func GetBirthDay(IDCardNo string) *time.Time {
- dayStr := IDCardNo[6:14]
- birthDay, err := time.Parse("20060102", dayStr)
- if err != nil {
- fmt.Println(err)
- return nil
- }
- return &birthDay
- }
-
- func IsIdCard(id string) (res bool) {
- id = strings.ToUpper(id)
- if len(id) != 15 && len(id) != 18 {
- fmt.Println("1111111")
- return false
- }
- r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
- if !r.MatchString(id) {
- fmt.Println("222222")
-
- return false
- }
- if len(id) == 15 {
- tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
- if tm2.Unix() == 0 {
- fmt.Println("44444443333")
-
- return false
- }
- return true
- } else {
- tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
- fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
- fmt.Println(tm2.Unix())
-
- if tm2.Unix() == 0 {
-
- fmt.Println("44445555555")
-
- return false
- }
- //检验18位身份证的校验码是否正确。
- //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
- arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
- arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
- sign := 0
- for k, v := range arr_int {
- int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
- sign += int_temp * v
- }
- n := sign % 11
- val_num := arr_ch[n]
- if val_num != string([]byte(id)[17:18]) {
- fmt.Println("5556666666")
-
- return false
- }
- return true
- }
- }
-
- func (c *PatientApiController) SaveEditAdvices() {
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
- startTime := c.GetString("start_time")
-
- theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
-
- groupno, _ := c.GetInt64("groupno")
- fmt.Println("组", groupno)
- date, _ := c.GetInt64("date")
- fmt.Println("date", date)
- patient_id, _ := c.GetInt64("patient_id")
- fmt.Println("paitent_id", patient_id)
- advice := models.XtDoctorAdvice{
- StartTime: theTime.Unix(),
- }
- err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
- key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(date, 10) + ":doctor_advices"
- redis := service.RedisClient()
-
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(date, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
-
- scheduleTime := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + scheduleTime + "_" + strconv.FormatInt(orgid, 10)
- fmt.Println("keyFour323223323232323232", keyFour)
- redis.Set(keyFour, "", time.Second)
-
- defer redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "advice": advice,
- })
- }
-
- func (c *PatientApiController) GetMaxDialysisNo() {
- dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "dialysis_no": dialysisNo,
- })
-
- }
-
- func GenerateDialysisNoTwo(patients []*models.Patients) string {
- dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
- var tempPatient *models.Patients
- for _, item := range patients {
- if item.DialysisNo == dialysisNo2 {
- tempPatient = item
- }
- }
- if tempPatient == nil || tempPatient.ID == 0 {
- return dialysisNo2
- }
- return GenerateDialysisNoTwo(patients)
- }
-
- func (c *PatientApiController) GetBanner() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- _, errcodes := service.GetOrgFollowIsExist(orgId)
-
- if errcodes == gorm.ErrRecordNotFound {
- information, err := service.GetAdminUserRoleInformation(0)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "information": information,
- })
- } else if errcodes == nil {
- information, err := service.GetAdminUserRoleInformation(orgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "information": information,
- })
- }
- }
-
- func (c *PatientApiController) GetPatientDialysisLongSolution() {
-
- patient_id, _ := c.GetInt64("id", 0)
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- if patient_id <= 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "solutions": nil,
- })
- return
- }
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- //获取该患者分组的透析模式
- list, _ := service.GetPatientSolutionGroupList(patient_id, adminUserInfo.CurrentOrgId)
-
- for _, item := range list {
- //获取该模式最新的1条数据
- solution, _ := service.GetNewPatientSolutionByModeId(patient_id, item.ModeId, adminUserInfo.CurrentOrgId)
- //更新状态值
- service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, adminUserInfo.CurrentOrgId, patient_id)
- }
-
- solution, total, err := service.GetPatientDialysisLongSolution(patient_id, page, limit, adminUserInfo.CurrentOrgId)
- stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "solutions": solution,
- "total": total,
- "stockType": stockType,
- })
- }
-
- func (c *PatientApiController) GetDialysisSolutionDetailList() {
-
- patient_id, _ := c.GetInt64("patient_id")
- mode_id, _ := c.GetInt64("mode_id")
- page, _ := c.GetInt64("page")
- limit, _ := c.GetInt64("limit")
- orgId := c.GetAdminUserInfo().CurrentOrgId
- list, total, err := service.GetDialysisSolutionDetailList(orgId, patient_id, mode_id, page, limit)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "total": total,
- })
- }
-
- func (c *PatientApiController) SaveFallOutBedPrint() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- outPrint := models.XtFallOutPrint{
- UserOrgId: orgid,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- //查询该机构是否存在
- list, err := service.GetOutPrintList(orgid)
-
- if list.ID == 0 {
- service.CreateFallOutBedPrint(outPrint)
- }
-
- if list.ID > 0 {
- service.UpdateFallOutBedPrint(list.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (c *PatientApiController) GetFallOutBedPrintList() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
-
- list, _ := service.GetFallOutBedPrintList(orgid)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (c *PatientApiController) SaveFilterInformed() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
- informed := models.XtFilterInformed{
- UserOrgId: orgid,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- filterInformed, _ := service.GetFilterInformed(orgid)
-
- if filterInformed.ID == 0 {
-
- service.CreateFilterInformed(informed)
- }
-
- if filterInformed.ID > 0 {
-
- service.UpdateFilterInformed(filterInformed.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "informed": informed,
- })
-
- }
-
- func (c *PatientApiController) GetFilterInformed() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
- filterInformed, _ := service.GetFilterInformed(orgid)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": filterInformed,
- })
- }
-
- func (c *PatientApiController) SaveProfundaInformed() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- informed := models.XtProfundaInformed{
- UserOrgId: orgid,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- profundaInformed, _ := service.GetProfundaInformed(orgid)
-
- if profundaInformed.ID == 0 {
- service.CreateProfundaInformed(informed)
- }
-
- if profundaInformed.ID > 0 {
-
- service.UpdateProfundaInformed(profundaInformed.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": profundaInformed,
- })
- }
-
- func (c *PatientApiController) GetProfundaInformed() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
-
- profundaInformed, _ := service.GetProfundaInformed(orgid)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": profundaInformed,
- })
- }
-
- func (c *PatientApiController) SaveArterOvenous() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- arterOvenous := models.XtArterOvenous{
- UserOrgId: orgid,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- list, _ := service.GetArterOvenousList(orgid)
-
- if list.ID == 0 {
-
- service.CreateArterOvernous(arterOvenous)
- }
-
- if list.ID > 0 {
- service.UpdateArterOvernous(list.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (c *PatientApiController) GetArterOverNous() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
-
- list, _ := service.GetArterOvenousList(orgid)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
-
- }
-
- func (c *PatientApiController) SaveHighRikInformed() {
-
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- risk := models.XtHightRisk{
- UserOrgId: orgid,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- highRik, _ := service.GetHightRikInformed(orgid)
-
- if highRik.ID == 0 {
-
- service.CreateHighRik(risk)
- }
-
- if highRik.ID > 0 {
-
- service.UpdateHighRik(highRik.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": risk,
- })
- }
-
- func (c *PatientApiController) GetHighRiskInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- rikInformed, _ := service.GetHightRikInformed(orgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": rikInformed,
- })
- }
-
- func (c *PatientApiController) SaveAnticoagulation() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- auticoagutionPrint := models.XtAuticoagutionPrint{
- Content: content,
- UserOrgId: orgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- anticoagulation, _ := service.GetAnticoagulation(orgId)
-
- if anticoagulation.ID == 0 {
-
- service.CreateAnticoagulation(auticoagutionPrint)
- }
-
- if anticoagulation.ID > 0 {
-
- service.UpdateAnticoagulation(anticoagulation.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": auticoagutionPrint,
- })
-
- }
-
- func (c *PatientApiController) GetAnticoagulationInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- anticoagulation, _ := service.GetAnticoagulation(orgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": anticoagulation,
- })
- }
-
- func (c *PatientApiController) SaveCriticalInfomed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- criticalinfomedPrint := models.XtCriticalinfomedPrint{
- UserOrgId: orgId,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- infomed, _ := service.GetCriticalInfomed(orgId)
-
- if infomed.ID == 0 {
- service.CreatedCriticalInfomed(criticalinfomedPrint)
- }
-
- if infomed.ID > 0 {
- service.UpdateCriticalInfomed(infomed.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": criticalinfomedPrint,
- })
- }
-
- func (c *PatientApiController) GetCriticalInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- infomed, _ := service.GetCriticalInfomed(orgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": infomed,
- })
- }
-
- func (c *PatientApiController) SaveHemoperfusionInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- hemoperfusionmedPrint := models.XtHemoperfusionmedPrint{
- UserOrgId: orgId,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- informed, _ := service.GetHemoperfusionInformed(orgId)
-
- if informed.ID == 0 {
-
- service.CreateHemoperfusionInformed(hemoperfusionmedPrint)
- }
-
- if informed.ID > 0 {
-
- service.UpdateHemoperfusionInformed(informed.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": hemoperfusionmedPrint,
- })
- }
-
- func (c *PatientApiController) GetHemoperfusionInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- informed, _ := service.GetHemoperfusionInformed(orgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": informed,
- })
- }
-
- func (c *PatientApiController) SaveBringInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- bringinformedPrint := models.XtBringinformedPrint{
- Content: content,
- UserOrgId: orgId,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- }
-
- informed, _ := service.GetBringInformed(orgId)
-
- if informed.ID == 0 {
- service.CreateBringInformed(bringinformedPrint)
- }
- if informed.ID > 0 {
- service.UpdateBringInformed(informed.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": bringinformedPrint,
- })
- }
-
- func (c *PatientApiController) GetInformedContsent() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- informed, _ := service.GetBringInformed(orgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": informed,
- })
- }
-
- func (c *PatientApiController) SaveCatheterization() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- cathetercationPrint := models.XtCathetercationPrint{
- UserOrgId: orgId,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- catheterization, _ := service.GetCatheterization(orgId)
-
- if cathetercationPrint.ID == 0 {
-
- service.CreateCatheteriztion(cathetercationPrint)
- }
-
- if cathetercationPrint.ID > 0 {
-
- service.UpdateCatheterization(catheterization.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": catheterization,
- })
- }
-
- func (c *PatientApiController) GetCatheterization() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- catheterization, _ := service.GetCatheterization(orgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": catheterization,
- })
- }
-
- func (c *PatientApiController) SaveDialyzerInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- dialyszerinformedPrint := models.XtDialyszerinformedPrint{
- UserOrgId: orgId,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- informed, _ := service.GetDialyzerInformed(orgId)
-
- if informed.ID == 0 {
-
- service.CreateDialyzerInformed(dialyszerinformedPrint)
- }
-
- if informed.ID > 0 {
- service.UpdateDialyszerInformed(informed.ID, content)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": dialyszerinformedPrint,
- })
- }
-
- func (c *PatientApiController) GetDialyzerInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- informed, _ := service.GetDialyzerInformed(orgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": informed,
- })
- }
-
- func (c *PatientApiController) SaveTheapyInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- theapyinformedPrint := models.XtTheapyinformedPrint{
- Content: content,
- UserOrgId: orgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- theapyInformed, _ := service.GetTheapyInformed(orgId)
-
- if theapyInformed.ID == 0 {
-
- service.CreateTheapyInformed(theapyinformedPrint)
- }
-
- if theapyInformed.ID > 0 {
-
- service.UpdateTheaphInformed(theapyInformed.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": theapyinformedPrint,
- })
-
- }
-
- func (c *PatientApiController) GetTherapyInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- theapyInformed, _ := service.GetTheapyInformed(orgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": theapyInformed,
- })
- }
-
- func (c *PatientApiController) SaveMedicalHistory() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
- patient_id := int64(dataBody["patient_id"].(float64))
- medicalHistory := models.XtMedicalHistory{
- UserOrgId: orgId,
- PatientId: patient_id,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Status: 1,
- Content: content,
- }
-
- //
- history, _ := service.GetPatientMedicalHistory(patient_id, orgId)
-
- if history.ID > 0 {
- service.UpdatePatientMedicalHistory(history.ID, content)
- }
- if history.ID == 0 {
- service.CreatePatientMedicalHistory(medicalHistory)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "medicalHistory": medicalHistory,
- })
-
- }
-
- func (c *PatientApiController) SavePatientCritaicalInformed() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- patientCritical := models.XtPatientCritical{
- UserOrgId: orgId,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- patientCritaicalInformed, _ := service.GetPatientCritaicalInformed(orgId)
-
- if patientCritaicalInformed.ID == 0 {
- service.CreatePatientCritaicalinformed(patientCritical)
- }
- if patientCritaicalInformed.ID > 0 {
- service.UpdatePatientCritaicalInformed(patientCritaicalInformed.ID, content)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "patientCritical": patientCritical,
- })
- }
-
- func (c *PatientApiController) GetPatientCriticalList() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- patientCritaicalInformed, _ := service.GetPatientCritaicalInformed(orgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "patientCritaicalInformed": patientCritaicalInformed,
- })
- }
-
- func (c *PatientApiController) SavePatientCriticalInformedOne() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- criticalOne := models.XtPatientCriticalOne{
- UserOrgId: orgId,
- Content: content,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- critical, _ := service.GetPatientCriticalByUserOrgId(orgId)
-
- if critical.ID == 0 {
- service.CreatePatientCritical(criticalOne)
- }
-
- if critical.ID > 0 {
- service.UpdatePatientCriticalOne(orgId, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "criticalOne": criticalOne,
- })
-
- }
-
- func (c *PatientApiController) GetPatientCriticalOneList() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- list, _ := service.GetPatientCriticalOneList(orgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (c *PatientApiController) DeleteSolution() {
-
- id, _ := c.GetInt64("id")
- solution, _ := service.DeleteSolutionById(id)
- c.ServeSuccessJSON(map[string]interface{}{
- "solution": solution,
- })
- }
-
- func (c *PatientApiController) SaveTreatmentPlan() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- content := dataBody["content"].(string)
-
- theapyinformedPrint := models.XtTreatmentPlan{
- Content: content,
- UserOrgId: orgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- treamentPlan, _ := service.GetTreamentPland(orgId)
-
- if treamentPlan.ID == 0 {
-
- service.CreateTreatqmentPland(theapyinformedPrint)
- }
-
- if treamentPlan.ID > 0 {
-
- service.UpdateTheatmentPland(treamentPlan.ID, content)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": theapyinformedPrint,
- })
- }
-
- func (c *PatientApiController) GetTreatMentPlanList() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- treamentPlan, _ := service.GetTreamentPland(orgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "treamentPlan": treamentPlan,
- })
- }
-
- func (c *PatientApiController) GetPatientByPatientId() {
-
- orgId := c.GetAdminUserInfo().CurrentOrgId
-
- id, _ := c.GetInt64("id")
-
- patients, _ := service.GetPatientByIDOne(orgId, id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": patients,
- })
- }
-
- func (c *PatientApiController) SavePatientLapse() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
-
- patient_id := int64(dataBody["patient_id"].(float64))
-
- admin_user_id := int64(dataBody["admin_user_id"].(float64))
-
- lapse_class := int64(dataBody["lapse_class"].(float64))
-
- lapse_type := int64(dataBody["lapse_type"].(float64))
-
- lapse_reason := dataBody["lapse_reason"].(string)
-
- record_date := dataBody["record_date"].(string)
-
- lapse_type_name := dataBody["lapse_type_name"].(string)
-
- his_bed := dataBody["his_bed"].(string)
-
- his_zone := dataBody["his_zone"].(string)
-
- his_type := int64(dataBody["his_type"].(float64))
-
- patient_address := dataBody["patient_address"].(string)
-
- start_time := dataBody["start_time"].(string)
-
- end_time := dataBody["end_time"].(string)
-
- start_time_one := dataBody["start_time_one"].(string)
-
- end_time_one := dataBody["end_time_one"].(string)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var recordDate int64
- if len(record_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDate = theTime.Unix()
- }
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- var startTimeOne int64
- if len(start_time_one) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_one+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTimeOne = theTime.Unix()
- }
-
- var endTimeOne int64
- if len(end_time_one) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_one+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTimeOne = theTime.Unix()
- }
-
- remark := dataBody["remark"].(string)
-
- org_id := c.GetAdminUserInfo().CurrentOrgId
-
- record := models.XtPatientLaspseRecord{
- PatientId: patient_id,
- RecordDate: recordDate,
- LapseDate: recordDate,
- LapseType: lapse_type,
- LapseClass: lapse_class,
- LapseReason: lapse_reason,
- AdminUserId: admin_user_id,
- Remark: remark,
- UserOrgId: org_id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- LapseTypeName: lapse_type_name,
- HisBed: his_bed,
- HisType: his_type,
- HisZone: his_zone,
- StartTime: startTime,
- EndTime: endTime,
- StartTimeOne: startTimeOne,
- EndTimeOne: endTimeOne,
- PatientAddress: patient_address,
- }
-
- //病人转出
- if lapse_type == 2 {
-
- service.UpdatePatientLapsetoByPatientId(patient_id, recordDate, lapse_reason)
-
- service.UpdateScheduleByDeathTime(patient_id, recordDate)
-
- service.UpdateScheduleItemByPatientId(patient_id)
- }
-
- //病人转出
- if lapse_type == 3 {
-
- service.UpdatePatientLapsetoByPatientIdOne(patient_id, recordDate, lapse_reason)
-
- service.UpdateScheduleByDeathTime(patient_id, recordDate)
-
- service.UpdateScheduleItemByPatientId(patient_id)
- }
-
- if lapse_type == 11 {
-
- service.UpdatePatientLasetoType(patient_id, lapse_type)
- }
-
- //病人转出
- if lapse_type == 1 {
-
- service.UpdatePatientLapsetoByPatientIdTwo(patient_id, recordDate)
-
- }
-
- service.CreatePatientRecord(record)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "record": record,
- })
-
- }
-
- func (c *PatientApiController) GetPatientLapsorecord() {
-
- id, _ := c.GetInt64("id")
-
- lapsorecord, _ := service.GetPatientLapsorecord(id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "lapsorecord": lapsorecord,
- })
- }
-
- func (this *DialysisApiController) GetPatientLapseRecord() {
-
- patient_id, _ := this.GetInt64("patient_id")
-
- limit, _ := this.GetInt64("limit")
-
- page, _ := this.GetInt64("page")
-
- orgId := this.GetAdminUserInfo().CurrentOrgId
-
- record, total, _ := service.GetPatientLapseRecord(patient_id, limit, page, orgId)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "record": record,
- "total": total,
- })
- }
-
- func (c *DialysisApiController) UpdatePatientLapseRecord() {
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
-
- patient_id := int64(dataBody["patient_id"].(float64))
-
- admin_user_id := int64(dataBody["admin_user_id"].(float64))
-
- lapse_class := int64(dataBody["lapse_class"].(float64))
-
- lapse_type := int64(dataBody["lapse_type"].(float64))
-
- lapse_reason := dataBody["lapse_reason"].(string)
-
- record_date := dataBody["record_date"].(string)
-
- lapse_type_name := dataBody["lapse_type_name"].(string)
-
- his_bed := dataBody["his_bed"].(string)
-
- his_zone := dataBody["his_zone"].(string)
-
- his_type := int64(dataBody["his_type"].(float64))
-
- patient_address := dataBody["patient_address"].(string)
-
- start_time := dataBody["start_time"].(string)
-
- end_time := dataBody["end_time"].(string)
-
- start_time_one := dataBody["start_time_one"].(string)
-
- end_time_one := dataBody["end_time_one"].(string)
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var recordDate int64
- if len(record_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDate = theTime.Unix()
- }
-
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
-
- var endTime int64
- if len(end_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- var startTimeOne int64
- if len(start_time_one) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_one+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTimeOne = theTime.Unix()
- }
-
- var endTimeOne int64
- if len(end_time_one) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_one+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTimeOne = theTime.Unix()
- }
-
- remark := dataBody["remark"].(string)
-
- id := int64(dataBody["id"].(float64))
-
- org_id := c.GetAdminUserInfo().CurrentOrgId
-
- record := models.XtPatientLaspseRecord{
- ID: id,
- PatientId: patient_id,
- RecordDate: recordDate,
- LapseDate: recordDate,
- LapseType: lapse_type,
- LapseClass: lapse_class,
- LapseReason: lapse_reason,
- AdminUserId: admin_user_id,
- Remark: remark,
- UserOrgId: org_id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- LapseTypeName: lapse_type_name,
- HisZone: his_zone,
- HisBed: his_bed,
- HisType: his_type,
- StartTime: startTime,
- StartTimeOne: startTimeOne,
- EndTime: endTime,
- EndTimeOne: endTimeOne,
- PatientAddress: patient_address,
- }
-
- //病人转出
- if lapse_type == 2 {
- service.UpdatePatientLapsetoByPatientId(patient_id, recordDate, lapse_reason)
-
- service.UpdateScheduleByDeathTime(patient_id, recordDate)
-
- service.UpdateScheduleItemByPatientId(patient_id)
- }
-
- if lapse_type == 3 {
- service.UpdatePatientLapsetoByPatientIdOne(patient_id, recordDate, lapse_reason)
-
- service.UpdateScheduleByDeathTime(patient_id, recordDate)
-
- service.UpdateScheduleItemByPatientId(patient_id)
- }
-
- //病人转出
- if lapse_type == 1 {
-
- service.UpdatePatientLapsetoByPatientIdTwo(patient_id, recordDate)
-
- }
-
- if lapse_type == 11 {
- service.UpdatePatientLasetoType(patient_id, lapse_type)
- }
-
- service.SavePatientLapseRecord(record)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "record": record,
- })
- }
-
- func (c *DialysisApiController) DeletePatientLapseRecord() {
-
- id, _ := c.GetInt64("id")
-
- service.DeletePatientLapseRecord(id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
-
- }
-
- func (c *DialysisApiController) GetPatientLapseList() {
-
- fmt.Println("除非哈哈哈哈哈")
-
- list, _ := service.GetAllpatientFivty()
-
- if len(list) > 0 {
-
- for _, item := range list {
-
- patientLaspseRecord := models.XtPatientLaspseRecord{
- PatientId: item.ID,
- RecordDate: 0,
- LapseDate: item.CreatedTime,
- LapseType: 1,
- LapseClass: 0,
- LapseReason: "",
- AdminUserId: item.RegistrarsId,
- Remark: "",
- UserOrgId: item.UserOrgId,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- LapseTypeName: "",
- HisType: 0,
- HisZone: "",
- HisBed: "",
- PatientAddress: "",
- StartTime: 0,
- EndTime: 0,
- StartTimeOne: 0,
- EndTimeOne: 0,
- }
-
- service.CreatePatientRecord(patientLaspseRecord)
- }
- }
-
- //list, _ := service.GetPatientLapsorecordListOne()
- //
- //if len(list) > 0 {
- // for _, item := range list {
- // //查询患者的信息
- // patients, _ := service.GetPatientByIDTwoOne(item.PatientId)
- //
- // if patients.Lapseto == 2 || patients.Lapseto == 3 {
- //
- // patientLaspseRecord := models.XtPatientLaspseRecord{
- // PatientId: item.PatientId,
- // RecordDate: patients.DeathTime,
- // LapseDate: patients.DeathTime,
- // LapseType: patients.Lapseto,
- // LapseClass: patients.Lapseto,
- // LapseReason: patients.OutReason,
- // AdminUserId: 0,
- // Remark: "",
- // UserOrgId: patients.UserOrgId,
- // Ctime: time.Now().Unix(),
- // Mtime: time.Now().Unix(),
- // Status: 1,
- // LapseTypeName: "",
- // HisType: 0,
- // HisZone: "",
- // HisBed: "",
- // PatientAddress: "",
- // StartTime: patients.PatientStartTime,
- // EndTime: patients.PatientEndTime,
- // StartTimeOne: patients.PatientStartTime,
- // EndTimeOne: patients.PatientEndTime,
- // }
- //
- // service.CreatePatientRecord(patientLaspseRecord)
- // }
- // }
- //}
- //fmt.Println("lsit", list)
-
- //for _, item := range list {
- //
- //
- //}
- }
|