patient_api_controller.go 265KB

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