patient_api_controller.go 264KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994
  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. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1909. }
  1910. }
  1911. if pharmacyConfig.IsOpen != 1 {
  1912. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1913. if drugOutInfo.ID == 0 {
  1914. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1915. }
  1916. }
  1917. //查询默认仓库
  1918. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  1919. //查询默认仓库剩余多少库存
  1920. var sum_count int64
  1921. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1922. for _, its := range stockInfo {
  1923. if its.MaxUnit == medical.MaxUnit {
  1924. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1925. }
  1926. sum_count += its.StockMaxNumber + its.StockMinNumber
  1927. }
  1928. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1929. break
  1930. c.ServeSuccessJSON(map[string]interface{}{
  1931. "msg": "1",
  1932. "advice": advice,
  1933. })
  1934. return
  1935. }
  1936. if medical.IsUse == 1 {
  1937. c.ServeSuccessJSON(map[string]interface{}{
  1938. "msg": "1",
  1939. "advice": advice,
  1940. })
  1941. return
  1942. }
  1943. }
  1944. }
  1945. }
  1946. advice.ExecutionStaff = executionStaff
  1947. advice.ExecutionTime = theTime.Unix()
  1948. c.ServeSuccessJSON(map[string]interface{}{
  1949. "msg": "ok",
  1950. "advice": advice,
  1951. })
  1952. return
  1953. }
  1954. func (c *PatientApiController) ExecDoctorAdvice() {
  1955. origin, _ := c.GetInt64("origin", 0)
  1956. patient, _ := c.GetInt64("patient", 0)
  1957. id, _ := c.GetInt64("id", 0)
  1958. executionTime := c.GetString("execution_time")
  1959. if origin != 2 {
  1960. if id <= 0 || patient <= 0 {
  1961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1962. return
  1963. }
  1964. if len(executionTime) <= 0 {
  1965. utils.ErrorLog("execution_time")
  1966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1967. return
  1968. }
  1969. adminUserInfo := c.GetAdminUserInfo()
  1970. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1971. //自备药
  1972. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
  1973. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  1974. //查询库存是否
  1975. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  1976. if selfBasedrug.IsSelfDrug == 1 {
  1977. selfDrugStockCount, _ := service.GetSelfDrugStockCountByPatientId(advice.DrugId, advice.PatientId, advice.UserOrgId)
  1978. var prescribing_number_total_one int64
  1979. //判断单位是否相等
  1980. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  1981. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1982. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1983. //转化为最小单位
  1984. prescribing_number_total_one = count * selfBasedrug.MinNumber
  1985. }
  1986. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  1987. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1988. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1989. prescribing_number_total_one = count
  1990. }
  1991. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  1992. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1993. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1994. prescribing_number_total_one = count
  1995. }
  1996. //库存不足
  1997. if prescribing_number_total_one > selfDrugStockCount.FlushCount {
  1998. c.ServeSuccessJSON(map[string]interface{}{
  1999. "msg": "2",
  2000. "advice": advice,
  2001. })
  2002. return
  2003. }
  2004. }
  2005. }
  2006. if advice.ID == 0 || advice.PatientId != patient {
  2007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2008. return
  2009. }
  2010. //医嘱已执行
  2011. if advice.ExecutionState == 1 {
  2012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  2013. return
  2014. }
  2015. executionStaff := adminUserInfo.AdminUser.Id
  2016. timeLayout := "2006-01-02 15:04:05"
  2017. loc, _ := time.LoadLocation("Local")
  2018. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  2019. if err != nil {
  2020. utils.ErrorLog(err.Error())
  2021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2022. return
  2023. }
  2024. if advice.StartTime > theTime.Unix() {
  2025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2026. return
  2027. }
  2028. exceAdvice := models.DoctorAdvice{
  2029. ExecutionStaff: executionStaff,
  2030. ExecutionTime: theTime.Unix(),
  2031. UpdatedTime: time.Now().Unix(),
  2032. }
  2033. // 查询信息规挡的设置天数
  2034. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2035. if infor.ID > 0 && infor.WeekDay > 0 {
  2036. var cha_time int64
  2037. timeNowStr := time.Now().Format("2006-01-02")
  2038. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2039. //今日的日期减去设置的日期
  2040. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2041. if cha_time >= advice.AdviceDate {
  2042. //查询审核是否允许
  2043. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  2044. //申请状态不允许的情况 拒绝修改
  2045. if infor.ApplicationStatus != 1 {
  2046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2047. return
  2048. }
  2049. }
  2050. }
  2051. if advice.ParentId > 0 {
  2052. err = service.ExceDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2053. //记录日志
  2054. byterequest, _ := json.Marshal(exceAdvice)
  2055. doctorAdviceLog := models.XtDoctorAdviceLog{
  2056. UserOrgId: exceAdvice.UserOrgId,
  2057. PatientId: exceAdvice.PatientId,
  2058. AdminUserId: adminUserInfo.AdminUser.Id,
  2059. Module: 2,
  2060. ErrLog: string(byterequest),
  2061. Status: 1,
  2062. Ctime: time.Now().Unix(),
  2063. Mtime: 0,
  2064. Source: "电脑端执行医嘱",
  2065. RecordDate: exceAdvice.RecordDate,
  2066. }
  2067. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2068. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2069. redis := service.RedisClient()
  2070. //清空key 值
  2071. redis.Set(key, "", time.Second)
  2072. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2073. redis.Set(keyTwo, "", time.Second)
  2074. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2075. redis.Set(keyThree, "", time.Second)
  2076. theTimes := theTime.Format("2006-01-02")
  2077. fmt.Println("theTIME", theTime)
  2078. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2079. redis.Set(keyFour, "", time.Second)
  2080. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2081. redis.Set(keyFive, "", time.Second)
  2082. defer redis.Close()
  2083. } else {
  2084. err = service.ExceDoctorAdviceById(&exceAdvice, id, patient)
  2085. //记录日志
  2086. byterequest, _ := json.Marshal(exceAdvice)
  2087. doctorAdviceLog := models.XtDoctorAdviceLog{
  2088. UserOrgId: exceAdvice.UserOrgId,
  2089. PatientId: exceAdvice.PatientId,
  2090. AdminUserId: adminUserInfo.AdminUser.Id,
  2091. Module: 2,
  2092. ErrLog: string(byterequest),
  2093. Status: 1,
  2094. Ctime: time.Now().Unix(),
  2095. Mtime: 0,
  2096. Source: "电脑端执行医嘱",
  2097. RecordDate: exceAdvice.RecordDate,
  2098. }
  2099. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2100. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2101. redis := service.RedisClient()
  2102. //清空key 值
  2103. redis.Set(key, "", time.Second)
  2104. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2105. redis.Set(keyTwo, "", time.Second)
  2106. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2107. redis.Set(keyThree, "", time.Second)
  2108. theTimes := theTime.Format("2006-01-02")
  2109. fmt.Println("theTIME", theTime)
  2110. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2111. redis.Set(keyFour, "", time.Second)
  2112. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2113. redis.Set(keyFive, "", time.Second)
  2114. defer redis.Close()
  2115. }
  2116. if err != nil {
  2117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2118. return
  2119. }
  2120. advice.ExecutionStaff = executionStaff
  2121. advice.ExecutionTime = theTime.Unix()
  2122. //处理出库相关逻辑
  2123. //1.判断是否启用药品管理和自备药出库功能
  2124. //药品管理信息
  2125. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2126. //自备药信息
  2127. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
  2128. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2129. if drugStockConfig.IsOpen == 1 {
  2130. var total int64
  2131. var prescribing_number_total int64
  2132. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  2133. for _, item := range advices {
  2134. houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2135. //查询该药品是否有库存
  2136. list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  2137. //查询改药品信息
  2138. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  2139. //判断单位是否相等
  2140. if medical.MaxUnit == item.PrescribingNumberUnit {
  2141. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2142. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2143. //转化为最小单位
  2144. total = list.Count*medical.MinNumber + list.StockMinNumber
  2145. prescribing_number_total = count * medical.MinNumber
  2146. }
  2147. if medical.MinUnit == item.PrescribingNumberUnit {
  2148. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2149. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2150. total = list.Count*medical.MinNumber + list.StockMinNumber
  2151. prescribing_number_total = count
  2152. }
  2153. if medical.IsUse != 1 {
  2154. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  2155. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  2156. advice.ExecutionState = 2
  2157. advice.ExecutionStaff = 0
  2158. advice.ExecutionTime = 0
  2159. c.ServeSuccessJSON(map[string]interface{}{
  2160. "msg": "3",
  2161. "advice": advice,
  2162. })
  2163. return
  2164. }
  2165. if prescribing_number_total > total {
  2166. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  2167. advice.ExecutionState = 2
  2168. advice.ExecutionStaff = 0
  2169. advice.ExecutionTime = 0
  2170. c.ServeSuccessJSON(map[string]interface{}{
  2171. "msg": "2",
  2172. "advice": advice,
  2173. })
  2174. return
  2175. }
  2176. }
  2177. if medical.IsUse == 1 {
  2178. c.ServeSuccessJSON(map[string]interface{}{
  2179. "msg": "1",
  2180. "advice": advice,
  2181. })
  2182. return
  2183. }
  2184. if prescribing_number_total <= total {
  2185. //查询是否门诊处方和临时医嘱同步到透析医嘱的开关是否开启
  2186. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  2187. if adviceSetting.IsAdviceOpen == 1 {
  2188. //查询是否出库按钮开启
  2189. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  2190. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2191. if prescriptionConfig.IsOpen == 1 {
  2192. if medical.IsUse == 2 {
  2193. //是通过药房发药
  2194. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2195. //执行出库
  2196. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2197. if drugOutInfo.ID == 0 {
  2198. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2199. }
  2200. }
  2201. //不通过药房发药
  2202. if pharmacyConfig.IsOpen != 1 {
  2203. //执行出库
  2204. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2205. if drugOutInfo.ID == 0 {
  2206. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2207. }
  2208. }
  2209. //查询默认仓库
  2210. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2211. //查询默认仓库剩余多少库存
  2212. var sum_count int64
  2213. //更新字典里面的库存
  2214. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2215. for _, its := range stockInfo {
  2216. if its.MaxUnit == medical.MaxUnit {
  2217. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2218. }
  2219. sum_count += its.StockMaxNumber + its.StockMinNumber
  2220. }
  2221. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2222. //剩余库存
  2223. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2224. break
  2225. c.ServeSuccessJSON(map[string]interface{}{
  2226. "msg": "1",
  2227. "advice": advice,
  2228. })
  2229. return
  2230. }
  2231. if medical.IsUse == 1 {
  2232. c.ServeSuccessJSON(map[string]interface{}{
  2233. "msg": "1",
  2234. "advice": advice,
  2235. })
  2236. return
  2237. }
  2238. } else {
  2239. if medical.IsUse == 1 {
  2240. c.ServeSuccessJSON(map[string]interface{}{
  2241. "msg": "1",
  2242. "advice": advice,
  2243. })
  2244. return
  2245. }
  2246. }
  2247. } else {
  2248. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2249. if medical.IsUse == 2 {
  2250. //是通过药房发药
  2251. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2252. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2253. if drugOutInfo.ID == 0 {
  2254. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2255. }
  2256. }
  2257. //不通过药房发药
  2258. if pharmacyConfig.IsOpen != 1 {
  2259. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2260. if drugOutInfo.ID == 0 {
  2261. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2262. }
  2263. }
  2264. //更新字典里面的库存
  2265. var sum_count int64
  2266. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2267. for _, its := range stockInfo {
  2268. if its.MaxUnit == medical.MaxUnit {
  2269. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2270. }
  2271. sum_count += its.StockMaxNumber + its.StockMinNumber
  2272. }
  2273. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2274. //剩余库存
  2275. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2276. break
  2277. c.ServeSuccessJSON(map[string]interface{}{
  2278. "msg": "1",
  2279. "advice": advice,
  2280. })
  2281. return
  2282. }
  2283. if medical.IsUse == 1 {
  2284. c.ServeSuccessJSON(map[string]interface{}{
  2285. "msg": "1",
  2286. "advice": advice,
  2287. })
  2288. return
  2289. }
  2290. }
  2291. }
  2292. }
  2293. }
  2294. //自备药
  2295. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
  2296. if selfPrescriptionOutOpen.IsOpen == 1 {
  2297. db := service.XTWriteDB()
  2298. tx := db.Begin()
  2299. defer func() {
  2300. if r := recover(); r != nil {
  2301. tx.Rollback()
  2302. } else {
  2303. tx.Commit()
  2304. }
  2305. }()
  2306. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  2307. if selfBasedrug.IsSelfDrug == 1 {
  2308. //查询是否有库存
  2309. info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
  2310. if len(info) > 0 {
  2311. var total_count int64
  2312. var prescribing_number_total int64
  2313. for _, item := range info {
  2314. if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  2315. item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
  2316. }
  2317. total_count += item.StockMaxNumber + item.StockMinNumber
  2318. }
  2319. //判断单位是否相等
  2320. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  2321. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2322. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2323. //转化为最小单位
  2324. prescribing_number_total = count * selfBasedrug.MinNumber
  2325. }
  2326. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  2327. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2328. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2329. prescribing_number_total = count
  2330. }
  2331. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  2332. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2333. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2334. prescribing_number_total = count
  2335. }
  2336. if prescribing_number_total > total_count {
  2337. c.ServeSuccessJSON(map[string]interface{}{
  2338. "msg": "3",
  2339. "advice": advice,
  2340. })
  2341. return
  2342. }
  2343. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  2344. //出库
  2345. if prescribing_number_total <= total_count {
  2346. timeStr := time.Now().Format("2006-01-02")
  2347. timeArr := strings.Split(timeStr, "-")
  2348. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  2349. total = total + 1
  2350. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2351. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2352. number = number + total
  2353. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  2354. operation_time := time.Now().Unix()
  2355. creater := c.GetAdminUserInfo().AdminUser.Id
  2356. //创建一个出库单
  2357. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  2358. WarehouseOutOrderNumber: warehousing_out_order,
  2359. OperationTime: operation_time,
  2360. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2361. Creater: creater,
  2362. Ctime: time.Now().Unix(),
  2363. Status: 1,
  2364. WarehouseOutTime: advice.AdviceDate,
  2365. Type: 0,
  2366. PatientId: advice.PatientId,
  2367. IsCheck: 1,
  2368. IsSys: 1,
  2369. }
  2370. //查询今日是否有出库数据
  2371. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  2372. if lastWarehouseOut.ID == 0 {
  2373. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  2374. }
  2375. //查询今日是否有出库数据
  2376. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  2377. //出库
  2378. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  2379. WarehouseOutId: lastWarehouseOutOne.ID,
  2380. WarehouseOutOrderNumber: warehousing_out_order,
  2381. DrugId: advice.DrugId,
  2382. Count: prescribing_number_total,
  2383. Price: 0,
  2384. TotalPrice: 0,
  2385. Status: 1,
  2386. Ctime: advice.AdviceDate,
  2387. Mtime: advice.AdviceDate,
  2388. Remark: "",
  2389. OrgId: advice.UserOrgId,
  2390. Type: 0,
  2391. Manufacturer: selfBasedrug.Manufacturer,
  2392. Dealer: selfBasedrug.Dealer,
  2393. RetailPrice: 0,
  2394. RetailTotalPrice: 0,
  2395. CountUnit: selfBasedrug.MinUnit,
  2396. ExpiryDate: 0,
  2397. ProductDate: 0,
  2398. Number: "",
  2399. BatchNumber: "",
  2400. IsSys: 0,
  2401. WarehouseInfoId: 0,
  2402. AdminUserId: 0,
  2403. StockCount: "",
  2404. IsCheck: 1,
  2405. SysRecordTime: advice.AdviceDate,
  2406. PatientId: advice.PatientId,
  2407. AdviceId: advice.ID,
  2408. ClassType: "",
  2409. }
  2410. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  2411. for _, it := range warehousingOutInfo {
  2412. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  2413. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  2414. //出库逻辑
  2415. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  2416. //查询剩余库存
  2417. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  2418. var sum_count int64
  2419. for _, its := range stockInfo {
  2420. if its.MaxUnit == medical.MaxUnit {
  2421. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2422. }
  2423. sum_count += its.StockMaxNumber + its.StockMinNumber
  2424. }
  2425. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  2426. }
  2427. }
  2428. } else {
  2429. c.ServeSuccessJSON(map[string]interface{}{
  2430. "msg": "3",
  2431. "advice": advice,
  2432. })
  2433. return
  2434. }
  2435. }
  2436. }
  2437. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  2438. for _, item := range advices {
  2439. if item.Way == 2 {
  2440. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  2441. if item.ExecutionState == 1 {
  2442. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2443. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2444. timeStr := time.Now().Format("2006-01-02")
  2445. timeArr := strings.Split(timeStr, "-")
  2446. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  2447. total = total + 1
  2448. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2449. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2450. number = number + total
  2451. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2452. //插入自备药出库单
  2453. outStock := models.XtSelfOutStock{
  2454. DrugName: item.AdviceName,
  2455. DrugNameId: item.DrugId,
  2456. DrugSpec: item.AdviceDesc,
  2457. OutstoreNumber: count,
  2458. AdminUserId: adminUserInfo.AdminUser.Id,
  2459. StorckTime: item.RecordDate,
  2460. UserOrgId: adminUserInfo.CurrentOrgId,
  2461. CreatedTime: time.Now().Unix(),
  2462. Status: 1,
  2463. PatientId: item.PatientId,
  2464. ExitMode: 2,
  2465. MedicId: item.DrugId,
  2466. StockOutNumber: warehousing_out_order,
  2467. }
  2468. service.CreateOutStock(&outStock)
  2469. }
  2470. }
  2471. }
  2472. }
  2473. c.ServeSuccessJSON(map[string]interface{}{
  2474. "msg": "1",
  2475. "advice": advice,
  2476. })
  2477. return
  2478. } else {
  2479. if id <= 0 || patient <= 0 {
  2480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2481. return
  2482. }
  2483. if len(executionTime) <= 0 {
  2484. utils.ErrorLog("execution_time")
  2485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2486. return
  2487. }
  2488. adminUserInfo := c.GetAdminUserInfo()
  2489. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2490. if advice.ID == 0 || advice.PatientId != patient {
  2491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2492. return
  2493. }
  2494. //医嘱已执行
  2495. if advice.ExecutionState == 1 {
  2496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  2497. return
  2498. }
  2499. executionStaff := adminUserInfo.AdminUser.Id
  2500. timeLayout := "2006-01-02 15:04:05"
  2501. loc, _ := time.LoadLocation("Local")
  2502. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  2503. if err != nil {
  2504. utils.ErrorLog(err.Error())
  2505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2506. return
  2507. }
  2508. if advice.StartTime > theTime.Unix() {
  2509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2510. return
  2511. }
  2512. exceAdvice := models.HisDoctorAdviceInfo{
  2513. ExecutionStaff: executionStaff,
  2514. ExecutionTime: theTime.Unix(),
  2515. UpdatedTime: time.Now().Unix(),
  2516. }
  2517. if advice.ParentId > 0 {
  2518. err = service.ExceHidDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2519. //记录日志
  2520. byterequest, _ := json.Marshal(exceAdvice)
  2521. doctorAdviceLog := models.XtDoctorAdviceLog{
  2522. UserOrgId: exceAdvice.UserOrgId,
  2523. PatientId: exceAdvice.PatientId,
  2524. AdminUserId: adminUserInfo.AdminUser.Id,
  2525. Module: 2,
  2526. ErrLog: string(byterequest),
  2527. Status: 1,
  2528. Ctime: time.Now().Unix(),
  2529. Mtime: 0,
  2530. Source: "电脑端执行His医嘱",
  2531. RecordDate: exceAdvice.RecordDate,
  2532. }
  2533. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2534. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2535. redis := service.RedisClient()
  2536. //清空key 值
  2537. redis.Set(key, "", time.Second)
  2538. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2539. redis.Set(keyTwo, "", time.Second)
  2540. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2541. redis.Set(keyThree, "", time.Second)
  2542. theTimes := theTime.Format("2006-01-02")
  2543. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2544. redis.Set(keyFour, "", time.Second)
  2545. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2546. redis.Set(keyFive, "", time.Second)
  2547. defer redis.Close()
  2548. } else {
  2549. err = service.ExceHidDoctorAdviceById(&exceAdvice, id, patient)
  2550. //记录日志
  2551. byterequest, _ := json.Marshal(exceAdvice)
  2552. doctorAdviceLog := models.XtDoctorAdviceLog{
  2553. UserOrgId: exceAdvice.UserOrgId,
  2554. PatientId: exceAdvice.PatientId,
  2555. AdminUserId: adminUserInfo.AdminUser.Id,
  2556. Module: 2,
  2557. ErrLog: string(byterequest),
  2558. Status: 1,
  2559. Ctime: time.Now().Unix(),
  2560. Mtime: 0,
  2561. Source: "电脑端执行His医嘱",
  2562. RecordDate: exceAdvice.RecordDate,
  2563. }
  2564. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2565. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2566. redis := service.RedisClient()
  2567. //清空key 值
  2568. redis.Set(key, "", time.Second)
  2569. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2570. redis.Set(keyTwo, "", time.Second)
  2571. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2572. redis.Set(keyThree, "", time.Second)
  2573. theTimes := theTime.Format("2006-01-02")
  2574. fmt.Println("theTIME", theTime)
  2575. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2576. redis.Set(keyFour, "", time.Second)
  2577. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2578. redis.Set(keyFive, "", time.Second)
  2579. defer redis.Close()
  2580. }
  2581. if err != nil {
  2582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2583. return
  2584. }
  2585. advice.ExecutionStaff = executionStaff
  2586. advice.ExecutionTime = theTime.Unix()
  2587. //处理出库相关逻辑
  2588. //1.判断是否启用药品管理和自备药出库功能
  2589. //药品自动出库开关管理信息
  2590. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2591. if drugStockConfig.IsOpen == 1 {
  2592. //查询已经执行的医嘱
  2593. advices, _ := service.GetHisExecutionDoctorsTwo(adminUserInfo.CurrentOrgId, patient, id)
  2594. for _, item := range advices {
  2595. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  2596. var total int64
  2597. var prescribing_number_total int64
  2598. //药品保存处方出库
  2599. config, _ := service.GetDrugOpenConfigOne(adminUserInfo.CurrentOrgId)
  2600. if config.IsOpen != 1 {
  2601. //查询默认出库仓库
  2602. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  2603. //查询该药品在默认仓库是否有库存
  2604. list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  2605. //判断单位是否相等
  2606. if medical.MaxUnit == advice.PrescribingNumberUnit {
  2607. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2608. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2609. //转化为最小单位
  2610. total = list.Count*medical.MinNumber + list.StockMinNumber
  2611. prescribing_number_total = count * medical.MinNumber
  2612. }
  2613. if medical.MinUnit == advice.PrescribingNumberUnit {
  2614. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2615. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2616. total = list.Count*medical.MinNumber + list.StockMinNumber
  2617. prescribing_number_total = count
  2618. }
  2619. if medical.IsUse == 1 {
  2620. drugError := models.XtDrugError{
  2621. UserOrgId: item.UserOrgId,
  2622. DrugId: item.DrugId,
  2623. RecordDate: item.AdviceDate,
  2624. PatientId: item.PatientId,
  2625. Remark: "电脑端零用药品",
  2626. Status: 1,
  2627. Ctime: time.Now().Unix(),
  2628. Mtime: 0,
  2629. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2630. Prescribingnumber: item.PrescribingNumber,
  2631. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2632. }
  2633. service.CreateDrugError(drugError)
  2634. c.ServeSuccessJSON(map[string]interface{}{
  2635. "msg": "1",
  2636. "advice": advice,
  2637. })
  2638. return
  2639. }
  2640. if medical.IsUse != 1 {
  2641. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  2642. drugError := models.XtDrugError{
  2643. UserOrgId: item.UserOrgId,
  2644. DrugId: item.DrugId,
  2645. RecordDate: item.AdviceDate,
  2646. PatientId: item.PatientId,
  2647. Remark: "电脑端药品库存不足",
  2648. Status: 1,
  2649. Ctime: time.Now().Unix(),
  2650. Mtime: 0,
  2651. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2652. Prescribingnumber: item.PrescribingNumber,
  2653. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2654. }
  2655. service.CreateDrugError(drugError)
  2656. c.ServeSuccessJSON(map[string]interface{}{
  2657. "msg": "3",
  2658. "advice": advice,
  2659. })
  2660. return
  2661. }
  2662. if prescribing_number_total > total {
  2663. drugError := models.XtDrugError{
  2664. UserOrgId: item.UserOrgId,
  2665. DrugId: item.DrugId,
  2666. RecordDate: item.AdviceDate,
  2667. PatientId: item.PatientId,
  2668. Remark: "电脑端出库数量大于总库存",
  2669. Status: 1,
  2670. Ctime: time.Now().Unix(),
  2671. Mtime: 0,
  2672. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2673. Prescribingnumber: item.PrescribingNumber,
  2674. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2675. }
  2676. service.CreateDrugError(drugError)
  2677. c.ServeSuccessJSON(map[string]interface{}{
  2678. "msg": "2",
  2679. "advice": advice,
  2680. })
  2681. return
  2682. }
  2683. }
  2684. if prescribing_number_total <= total {
  2685. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2686. if medical.IsUse == 2 {
  2687. if config.IsOpen != 1 {
  2688. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2689. // 开始主事务
  2690. db := service.XTWriteDB()
  2691. tx := db.Begin()
  2692. // 在函数结束时处理事务回滚
  2693. defer func() {
  2694. if r := recover(); r != nil {
  2695. tx.Rollback()
  2696. }
  2697. }()
  2698. creater := c.GetAdminUserInfo().AdminUser.Id
  2699. outListExport, _ := service.GetWarehouseOutListExport(item.DrugId, item.PatientId, item.AdviceDate, item.ID)
  2700. var out_count int64
  2701. if len(outListExport) > 0 {
  2702. for _, item := range outListExport {
  2703. if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2704. out_count = item.Count * medical.MinNumber
  2705. }
  2706. if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2707. out_count = item.Count
  2708. }
  2709. if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2710. out_count = item.Count * medical.MinNumber
  2711. }
  2712. }
  2713. }
  2714. newadviceInfo := &models.HisDoctorAdviceInfo{
  2715. ID: item.ID,
  2716. UserOrgId: item.UserOrgId,
  2717. PatientId: item.PatientId,
  2718. HisPatientId: item.HisPatientId,
  2719. AdviceType: item.AdviceType,
  2720. AdviceDate: item.AdviceDate,
  2721. StartTime: item.StartTime,
  2722. AdviceName: item.AdviceName,
  2723. AdviceDesc: item.AdviceDesc,
  2724. ReminderDate: item.ReminderDate,
  2725. SingleDose: item.SingleDose,
  2726. SingleDoseUnit: item.SingleDoseUnit,
  2727. PrescribingNumber: item.PrescribingNumber,
  2728. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2729. DeliveryWay: item.DeliveryWay,
  2730. ExecutionFrequency: item.ExecutionFrequency,
  2731. AdviceDoctor: item.AdviceDoctor,
  2732. Status: item.Status,
  2733. CreatedTime: item.CreatedTime,
  2734. UpdatedTime: item.UpdatedTime,
  2735. AdviceAffirm: item.AdviceAffirm,
  2736. Remark: item.Remark,
  2737. StopTime: item.StopTime,
  2738. StopReason: item.StopReason,
  2739. StopDoctor: item.StopDoctor,
  2740. StopState: item.StopState,
  2741. ParentId: item.ParentId,
  2742. ExecutionTime: item.ExecutionTime,
  2743. ExecutionStaff: item.ExecutionStaff,
  2744. ExecutionState: item.ExecutionState,
  2745. Checker: item.Checker,
  2746. RecordDate: item.RecordDate,
  2747. DialysisOrderId: item.DialysisOrderId,
  2748. CheckTime: item.CheckTime,
  2749. CheckState: item.CheckState,
  2750. DrugSpec: item.DrugSpec,
  2751. DrugSpecUnit: item.DrugSpecUnit,
  2752. Groupno: item.Groupno,
  2753. RemindType: item.RemindType,
  2754. FrequencyType: item.FrequencyType,
  2755. DayCount: item.DayCount,
  2756. WeekDay: item.WeekDay,
  2757. TemplateId: item.TemplateId,
  2758. Modifier: item.Modifier,
  2759. DrugId: item.DrugId,
  2760. Price: item.Price,
  2761. PrescriptionId: item.PrescriptionId,
  2762. MedListCodg: item.MedListCodg,
  2763. FeedetlSn: item.FeedetlSn,
  2764. Day: item.DayCount,
  2765. ChildDoctorAdvice: nil,
  2766. Drug: models.Drug{},
  2767. Diagnosis: item.Diagnosis,
  2768. Way: item.Way,
  2769. HospApprFlag: item.HospApprFlag,
  2770. LmtUsedFlag: item.LmtUsedFlag,
  2771. HisOrderInfo: models.HisOrderInfo{},
  2772. IsMedicine: item.IsMedicine,
  2773. ExecutionFrequencyId: item.ExecutionFrequencyId,
  2774. Child: nil,
  2775. IsSettle: item.IsSettle,
  2776. IsMobile: item.IsMobile,
  2777. IsSelfDrug: item.IsSelfDrug,
  2778. DrugWayCount: item.DrugWayCount,
  2779. }
  2780. //如果当前医嘱数量大于历史出库数据则需要出库
  2781. if prescribing_number_total > out_count {
  2782. //按最小单位出库
  2783. var cha_count = prescribing_number_total - out_count
  2784. item.PrescribingNumber = float64(cha_count)
  2785. item.PrescribingNumberUnit = medical.MinUnit
  2786. service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
  2787. }
  2788. //如果当前医嘱数量小于历史出库数据则需要退库
  2789. if prescribing_number_total < out_count {
  2790. var cha_count = out_count - prescribing_number_total
  2791. drug, _ := service.FindBaseDrugLibRecordSeven(item.UserOrgId, item.DrugId)
  2792. service.NewHisDrugCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  2793. service.NewHisDrugAutoCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  2794. }
  2795. if prescribing_number_total == out_count {
  2796. if out_count == 0 {
  2797. service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
  2798. }
  2799. }
  2800. //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2801. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2802. //查询该药品是否有出库记录
  2803. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  2804. if len(flowMap) == 0 {
  2805. errs := service.UpdateHisAdviceById(item.ID)
  2806. if errs != nil {
  2807. drugError := models.XtDrugError{
  2808. UserOrgId: item.UserOrgId,
  2809. DrugId: item.DrugId,
  2810. RecordDate: item.AdviceDate,
  2811. PatientId: item.PatientId,
  2812. Remark: "出库记录为空,更新执行人失败",
  2813. Status: 1,
  2814. Ctime: time.Now().Unix(),
  2815. Mtime: 0,
  2816. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2817. Prescribingnumber: item.PrescribingNumber,
  2818. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2819. }
  2820. service.CreateDrugError(drugError)
  2821. }
  2822. c.ServeSuccessJSON(map[string]interface{}{
  2823. "msg": "6",
  2824. "advice": advice,
  2825. })
  2826. return
  2827. }
  2828. }
  2829. tx.Commit()
  2830. }
  2831. //不通过药房发药
  2832. if pharmacyConfig.IsOpen != 1 {
  2833. //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2834. // 开始主事务
  2835. db := service.XTWriteDB()
  2836. tx := db.Begin()
  2837. // 在函数结束时处理事务回滚
  2838. defer func() {
  2839. if r := recover(); r != nil {
  2840. tx.Rollback()
  2841. }
  2842. }()
  2843. creater := c.GetAdminUserInfo().AdminUser.Id
  2844. outListExport, _ := service.GetWarehouseOutListExport(item.DrugId, item.PatientId, item.AdviceDate, item.ID)
  2845. var out_count int64
  2846. if len(outListExport) > 0 {
  2847. for _, item := range outListExport {
  2848. if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2849. out_count = item.Count * medical.MinNumber
  2850. }
  2851. if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2852. out_count = item.Count
  2853. }
  2854. if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2855. out_count = item.Count * medical.MinNumber
  2856. }
  2857. }
  2858. }
  2859. newadviceInfo := &models.HisDoctorAdviceInfo{
  2860. ID: item.ID,
  2861. UserOrgId: item.UserOrgId,
  2862. PatientId: item.PatientId,
  2863. HisPatientId: item.HisPatientId,
  2864. AdviceType: item.AdviceType,
  2865. AdviceDate: item.AdviceDate,
  2866. StartTime: item.StartTime,
  2867. AdviceName: item.AdviceName,
  2868. AdviceDesc: item.AdviceDesc,
  2869. ReminderDate: item.ReminderDate,
  2870. SingleDose: item.SingleDose,
  2871. SingleDoseUnit: item.SingleDoseUnit,
  2872. PrescribingNumber: item.PrescribingNumber,
  2873. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2874. DeliveryWay: item.DeliveryWay,
  2875. ExecutionFrequency: item.ExecutionFrequency,
  2876. AdviceDoctor: item.AdviceDoctor,
  2877. Status: item.Status,
  2878. CreatedTime: item.CreatedTime,
  2879. UpdatedTime: item.UpdatedTime,
  2880. AdviceAffirm: item.AdviceAffirm,
  2881. Remark: item.Remark,
  2882. StopTime: item.StopTime,
  2883. StopReason: item.StopReason,
  2884. StopDoctor: item.StopDoctor,
  2885. StopState: item.StopState,
  2886. ParentId: item.ParentId,
  2887. ExecutionTime: item.ExecutionTime,
  2888. ExecutionStaff: item.ExecutionStaff,
  2889. ExecutionState: item.ExecutionState,
  2890. Checker: item.Checker,
  2891. RecordDate: item.RecordDate,
  2892. DialysisOrderId: item.DialysisOrderId,
  2893. CheckTime: item.CheckTime,
  2894. CheckState: item.CheckState,
  2895. DrugSpec: item.DrugSpec,
  2896. DrugSpecUnit: item.DrugSpecUnit,
  2897. Groupno: item.Groupno,
  2898. RemindType: item.RemindType,
  2899. FrequencyType: item.FrequencyType,
  2900. DayCount: item.DayCount,
  2901. WeekDay: item.WeekDay,
  2902. TemplateId: item.TemplateId,
  2903. Modifier: item.Modifier,
  2904. DrugId: item.DrugId,
  2905. Price: item.Price,
  2906. PrescriptionId: item.PrescriptionId,
  2907. MedListCodg: item.MedListCodg,
  2908. FeedetlSn: item.FeedetlSn,
  2909. Day: item.DayCount,
  2910. ChildDoctorAdvice: nil,
  2911. Drug: models.Drug{},
  2912. Diagnosis: item.Diagnosis,
  2913. Way: item.Way,
  2914. HospApprFlag: item.HospApprFlag,
  2915. LmtUsedFlag: item.LmtUsedFlag,
  2916. HisOrderInfo: models.HisOrderInfo{},
  2917. IsMedicine: item.IsMedicine,
  2918. ExecutionFrequencyId: item.ExecutionFrequencyId,
  2919. Child: nil,
  2920. IsSettle: item.IsSettle,
  2921. IsMobile: item.IsMobile,
  2922. IsSelfDrug: item.IsSelfDrug,
  2923. DrugWayCount: item.DrugWayCount,
  2924. }
  2925. //如果当前医嘱数量大于历史出库数据则需要出库
  2926. if prescribing_number_total > out_count {
  2927. //按最小单位出库
  2928. var cha_count = prescribing_number_total - out_count
  2929. newadviceInfo.PrescribingNumber = float64(cha_count)
  2930. newadviceInfo.PrescribingNumberUnit = medical.MinUnit
  2931. service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
  2932. }
  2933. //如果当前医嘱数量小于历史出库数据则需要退库
  2934. if prescribing_number_total < out_count {
  2935. var cha_count = out_count - prescribing_number_total
  2936. drug, _ := service.FindBaseDrugLibRecordSeven(item.UserOrgId, item.DrugId)
  2937. service.NewHisDrugCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  2938. service.NewHisDrugAutoCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  2939. }
  2940. if prescribing_number_total == out_count {
  2941. if out_count == 0 {
  2942. service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
  2943. }
  2944. }
  2945. //service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2946. tx.Commit()
  2947. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2948. //查询该药品是否有出库记录
  2949. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  2950. if len(flowMap) == 0 {
  2951. errs := service.UpdateHisAdviceById(item.ID)
  2952. if errs != nil {
  2953. drugError := models.XtDrugError{
  2954. UserOrgId: item.UserOrgId,
  2955. DrugId: item.DrugId,
  2956. RecordDate: item.AdviceDate,
  2957. PatientId: item.PatientId,
  2958. Remark: "出库记录为空,更新执行人失败",
  2959. Status: 1,
  2960. Ctime: time.Now().Unix(),
  2961. Mtime: 0,
  2962. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2963. Prescribingnumber: item.PrescribingNumber,
  2964. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2965. }
  2966. service.CreateDrugError(drugError)
  2967. }
  2968. c.ServeSuccessJSON(map[string]interface{}{
  2969. "msg": "6",
  2970. "advice": advice,
  2971. })
  2972. return
  2973. }
  2974. }
  2975. }
  2976. //查询默认仓库
  2977. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2978. //查询默认仓库剩余多少库存
  2979. var sum_count int64
  2980. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2981. for _, its := range stockInfo {
  2982. if its.MaxUnit == medical.MaxUnit {
  2983. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2984. }
  2985. sum_count += its.StockMaxNumber + its.StockMinNumber
  2986. }
  2987. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2988. //出库数量累加
  2989. //service.AddDrugCount(item.DrugId,item.UserOrgId,storeHouseConfig.DrugStorehouseOut,prescribing_number_total)
  2990. //剩余库存
  2991. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2992. break
  2993. c.ServeSuccessJSON(map[string]interface{}{
  2994. "msg": "1",
  2995. "advice": advice,
  2996. })
  2997. return
  2998. }
  2999. }
  3000. if medical.IsUse == 1 {
  3001. c.ServeSuccessJSON(map[string]interface{}{
  3002. "msg": "1",
  3003. "advice": advice,
  3004. })
  3005. return
  3006. }
  3007. }
  3008. }
  3009. }
  3010. }
  3011. //自备药
  3012. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
  3013. if selfPrescriptionOutOpen.IsOpen == 1 {
  3014. db := service.XTWriteDB()
  3015. tx := db.Begin()
  3016. defer func() {
  3017. if r := recover(); r != nil {
  3018. tx.Rollback()
  3019. } else {
  3020. tx.Commit()
  3021. }
  3022. }()
  3023. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  3024. if selfBasedrug.IsSelfDrug == 1 {
  3025. //查询是否有库存
  3026. info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
  3027. if len(info) > 0 {
  3028. var total_count int64
  3029. var prescribing_number_total int64
  3030. for _, item := range info {
  3031. if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  3032. item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
  3033. }
  3034. total_count += item.StockMaxNumber + item.StockMinNumber
  3035. }
  3036. //判断单位是否相等
  3037. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  3038. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  3039. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  3040. //转化为最小单位
  3041. prescribing_number_total = count * selfBasedrug.MinNumber
  3042. }
  3043. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  3044. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  3045. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  3046. prescribing_number_total = count
  3047. }
  3048. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  3049. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  3050. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  3051. prescribing_number_total = count
  3052. }
  3053. if prescribing_number_total > total_count {
  3054. c.ServeSuccessJSON(map[string]interface{}{
  3055. "msg": "3",
  3056. "advice": advice,
  3057. })
  3058. return
  3059. }
  3060. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  3061. //出库
  3062. if prescribing_number_total <= total_count {
  3063. timeStr := time.Now().Format("2006-01-02")
  3064. timeArr := strings.Split(timeStr, "-")
  3065. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  3066. total = total + 1
  3067. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3068. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3069. number = number + total
  3070. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  3071. operation_time := time.Now().Unix()
  3072. creater := c.GetAdminUserInfo().AdminUser.Id
  3073. //创建一个出库单
  3074. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  3075. WarehouseOutOrderNumber: warehousing_out_order,
  3076. OperationTime: operation_time,
  3077. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3078. Creater: creater,
  3079. Ctime: time.Now().Unix(),
  3080. Status: 1,
  3081. WarehouseOutTime: advice.AdviceDate,
  3082. Type: 0,
  3083. PatientId: advice.PatientId,
  3084. IsCheck: 1,
  3085. IsSys: 1,
  3086. }
  3087. //查询今日是否有出库数据
  3088. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  3089. if lastWarehouseOut.ID == 0 {
  3090. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  3091. }
  3092. //查询今日是否有出库数据
  3093. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  3094. //出库
  3095. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  3096. WarehouseOutId: lastWarehouseOutOne.ID,
  3097. WarehouseOutOrderNumber: warehousing_out_order,
  3098. DrugId: advice.DrugId,
  3099. Count: prescribing_number_total,
  3100. Price: 0,
  3101. TotalPrice: 0,
  3102. Status: 1,
  3103. Ctime: advice.AdviceDate,
  3104. Mtime: advice.AdviceDate,
  3105. Remark: "",
  3106. OrgId: advice.UserOrgId,
  3107. Type: 0,
  3108. Manufacturer: selfBasedrug.Manufacturer,
  3109. Dealer: selfBasedrug.Dealer,
  3110. RetailPrice: 0,
  3111. RetailTotalPrice: 0,
  3112. CountUnit: selfBasedrug.MinUnit,
  3113. ExpiryDate: 0,
  3114. ProductDate: 0,
  3115. Number: "",
  3116. BatchNumber: "",
  3117. IsSys: 0,
  3118. WarehouseInfoId: 0,
  3119. AdminUserId: 0,
  3120. StockCount: "",
  3121. IsCheck: 1,
  3122. SysRecordTime: advice.AdviceDate,
  3123. PatientId: advice.PatientId,
  3124. AdviceId: advice.ID,
  3125. ClassType: "",
  3126. }
  3127. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  3128. for _, it := range warehousingOutInfo {
  3129. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  3130. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  3131. //出库逻辑
  3132. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  3133. //查询剩余库存
  3134. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  3135. var sum_count int64
  3136. for _, its := range stockInfo {
  3137. if its.MaxUnit == medical.MaxUnit {
  3138. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  3139. }
  3140. sum_count += its.StockMaxNumber + its.StockMinNumber
  3141. }
  3142. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  3143. }
  3144. }
  3145. }
  3146. }
  3147. }
  3148. c.ServeSuccessJSON(map[string]interface{}{
  3149. "msg": "1",
  3150. "advice": advice,
  3151. })
  3152. return
  3153. }
  3154. }
  3155. func (c *PatientApiController) CheckGroupAdvice() {
  3156. groupno, _ := c.GetInt64("groupno", 0)
  3157. if groupno <= 0 {
  3158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3159. return
  3160. }
  3161. adminUserInfo := c.GetAdminUserInfo()
  3162. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
  3163. if advice.ID == 0 {
  3164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3165. return
  3166. }
  3167. if advice.CheckState == 1 {
  3168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  3169. return
  3170. }
  3171. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  3172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3173. return
  3174. }
  3175. checker := adminUserInfo.AdminUser.Id
  3176. theTime := time.Now()
  3177. exceAdvice := models.DoctorAdvice{
  3178. Checker: checker,
  3179. CheckTime: theTime.Unix(),
  3180. UpdatedTime: time.Now().Unix(),
  3181. }
  3182. var err error
  3183. err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
  3184. if err != nil {
  3185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3186. return
  3187. }
  3188. advice.Checker = checker
  3189. advice.CheckTime = theTime.Unix()
  3190. c.ServeSuccessJSON(map[string]interface{}{
  3191. "msg": "ok",
  3192. "advice": advice,
  3193. })
  3194. return
  3195. }
  3196. func (c *PatientApiController) CheckDoctorAdvice() {
  3197. patient, _ := c.GetInt64("patient", 0)
  3198. id, _ := c.GetInt64("id", 0)
  3199. origin, _ := c.GetInt64("origin", 0)
  3200. if origin != 2 {
  3201. // executionTime := c.GetString("execution_time")
  3202. if id <= 0 || patient <= 0 {
  3203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3204. return
  3205. }
  3206. adminUserInfo := c.GetAdminUserInfo()
  3207. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3208. if advice.ID == 0 || advice.PatientId != patient {
  3209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3210. return
  3211. }
  3212. if advice.CheckState == 1 {
  3213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  3214. return
  3215. }
  3216. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  3217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3218. return
  3219. }
  3220. // executionStaff := adminUserInfo.AdminUser.Id
  3221. checker := adminUserInfo.AdminUser.Id
  3222. // timeLayout := "2006-01-02 15:04:05"
  3223. // loc, _ := time.LoadLocation("Local")
  3224. // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  3225. // if err != nil {
  3226. // utils.ErrorLog(err.Error())
  3227. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3228. // return
  3229. // }
  3230. theTime := time.Now()
  3231. if advice.ExecutionTime > theTime.Unix() {
  3232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  3233. return
  3234. }
  3235. exceAdvice := models.DoctorAdvice{
  3236. Checker: checker,
  3237. CheckTime: theTime.Unix(),
  3238. UpdatedTime: time.Now().Unix(),
  3239. }
  3240. var err error
  3241. // 查询信息规挡的设置天数
  3242. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3243. if infor.ID > 0 && infor.WeekDay > 0 {
  3244. var cha_time int64
  3245. timeNowStr := time.Now().Format("2006-01-02")
  3246. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3247. //今日的日期减去设置的日期
  3248. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3249. if cha_time >= advice.AdviceDate {
  3250. //查询审核是否允许
  3251. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3252. //申请状态不允许的情况 拒绝修改
  3253. if infor.ApplicationStatus != 1 {
  3254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3255. return
  3256. }
  3257. }
  3258. }
  3259. if advice.ParentId > 0 {
  3260. err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  3261. //记录日志
  3262. byterequest, _ := json.Marshal(exceAdvice)
  3263. adviceLog := models.XtDoctorAdviceLog{
  3264. UserOrgId: exceAdvice.UserOrgId,
  3265. PatientId: exceAdvice.PatientId,
  3266. AdminUserId: adminUserInfo.AdminUser.Id,
  3267. Module: 3,
  3268. ErrLog: string(byterequest),
  3269. Status: 1,
  3270. Ctime: time.Now().Unix(),
  3271. Mtime: 0,
  3272. Source: "核对医嘱",
  3273. RecordDate: exceAdvice.AdviceDate,
  3274. }
  3275. service.CreateDoctorAdviceLog(adviceLog)
  3276. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3277. redis := service.RedisClient()
  3278. //清空key 值
  3279. redis.Set(key, "", time.Second)
  3280. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3281. redis.Set(keyTwo, "", time.Second)
  3282. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3283. redis.Set(keyThree, "", time.Second)
  3284. recordDate := theTime.Format("2006-01-02")
  3285. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3286. redis.Set(keyFour, "", time.Second)
  3287. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3288. redis.Set(keyFive, "", time.Second)
  3289. } else {
  3290. err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
  3291. //记录日志
  3292. byterequest, _ := json.Marshal(exceAdvice)
  3293. adviceLog := models.XtDoctorAdviceLog{
  3294. UserOrgId: exceAdvice.UserOrgId,
  3295. PatientId: exceAdvice.PatientId,
  3296. AdminUserId: adminUserInfo.AdminUser.Id,
  3297. Module: 3,
  3298. ErrLog: string(byterequest),
  3299. Status: 1,
  3300. Ctime: time.Now().Unix(),
  3301. Mtime: 0,
  3302. Source: "核对医嘱",
  3303. RecordDate: exceAdvice.AdviceDate,
  3304. }
  3305. service.CreateDoctorAdviceLog(adviceLog)
  3306. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3307. redis := service.RedisClient()
  3308. //清空key 值
  3309. redis.Set(key, "", time.Second)
  3310. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3311. redis.Set(keyTwo, "", time.Second)
  3312. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3313. redis.Set(keyThree, "", time.Second)
  3314. recordDate := theTime.Format("2006-01-02")
  3315. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3316. redis.Set(keyFour, "", time.Second)
  3317. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3318. redis.Set(keyFive, "", time.Second)
  3319. }
  3320. if err != nil {
  3321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3322. return
  3323. }
  3324. // advice.ExecutionStaff = executionStaff
  3325. // advice.ExecutionTime = theTime.Unix()
  3326. advice.Checker = checker
  3327. advice.CheckTime = theTime.Unix()
  3328. c.ServeSuccessJSON(map[string]interface{}{
  3329. "msg": "ok",
  3330. "advice": advice,
  3331. })
  3332. return
  3333. } else {
  3334. if id <= 0 || patient <= 0 {
  3335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3336. return
  3337. }
  3338. adminUserInfo := c.GetAdminUserInfo()
  3339. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3340. if advice.ID == 0 || advice.PatientId != patient {
  3341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3342. return
  3343. }
  3344. if advice.CheckState == 1 {
  3345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  3346. return
  3347. }
  3348. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  3349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3350. return
  3351. }
  3352. checker := adminUserInfo.AdminUser.Id
  3353. theTime := time.Now()
  3354. if advice.ExecutionTime > theTime.Unix() {
  3355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  3356. return
  3357. }
  3358. exceAdvice := models.HisDoctorAdviceInfo{
  3359. Checker: checker,
  3360. CheckTime: theTime.Unix(),
  3361. UpdatedTime: time.Now().Unix(),
  3362. }
  3363. var err error
  3364. if advice.ParentId > 0 {
  3365. err = service.CheckHisDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  3366. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3367. redis := service.RedisClient()
  3368. //清空key 值
  3369. redis.Set(key, "", time.Second)
  3370. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3371. redis.Set(keyTwo, "", time.Second)
  3372. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3373. redis.Set(keyThree, "", time.Second)
  3374. recordDate := theTime.Format("2006-01-02")
  3375. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3376. redis.Set(keyFour, "", time.Second)
  3377. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3378. redis.Set(keyFive, "", time.Second)
  3379. } else {
  3380. err = service.CheckHisDoctorAdviceById(&exceAdvice, id, patient)
  3381. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3382. redis := service.RedisClient()
  3383. //清空key 值
  3384. redis.Set(key, "", time.Second)
  3385. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3386. redis.Set(keyTwo, "", time.Second)
  3387. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3388. redis.Set(keyThree, "", time.Second)
  3389. recordDate := theTime.Format("2006-01-02")
  3390. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3391. redis.Set(keyFour, "", time.Second)
  3392. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3393. redis.Set(keyFive, "", time.Second)
  3394. }
  3395. if err != nil {
  3396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3397. return
  3398. }
  3399. // advice.ExecutionStaff = executionStaff
  3400. // advice.ExecutionTime = theTime.Unix()
  3401. advice.Checker = checker
  3402. advice.CheckTime = theTime.Unix()
  3403. c.ServeSuccessJSON(map[string]interface{}{
  3404. "msg": "ok",
  3405. "advice": advice,
  3406. })
  3407. return
  3408. }
  3409. }
  3410. func (c *PatientApiController) UpdateDoctorAdvice() {
  3411. patient, _ := c.GetInt64("patient", 0)
  3412. id, _ := c.GetInt64("id", 0)
  3413. if id <= 0 || patient <= 0 {
  3414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3415. return
  3416. }
  3417. adminUserInfo := c.GetAdminUserInfo()
  3418. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3419. if advice.ID == 0 || advice.PatientId != patient {
  3420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3421. return
  3422. }
  3423. //if advice.AdviceType == 1 {
  3424. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
  3425. // return
  3426. //}
  3427. if adminUserInfo.CurrentOrgId != 10612 && adminUserInfo.CurrentOrgId != 10460 {
  3428. if advice.StopState == 1 || advice.ExecutionState == 1 {
  3429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3430. return
  3431. }
  3432. }
  3433. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3434. //if appRole.UserType == 3 {
  3435. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3436. // if getPermissionErr != nil {
  3437. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3438. // return
  3439. // } else if headNursePermission == nil {
  3440. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3441. // return
  3442. // }
  3443. //}
  3444. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3445. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
  3446. // return
  3447. //}
  3448. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  3449. if code > 0 {
  3450. c.ServeFailJSONWithSGJErrorCode(code)
  3451. return
  3452. }
  3453. advice.UpdatedTime = time.Now().Unix()
  3454. advice.Modifier = adminUserInfo.AdminUser.Id
  3455. // 查询信息规挡的设置天数
  3456. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3457. if infor.ID > 0 && infor.WeekDay > 0 {
  3458. var cha_time int64
  3459. timeNowStr := time.Now().Format("2006-01-02")
  3460. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3461. //今日的日期减去设置的日期
  3462. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3463. if cha_time >= advice.AdviceDate {
  3464. //查询审核是否允许
  3465. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3466. //申请状态不允许的情况 拒绝修改
  3467. if infor.ApplicationStatus != 1 {
  3468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3469. return
  3470. }
  3471. }
  3472. }
  3473. err := service.UpdateDoctorAdvice(&advice)
  3474. //记录日志
  3475. byterequest, _ := json.Marshal(advice)
  3476. doctorAdviceLog := models.XtDoctorAdviceLog{
  3477. UserOrgId: advice.UserOrgId,
  3478. PatientId: advice.PatientId,
  3479. AdminUserId: adminUserInfo.AdminUser.Id,
  3480. Module: 1,
  3481. ErrLog: string(byterequest),
  3482. Status: 1,
  3483. Ctime: time.Now().Unix(),
  3484. Mtime: 0,
  3485. Source: "电脑端修改医嘱",
  3486. RecordDate: advice.AdviceDate,
  3487. }
  3488. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3489. redis := service.RedisClient()
  3490. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3491. redis.Set(key, "", time.Second)
  3492. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3493. redis.Set(keyOne, "", time.Second)
  3494. defer redis.Close()
  3495. if err != nil {
  3496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3497. return
  3498. }
  3499. c.ServeSuccessJSON(map[string]interface{}{
  3500. "msg": "ok",
  3501. "advice": advice,
  3502. })
  3503. return
  3504. }
  3505. func (c *PatientApiController) StopGroupAdvice() {
  3506. groupNo, _ := c.GetInt64("groupno", 0)
  3507. if groupNo <= 0 {
  3508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3509. return
  3510. }
  3511. adminUserInfo := c.GetAdminUserInfo()
  3512. advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
  3513. if advice.ID == 0 {
  3514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3515. return
  3516. }
  3517. if advice.StopState == 1 || advice.ExecutionState == 1 {
  3518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3519. return
  3520. }
  3521. dataBody := make(map[string]interface{}, 0)
  3522. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3523. if err != nil {
  3524. utils.ErrorLog(err.Error())
  3525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3526. return
  3527. }
  3528. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  3529. utils.ErrorLog("stop_time")
  3530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3531. return
  3532. }
  3533. stopTime, _ := dataBody["stop_time"].(string)
  3534. if len(stopTime) == 0 {
  3535. utils.ErrorLog("len(stop_time) == 0")
  3536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3537. return
  3538. }
  3539. timeLayout := "2006-01-02"
  3540. loc, _ := time.LoadLocation("Local")
  3541. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  3542. if err != nil {
  3543. utils.ErrorLog(err.Error())
  3544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3545. return
  3546. }
  3547. advice.StopTime = theTime.Unix()
  3548. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  3549. stopReason, _ := dataBody["stop_reason"].(string)
  3550. advice.StopReason = stopReason
  3551. }
  3552. advice.UpdatedTime = time.Now().Unix()
  3553. advice.StopDoctor = adminUserInfo.AdminUser.Id
  3554. advice.StopState = 1
  3555. err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
  3556. if err != nil {
  3557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  3558. return
  3559. }
  3560. c.ServeSuccessJSON(map[string]interface{}{
  3561. "msg": "ok",
  3562. })
  3563. return
  3564. }
  3565. func (c *PatientApiController) StopDoctorAdvice() {
  3566. id, _ := c.GetInt64("id", 0)
  3567. if id <= 0 {
  3568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3569. return
  3570. }
  3571. adminUserInfo := c.GetAdminUserInfo()
  3572. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3573. //
  3574. //if appRole.UserType == 3 {
  3575. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3576. // if getPermissionErr != nil {
  3577. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3578. // return
  3579. // } else if headNursePermission == nil {
  3580. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3581. // return
  3582. // }
  3583. //}
  3584. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3585. if advice.ID == 0 {
  3586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3587. return
  3588. }
  3589. if advice.StopState == 1 || advice.ExecutionState == 1 {
  3590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3591. return
  3592. }
  3593. dataBody := make(map[string]interface{}, 0)
  3594. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3595. if err != nil {
  3596. utils.ErrorLog(err.Error())
  3597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3598. return
  3599. }
  3600. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  3601. utils.ErrorLog("stop_time")
  3602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3603. return
  3604. }
  3605. stopTime, _ := dataBody["stop_time"].(string)
  3606. if len(stopTime) == 0 {
  3607. utils.ErrorLog("len(stop_time) == 0")
  3608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3609. return
  3610. }
  3611. timeLayout := "2006-01-02"
  3612. loc, _ := time.LoadLocation("Local")
  3613. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  3614. if err != nil {
  3615. utils.ErrorLog(err.Error())
  3616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3617. return
  3618. }
  3619. advice.StopTime = theTime.Unix()
  3620. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  3621. stopReason, _ := dataBody["stop_reason"].(string)
  3622. advice.StopReason = stopReason
  3623. }
  3624. advice.UpdatedTime = time.Now().Unix()
  3625. advice.StopDoctor = adminUserInfo.AdminUser.Id
  3626. advice.StopState = 1
  3627. err = service.StopDoctorAdvice(&advice)
  3628. if err != nil {
  3629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  3630. return
  3631. }
  3632. c.ServeSuccessJSON(map[string]interface{}{
  3633. "msg": "ok",
  3634. "advice": advice,
  3635. })
  3636. return
  3637. }
  3638. func (c *PatientApiController) DeleteDoctorAdvice() {
  3639. id, _ := c.GetInt64("id", 0)
  3640. if id <= 0 {
  3641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3642. return
  3643. }
  3644. adminUserInfo := c.GetAdminUserInfo()
  3645. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3646. if advice.ID == 0 {
  3647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3648. return
  3649. }
  3650. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3651. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3652. // return
  3653. //}
  3654. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3655. //
  3656. //if appRole.UserType == 3 {
  3657. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3658. // if getPermissionErr != nil {
  3659. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3660. // return
  3661. // } else if headNursePermission == nil {
  3662. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3663. // return
  3664. // }
  3665. //}
  3666. advice.UpdatedTime = time.Now().Unix()
  3667. advice.Status = 0
  3668. advice.Modifier = adminUserInfo.AdminUser.Id
  3669. // 查询信息规挡的设置天数
  3670. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3671. if infor.ID > 0 && infor.WeekDay > 0 {
  3672. var cha_time int64
  3673. timeNowStr := time.Now().Format("2006-01-02")
  3674. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3675. //今日的日期减去设置的日期
  3676. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3677. if cha_time >= advice.AdviceDate {
  3678. //查询审核是否允许
  3679. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3680. //申请状态不允许的情况 拒绝修改
  3681. if infor.ApplicationStatus != 1 {
  3682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3683. return
  3684. }
  3685. }
  3686. }
  3687. //自备药
  3688. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
  3689. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  3690. //查询库存是否是自备药
  3691. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  3692. if selfBasedrug.IsSelfDrug == 1 {
  3693. creater := adminUserInfo.AdminUser.Id
  3694. //退库
  3695. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  3696. }
  3697. }
  3698. err := service.DeleteDoctorAdvice(&advice)
  3699. //记录日志
  3700. byterequest, _ := json.Marshal(advice)
  3701. doctorAdviceLog := models.XtDoctorAdviceLog{
  3702. UserOrgId: advice.UserOrgId,
  3703. PatientId: advice.PatientId,
  3704. AdminUserId: adminUserInfo.AdminUser.Id,
  3705. Module: 4,
  3706. ErrLog: string(byterequest),
  3707. Status: 1,
  3708. Ctime: time.Now().Unix(),
  3709. Mtime: 0,
  3710. Source: "电脑端删除医嘱",
  3711. RecordDate: advice.RecordDate,
  3712. }
  3713. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3714. redis := service.RedisClient()
  3715. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3716. redis.Set(keyOne, "", time.Second)
  3717. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3718. redis.Set(key, "", time.Second)
  3719. redis.Close()
  3720. if err != nil {
  3721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3722. return
  3723. }
  3724. c.ServeSuccessJSON(map[string]interface{}{
  3725. "msg": "ok",
  3726. })
  3727. return
  3728. }
  3729. func (c *PatientApiController) DeleteGroupAdvice() {
  3730. groupNo, _ := c.GetInt64("groupno", 0)
  3731. if groupNo <= 0 {
  3732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3733. return
  3734. }
  3735. adminUserInfo := c.GetAdminUserInfo()
  3736. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  3737. if advice.ID == 0 {
  3738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3739. return
  3740. }
  3741. //自备药
  3742. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
  3743. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  3744. //查询库存是否是自备药
  3745. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  3746. if selfBasedrug.IsSelfDrug == 1 {
  3747. creater := adminUserInfo.AdminUser.Id
  3748. //退库
  3749. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  3750. }
  3751. }
  3752. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3753. //if appRole.UserType == 3 {
  3754. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3755. // if getPermissionErr != nil {
  3756. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3757. // return
  3758. // } else if headNursePermission == nil {
  3759. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3760. // return
  3761. // }
  3762. //}
  3763. // 查询信息规挡的设置天数
  3764. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3765. if infor.ID > 0 && infor.WeekDay > 0 {
  3766. var cha_time int64
  3767. timeNowStr := time.Now().Format("2006-01-02")
  3768. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3769. //今日的日期减去设置的日期
  3770. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3771. if cha_time >= advice.AdviceDate {
  3772. //查询审核是否允许
  3773. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3774. //申请状态不允许的情况 拒绝修改
  3775. if infor.ApplicationStatus != 1 {
  3776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3777. return
  3778. }
  3779. }
  3780. }
  3781. err := service.DeleteGroupAdviceOne(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
  3782. byterequest, _ := json.Marshal(advice)
  3783. doctorAdviceLog := models.XtDoctorAdviceLog{
  3784. UserOrgId: advice.UserOrgId,
  3785. PatientId: advice.PatientId,
  3786. AdminUserId: adminUserInfo.AdminUser.Id,
  3787. Module: 4,
  3788. ErrLog: string(byterequest),
  3789. Status: 1,
  3790. Ctime: time.Now().Unix(),
  3791. Mtime: 0,
  3792. Source: "电脑端批量删除医嘱",
  3793. RecordDate: advice.RecordDate,
  3794. }
  3795. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3796. key := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3797. redis := service.RedisClient()
  3798. redis.Set(key, "", time.Second)
  3799. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3800. redis.Set(keyOne, "", time.Second)
  3801. defer redis.Close()
  3802. if err != nil {
  3803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3804. return
  3805. }
  3806. c.ServeSuccessJSON(map[string]interface{}{
  3807. "msg": "ok",
  3808. })
  3809. return
  3810. }
  3811. // GetDoctorAdvices 医嘱列表
  3812. func (c *PatientApiController) GetDoctorAdvices() {
  3813. id, _ := c.GetInt64("id", 0)
  3814. adviceType, _ := c.GetInt64("advice_type", 0)
  3815. stopType, _ := c.GetInt64("stop_state", 0)
  3816. startTime := c.GetString("start_time", "")
  3817. endTime := c.GetString("end_time", "")
  3818. keywords := c.GetString("keywords", "")
  3819. page, _ := c.GetInt64("page")
  3820. limit, _ := c.GetInt64("limit")
  3821. adminUserInfo := c.GetAdminUserInfo()
  3822. delivery_way_one := c.GetString("delivery_way_one", "")
  3823. operatorIDs := make([]int64, 0)
  3824. timeLayout := "2006-01-02"
  3825. loc, _ := time.LoadLocation("Local")
  3826. var theStartTIme int64
  3827. if len(startTime) > 0 {
  3828. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3829. if err != nil {
  3830. utils.ErrorLog(err.Error())
  3831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3832. return
  3833. }
  3834. theStartTIme = theTime.Unix()
  3835. }
  3836. var theEndtTIme int64
  3837. if len(endTime) > 0 {
  3838. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3839. if err != nil {
  3840. utils.ErrorLog(err.Error())
  3841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3842. return
  3843. }
  3844. theEndtTIme = theTime.Unix()
  3845. }
  3846. hisconfig, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3847. if hisconfig.IsOpen == 1 {
  3848. advices, total, _ := service.GetDoctorAdviceListThree(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit, delivery_way_one)
  3849. advicestwo, _, _ := service.GetDoctorAdviceListFour(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page, delivery_way_one)
  3850. if len(advices) > 0 {
  3851. for _, item := range advices {
  3852. if item.AdviceDoctor > 0 {
  3853. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3854. }
  3855. if item.ExecutionStaff > 0 {
  3856. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3857. }
  3858. if item.Checker > 0 {
  3859. operatorIDs = append(operatorIDs, item.Checker)
  3860. }
  3861. if item.StopDoctor > 0 {
  3862. operatorIDs = append(operatorIDs, item.StopDoctor)
  3863. }
  3864. }
  3865. }
  3866. //相关操作对应的操作人
  3867. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3868. //获取长期医嘱
  3869. longAdvice, _, _ := service.GetLongDoctorAdviceList(adminUserInfo.CurrentOrgId, id, 1, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3870. c.ServeSuccessJSON(map[string]interface{}{
  3871. "advices": advices,
  3872. "operators": operators,
  3873. "total": total,
  3874. "advicetwo": advicestwo,
  3875. "longAdvice": longAdvice,
  3876. "is_open": hisconfig.IsOpen,
  3877. })
  3878. return
  3879. } else {
  3880. advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit, delivery_way_one)
  3881. advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page, delivery_way_one)
  3882. if len(advices) > 0 {
  3883. for _, item := range advices {
  3884. if item.AdviceDoctor > 0 {
  3885. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3886. }
  3887. if item.ExecutionStaff > 0 {
  3888. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3889. }
  3890. if item.Checker > 0 {
  3891. operatorIDs = append(operatorIDs, item.Checker)
  3892. }
  3893. if item.StopDoctor > 0 {
  3894. operatorIDs = append(operatorIDs, item.StopDoctor)
  3895. }
  3896. }
  3897. }
  3898. //相关操作对应的操作人
  3899. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3900. c.ServeSuccessJSON(map[string]interface{}{
  3901. "advices": advices,
  3902. "operators": operators,
  3903. "total": total,
  3904. "advicetwo": advicestwo,
  3905. "is_open": hisconfig.IsOpen,
  3906. })
  3907. return
  3908. }
  3909. }
  3910. func (c *PatientApiController) GetPatientSchedules() {
  3911. id, _ := c.GetInt64("id", 0)
  3912. if id <= 0 {
  3913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3914. return
  3915. }
  3916. adminUserInfo := c.GetAdminUserInfo()
  3917. todayTime := time.Now().Format("2006-01-02")
  3918. timeLayout := "2006-01-02 15:04:05"
  3919. loc, _ := time.LoadLocation("Local")
  3920. var theStartTime int64
  3921. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  3922. theStartTime = theTime.Unix()
  3923. schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
  3924. if len(schedules) > 0 {
  3925. for index, item := range schedules {
  3926. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  3927. schedules[index].Week = int64(week)
  3928. }
  3929. }
  3930. c.ServeSuccessJSON(map[string]interface{}{
  3931. "schedules": schedules,
  3932. })
  3933. return
  3934. }
  3935. func (c *PatientApiController) GetPatientDialysisRecords() {
  3936. patientID, _ := c.GetInt64("patient_id", 0)
  3937. page, _ := c.GetInt64("page", 0)
  3938. limit, _ := c.GetInt64("limit", 0)
  3939. startTime := c.GetString("start_time", "")
  3940. endTime := c.GetString("end_time", "")
  3941. mode_id, _ := c.GetInt64("mode_id", 0)
  3942. if page <= 0 {
  3943. page = 1
  3944. }
  3945. if limit <= 0 {
  3946. limit = 10
  3947. }
  3948. if patientID <= 0 {
  3949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3950. return
  3951. }
  3952. timeLayout := "2006-01-02"
  3953. loc, _ := time.LoadLocation("Local")
  3954. var theStartTIme int64
  3955. if len(startTime) > 0 {
  3956. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3957. if err != nil {
  3958. theStartTIme = 0
  3959. }
  3960. theStartTIme = theTime.Unix()
  3961. }
  3962. var theEndtTIme int64
  3963. if len(endTime) > 0 {
  3964. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3965. if err != nil {
  3966. theEndtTIme = 0
  3967. }
  3968. theEndtTIme = theTime.Unix()
  3969. }
  3970. adminInfo := c.GetAdminUserInfo()
  3971. records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  3972. if len(records) == 0 {
  3973. list, _ := service.GetAllDialysisOrder(patientID)
  3974. for _, item := range list {
  3975. schedule, _ := service.GetLastScheduleByUserOrg(item.PatientId, item.DialysisDate, adminInfo.CurrentOrgId, item.BedId, item.ZoneId, item.SchedualType)
  3976. service.UpdateScheduleByOrder(item.PatientId, item.DialysisDate, adminInfo.CurrentOrgId, item.BedId, item.ZoneId, item.SchedualType, schedule.ID)
  3977. }
  3978. }
  3979. c.ServeSuccessJSON(map[string]interface{}{
  3980. "total": total,
  3981. "records": records,
  3982. })
  3983. return
  3984. }
  3985. func (c *PatientApiController) ProEducation() {
  3986. patientID, _ := c.GetInt64("patient_id", 0)
  3987. page, _ := c.GetInt64("page", 0)
  3988. limit, _ := c.GetInt64("limit", 0)
  3989. startTime := c.GetString("start_time", "")
  3990. endTime := c.GetString("end_time", "")
  3991. if page <= 0 {
  3992. page = 1
  3993. }
  3994. if limit <= 0 {
  3995. limit = 10
  3996. }
  3997. if patientID <= 0 {
  3998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3999. return
  4000. }
  4001. timeLayout := "2006-01-02"
  4002. loc, _ := time.LoadLocation("Local")
  4003. var theStartTIme int64
  4004. if len(startTime) > 0 {
  4005. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4006. if err != nil {
  4007. theStartTIme = 0
  4008. }
  4009. theStartTIme = theTime.Unix()
  4010. }
  4011. var theEndtTIme int64
  4012. if len(endTime) > 0 {
  4013. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4014. if err != nil {
  4015. theEndtTIme = 0
  4016. }
  4017. theEndtTIme = theTime.Unix()
  4018. }
  4019. adminInfo := c.GetAdminUserInfo()
  4020. edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
  4021. c.ServeSuccessJSON(map[string]interface{}{
  4022. "total": total,
  4023. "edus": edus,
  4024. })
  4025. return
  4026. }
  4027. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  4028. dataBody := make(map[string]interface{}, 0)
  4029. err := json.Unmarshal(data, &dataBody)
  4030. if err != nil {
  4031. utils.ErrorLog(err.Error())
  4032. code = enums.ErrorCodeParamWrong
  4033. return
  4034. }
  4035. timeLayout := "2006-01-02"
  4036. loc, _ := time.LoadLocation("Local")
  4037. isChild := false
  4038. if action == "create" {
  4039. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4040. utils.ErrorLog("advice_type")
  4041. code = enums.ErrorCodeParamWrong
  4042. return
  4043. }
  4044. adviceType := int64(dataBody["advice_type"].(float64))
  4045. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  4046. utils.ErrorLog("advice_type != 1&&2")
  4047. code = enums.ErrorCodeParamWrong
  4048. return
  4049. }
  4050. advice.AdviceType = adviceType
  4051. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4052. utils.ErrorLog("advice_date")
  4053. code = enums.ErrorCodeParamWrong
  4054. return
  4055. }
  4056. adviceDate, _ := dataBody["advice_date"].(string)
  4057. if len(adviceDate) == 0 {
  4058. utils.ErrorLog("len(adviceDate) == 0")
  4059. code = enums.ErrorCodeParamWrong
  4060. return
  4061. }
  4062. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4063. if err != nil {
  4064. utils.ErrorLog(err.Error())
  4065. code = enums.ErrorCodeParamWrong
  4066. return
  4067. }
  4068. advice.AdviceDate = theTime.Unix()
  4069. advice.RecordDate = theTime.Unix()
  4070. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  4071. parentId := int64(dataBody["parent_id"].(float64))
  4072. advice.ParentId = parentId
  4073. if parentId > 0 {
  4074. isChild = true
  4075. }
  4076. }
  4077. }
  4078. if !isChild {
  4079. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4080. utils.ErrorLog("start_time")
  4081. code = enums.ErrorCodeParamWrong
  4082. return
  4083. }
  4084. startTime, _ := dataBody["start_time"].(string)
  4085. if len(startTime) == 0 {
  4086. utils.ErrorLog("len(start_time) == 0")
  4087. code = enums.ErrorCodeParamWrong
  4088. return
  4089. }
  4090. theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  4091. if err != nil {
  4092. utils.ErrorLog(err.Error())
  4093. code = enums.ErrorCodeParamWrong
  4094. return
  4095. }
  4096. advice.StartTime = theTime.Unix()
  4097. // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
  4098. // utils.ErrorLog("advice_doctor")
  4099. // code = enums.ErrorCodeParamWrong
  4100. // return
  4101. // }
  4102. // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
  4103. // if adviceDoctor <= 0 {
  4104. // utils.ErrorLog("advice_doctor <=0")
  4105. // code = enums.ErrorCodeParamWrong
  4106. // return
  4107. // }
  4108. // advice.AdviceDoctor = adviceDoctor
  4109. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  4110. deliveryWay, _ := dataBody["delivery_way"].(string)
  4111. advice.DeliveryWay = deliveryWay
  4112. }
  4113. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  4114. executionFrequency, _ := dataBody["execution_frequency"].(string)
  4115. advice.ExecutionFrequency = executionFrequency
  4116. }
  4117. if advice.AdviceType == 1 && advice.ParentId == 0 {
  4118. if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
  4119. frequency_type := int64(dataBody["frequency_type"].(float64))
  4120. advice.FrequencyType = frequency_type
  4121. }
  4122. if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
  4123. day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
  4124. advice.DayCount = day_count
  4125. }
  4126. if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
  4127. week_day, _ := dataBody["week_days"].(string)
  4128. advice.WeekDay = week_day
  4129. }
  4130. }
  4131. }
  4132. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  4133. utils.ErrorLog("advice_name")
  4134. code = enums.ErrorCodeParamWrong
  4135. return
  4136. }
  4137. adviceName, _ := dataBody["advice_name"].(string)
  4138. if len(adviceName) == 0 {
  4139. utils.ErrorLog("len(advice_name) == 0")
  4140. code = enums.ErrorCodeParamWrong
  4141. return
  4142. }
  4143. advice.AdviceName = adviceName
  4144. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  4145. adviceDsc, _ := dataBody["advice_desc"].(string)
  4146. advice.AdviceDesc = adviceDsc
  4147. }
  4148. if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
  4149. dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
  4150. advice.DialysisOrderId = int64(dialysisOrderId)
  4151. }
  4152. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  4153. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  4154. advice.SingleDose = singleDose
  4155. }
  4156. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "float64" {
  4157. singleDose := dataBody["single_dose"].(float64)
  4158. advice.SingleDose = singleDose
  4159. }
  4160. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  4161. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  4162. advice.SingleDoseUnit = singleDoseUnit
  4163. }
  4164. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "float64" {
  4165. tmp := dataBody["single_dose_unit"].(float64)
  4166. singleDoseUnit := service.TypeConversion(tmp)
  4167. advice.SingleDoseUnit = singleDoseUnit
  4168. }
  4169. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  4170. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  4171. advice.DrugSpec = drugSpec
  4172. }
  4173. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  4174. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  4175. advice.DrugSpecUnit = drugSpecUnit
  4176. }
  4177. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  4178. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  4179. advice.PrescribingNumber = prescribingNumber
  4180. }
  4181. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "float64" {
  4182. prescribingNumber := dataBody["prescribing_number"].(float64)
  4183. advice.PrescribingNumber = prescribingNumber
  4184. }
  4185. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  4186. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  4187. advice.PrescribingNumberUnit = prescribingNumberUnit
  4188. }
  4189. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4190. remark, _ := dataBody["remark"].(string)
  4191. advice.Remark = remark
  4192. }
  4193. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "string" {
  4194. drug_id, _ := dataBody["drug_id"].(string)
  4195. tmpDrugId, _ := strconv.ParseInt(drug_id, 10, 64)
  4196. advice.DrugId = tmpDrugId
  4197. }
  4198. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  4199. drug_id, _ := dataBody["drug_id"].(float64)
  4200. advice.DrugId = int64(drug_id)
  4201. }
  4202. if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  4203. drug_name_id, _ := dataBody["drug_name_id"].(float64)
  4204. advice.DrugNameId = int64(drug_name_id)
  4205. }
  4206. if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
  4207. way, _ := dataBody["way"].(float64)
  4208. advice.Way = int64(way)
  4209. }
  4210. if dataBody["push_start_time"] != nil && reflect.TypeOf(dataBody["push_start_time"]).String() == "string" {
  4211. push_start_time, _ := dataBody["push_start_time"].(string)
  4212. var startTime int64
  4213. if len(push_start_time) > 0 {
  4214. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
  4215. startTime = theTime.Unix()
  4216. }
  4217. advice.PushStartTime = startTime
  4218. }
  4219. return
  4220. }
  4221. func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
  4222. dataBody := make(map[string]interface{}, 0)
  4223. err := json.Unmarshal(data, &dataBody)
  4224. utils.InfoLog(string(data))
  4225. if err != nil {
  4226. utils.ErrorLog(err.Error())
  4227. code = enums.ErrorCodeParamWrong
  4228. return
  4229. }
  4230. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  4231. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  4232. solution.DialysisDuration = dialysisDuration
  4233. }
  4234. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  4235. replacementWay := int64(dataBody["replacement_way"].(float64))
  4236. solution.ReplacementWay = replacementWay
  4237. }
  4238. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  4239. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  4240. solution.BloodFlowVolume = bloodFlowVolume
  4241. }
  4242. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  4243. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  4244. solution.HemodialysisMachine = hemodialysisMachine
  4245. }
  4246. if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
  4247. bloodFilter := int64(dataBody["blood_filter"].(float64))
  4248. solution.BloodFilter = bloodFilter
  4249. }
  4250. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  4251. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  4252. solution.PerfusionApparatus = perfusionApparatus
  4253. }
  4254. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  4255. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  4256. solution.DialysateFlow = dialysateFlow
  4257. }
  4258. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  4259. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  4260. solution.Kalium = kalium
  4261. }
  4262. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  4263. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  4264. solution.Sodium = sodium
  4265. }
  4266. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  4267. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  4268. solution.Calcium = calcium
  4269. }
  4270. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  4271. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  4272. solution.Bicarbonate = bicarbonate
  4273. }
  4274. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  4275. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  4276. solution.Anticoagulant = anticoagulant
  4277. }
  4278. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  4279. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  4280. solution.AnticoagulantShouji = anticoagulantShouji
  4281. }
  4282. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  4283. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  4284. solution.AnticoagulantWeichi = anticoagulantWeichi
  4285. }
  4286. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  4287. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  4288. solution.AnticoagulantZongliang = anticoagulantZongliang
  4289. }
  4290. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  4291. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  4292. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  4293. }
  4294. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  4295. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  4296. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  4297. }
  4298. return
  4299. }
  4300. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  4301. dataBody := make(map[string]interface{}, 0)
  4302. err := json.Unmarshal(data, &dataBody)
  4303. utils.InfoLog(string(data))
  4304. if err != nil {
  4305. utils.ErrorLog(err.Error())
  4306. code = enums.ErrorCodeParamWrong
  4307. return
  4308. }
  4309. if method == "create" {
  4310. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  4311. utils.ErrorLog("mode")
  4312. code = enums.ErrorCodeParamWrong
  4313. return
  4314. }
  4315. mode := int64(dataBody["mode"].(float64))
  4316. if mode <= 0 {
  4317. utils.ErrorLog("mode <= 0")
  4318. code = enums.ErrorCodeParamWrong
  4319. return
  4320. }
  4321. solution.ModeId = mode
  4322. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  4323. utils.ErrorLog("mode_name")
  4324. code = enums.ErrorCodeParamWrong
  4325. return
  4326. }
  4327. modeName, _ := dataBody["mode_name"].(string)
  4328. if len(modeName) == 0 {
  4329. utils.ErrorLog("len(mode_name) == 0")
  4330. code = enums.ErrorCodeParamWrong
  4331. return
  4332. }
  4333. solution.ModeName = modeName
  4334. solution.Name = modeName
  4335. }
  4336. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  4337. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  4338. solution.DialysisDuration = dialysisDuration
  4339. }
  4340. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  4341. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  4342. solution.TargetUltrafiltration = targetUltrafiltration
  4343. }
  4344. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  4345. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  4346. solution.DialysateFormulation = dialysateFormulation
  4347. }
  4348. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  4349. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  4350. solution.DialysisDurationHour = int64(dialysisDurationHour)
  4351. }
  4352. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  4353. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  4354. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  4355. }
  4356. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  4357. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  4358. solution.HemodialysisMachine = hemodialysisMachine
  4359. }
  4360. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  4361. dialyzer := int64(dataBody["dialyzer"].(float64))
  4362. solution.Dialyzer = dialyzer
  4363. }
  4364. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  4365. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  4366. solution.PerfusionApparatus = perfusionApparatus
  4367. }
  4368. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  4369. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  4370. solution.BloodFlowVolume = bloodFlowVolume
  4371. }
  4372. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  4373. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  4374. solution.Dewater = dewater
  4375. }
  4376. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  4377. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  4378. solution.DisplaceLiqui = displaceLiqui
  4379. }
  4380. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  4381. replacementWay := int64(dataBody["replacement_way"].(float64))
  4382. solution.ReplacementWay = replacementWay
  4383. }
  4384. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  4385. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  4386. solution.Anticoagulant = anticoagulant
  4387. }
  4388. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  4389. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  4390. solution.AnticoagulantShouji = anticoagulantShouji
  4391. }
  4392. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  4393. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  4394. solution.AnticoagulantWeichi = anticoagulantWeichi
  4395. }
  4396. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  4397. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  4398. solution.AnticoagulantZongliang = anticoagulantZongliang
  4399. }
  4400. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  4401. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  4402. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  4403. }
  4404. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  4405. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  4406. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  4407. }
  4408. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  4409. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  4410. solution.Kalium = kalium
  4411. }
  4412. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  4413. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  4414. solution.Sodium = sodium
  4415. }
  4416. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  4417. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  4418. solution.Calcium = calcium
  4419. }
  4420. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  4421. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  4422. solution.Bicarbonate = bicarbonate
  4423. }
  4424. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  4425. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  4426. solution.Glucose = glucose
  4427. }
  4428. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  4429. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  4430. // solution.DryWeight = dryWeight
  4431. // }
  4432. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  4433. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  4434. solution.DialysateFlow = dialysateFlow
  4435. }
  4436. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  4437. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  4438. solution.DialysateTemperature = dialysateTemperature
  4439. }
  4440. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  4441. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  4442. solution.Conductivity = conductivity
  4443. }
  4444. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  4445. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  4446. solution.ReplacementTotal = replacementTotal
  4447. }
  4448. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  4449. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  4450. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  4451. }
  4452. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  4453. body_fluid := int64(dataBody["body_fluid"].(float64))
  4454. solution.BodyFluid = body_fluid
  4455. }
  4456. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  4457. body_fluid_other := dataBody["body_fluid_other"].(string)
  4458. solution.BodyFluidOther = body_fluid_other
  4459. }
  4460. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  4461. special_medicine := int64(dataBody["special_medicine"].(float64))
  4462. solution.SpecialMedicine = special_medicine
  4463. }
  4464. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  4465. special_medicine_other := dataBody["special_medicine_other"].(string)
  4466. solution.SpecialMedicineOther = special_medicine_other
  4467. }
  4468. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  4469. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  4470. solution.DisplaceLiquiPart = displace_liqui_part
  4471. }
  4472. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  4473. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  4474. solution.DisplaceLiquiValue = displace_liqui_value
  4475. }
  4476. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  4477. blood_access := int64(dataBody["blood_access"].(float64))
  4478. solution.BloodAccess = blood_access
  4479. }
  4480. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  4481. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  4482. solution.Ultrafiltration = ultrafiltration
  4483. }
  4484. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  4485. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  4486. solution.TargetKtv = target_ktv
  4487. }
  4488. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4489. remark := dataBody["remark"].(string)
  4490. solution.Remark = remark
  4491. }
  4492. if dataBody["hemodialysis_pipelines"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines"]).String() == "string" {
  4493. hemodialysis_pipelines := dataBody["hemodialysis_pipelines"].(string)
  4494. solution.HemodialysisPipelines = hemodialysis_pipelines
  4495. }
  4496. if dataBody["hemodialysis_pipelines_count"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines_count"]).String() == "string" {
  4497. hemodialysis_pipelines_count, _ := strconv.ParseFloat(dataBody["hemodialysis_pipelines_count"].(string), 64)
  4498. solution.HemodialysisPipelinesCount = hemodialysis_pipelines_count
  4499. }
  4500. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  4501. puncture_needle := dataBody["puncture_needle"].(string)
  4502. solution.PunctureNeedle = puncture_needle
  4503. }
  4504. if dataBody["puncture_needle_count"] != nil && reflect.TypeOf(dataBody["puncture_needle_count"]).String() == "string" {
  4505. puncture_needle_count, _ := strconv.ParseFloat(dataBody["puncture_needle_count"].(string), 64)
  4506. solution.PunctureNeedleCount = puncture_needle_count
  4507. }
  4508. if dataBody["epo"] != nil && reflect.TypeOf(dataBody["epo"]).String() == "string" {
  4509. epo := dataBody["epo"].(string)
  4510. solution.Epo = epo
  4511. }
  4512. if dataBody["epo_count"] != nil && reflect.TypeOf(dataBody["epo_count"]).String() == "string" {
  4513. epo_count, _ := strconv.ParseFloat(dataBody["epo_count"].(string), 64)
  4514. solution.EpoCount = epo_count
  4515. }
  4516. if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
  4517. created_time := int64(dataBody["created_time"].(float64))
  4518. solution.CreatedTime = created_time
  4519. }
  4520. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  4521. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  4522. solution.DialysisDialyszers = dialysisDialyszers
  4523. }
  4524. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  4525. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  4526. solution.DialysisIrrigation = dialysisIrrigation
  4527. }
  4528. if dataBody["dialysis_strainer"] != nil && reflect.TypeOf(dataBody["dialysis_strainer"]).String() == "string" {
  4529. dialysis_strainer := dataBody["dialysis_strainer"].(string)
  4530. solution.DialysisStrainer = dialysis_strainer
  4531. }
  4532. if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
  4533. plasmaSeparator := dataBody["plasma_separator"].(string)
  4534. solution.PlasmaSeparator = plasmaSeparator
  4535. }
  4536. if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
  4537. bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
  4538. solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
  4539. }
  4540. if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
  4541. oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
  4542. solution.OxygenUptake = oxygen_uptake
  4543. }
  4544. if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
  4545. oxygen_flow := dataBody["oxygen_flow"].(string)
  4546. solution.OxygenFlow = oxygen_flow
  4547. }
  4548. if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
  4549. oxygen_time := dataBody["oxygen_time"].(string)
  4550. solution.OxygenTime = oxygen_time
  4551. }
  4552. if dataBody["max_ultrafiltration_rate"] != nil && reflect.TypeOf(dataBody["max_ultrafiltration_rate"]).String() == "string" {
  4553. max_ultrafiltration_rate, _ := strconv.ParseFloat(dataBody["max_ultrafiltration_rate"].(string), 64)
  4554. solution.MaxUltrafiltrationRate = max_ultrafiltration_rate
  4555. }
  4556. if dataBody["amylaceum"] != nil && reflect.TypeOf(dataBody["amylaceum"]).String() == "string" {
  4557. amylaceum := dataBody["amylaceum"].(string)
  4558. solution.Amylaceum = amylaceum
  4559. }
  4560. if dataBody["chaptalization"] != nil && reflect.TypeOf(dataBody["chaptalization"]).String() == "string" {
  4561. chaptalization := dataBody["chaptalization"].(string)
  4562. solution.Chaptalization = chaptalization
  4563. }
  4564. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  4565. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  4566. solution.BloodAccessPartId = blood_access_part_id
  4567. }
  4568. return
  4569. }
  4570. func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  4571. dataBody := make(map[string]interface{}, 0)
  4572. err := json.Unmarshal(data, &dataBody)
  4573. utils.InfoLog(string(data))
  4574. if err != nil {
  4575. utils.ErrorLog(err.Error())
  4576. code = enums.ErrorCodeParamWrong
  4577. return
  4578. }
  4579. if method == "create" {
  4580. if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
  4581. utils.ErrorLog("parent_id")
  4582. code = enums.ErrorCodeParamWrong
  4583. return
  4584. }
  4585. parentID := int64(dataBody["parent_id"].(float64))
  4586. if parentID <= 0 {
  4587. utils.ErrorLog("parentID <= 0")
  4588. code = enums.ErrorCodeParamWrong
  4589. return
  4590. }
  4591. solution.ParentId = parentID
  4592. if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
  4593. utils.ErrorLog("sub_name")
  4594. code = enums.ErrorCodeParamWrong
  4595. return
  4596. }
  4597. subName, _ := dataBody["sub_name"].(string)
  4598. if len(subName) == 0 {
  4599. utils.ErrorLog("len(sub_name) == 0")
  4600. code = enums.ErrorCodeParamWrong
  4601. return
  4602. }
  4603. solution.SubName = subName
  4604. }
  4605. if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
  4606. utils.ErrorLog("initiate_mode")
  4607. code = enums.ErrorCodeParamWrong
  4608. return
  4609. }
  4610. initiateMode := int64(dataBody["initiate_mode"].(float64))
  4611. if initiateMode != 1 && initiateMode != 2 {
  4612. utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
  4613. code = enums.ErrorCodeParamWrong
  4614. return
  4615. }
  4616. solution.InitiateMode = initiateMode
  4617. if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  4618. utils.ErrorLog("doctor")
  4619. code = enums.ErrorCodeParamWrong
  4620. return
  4621. }
  4622. doctor := int64(dataBody["doctor"].(float64))
  4623. if doctor <= 0 {
  4624. utils.ErrorLog("doctor <= 0")
  4625. code = enums.ErrorCodeParamWrong
  4626. return
  4627. }
  4628. solution.Doctor = doctor
  4629. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  4630. blood_access_part_id, _ := dataBody["blood_access_part_id"].(string)
  4631. solution.BloodAccessPartId = blood_access_part_id
  4632. }
  4633. return
  4634. }
  4635. func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
  4636. patientBody := make(map[string]interface{}, 0)
  4637. err := json.Unmarshal(data, &patientBody)
  4638. if err != nil {
  4639. utils.ErrorLog(err.Error())
  4640. code = enums.ErrorCodeParamWrong
  4641. return
  4642. }
  4643. if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
  4644. formItem, _ := patientBody["formItem"].([]interface{})
  4645. if len(formItem) > 0 {
  4646. for _, item := range formItem {
  4647. items := item.(map[string]interface{})
  4648. project_name, _ := items["project_name"].(string)
  4649. fmt.Println(project_name)
  4650. range_type := int64(items["range_type"].(float64))
  4651. fmt.Println(range_type)
  4652. project_id := int64(items["project_id"].(float64))
  4653. fmt.Println(project_id)
  4654. item_id := int64(items["item_id"].(float64))
  4655. fmt.Println(item_id)
  4656. item, _ := items["item"].(string)
  4657. fmt.Println(items["item"].(string))
  4658. item_name, _ := items["item_name"].(string)
  4659. fmt.Println(item_name)
  4660. value, _ := items["value"].(string)
  4661. fmt.Println(items["value"].(string))
  4662. var form models.FormItem
  4663. form.ProjectName = project_name
  4664. form.RangeType = range_type
  4665. form.ProjectId = project_id
  4666. form.ItemId = item_id
  4667. form.Item = item
  4668. form.ItemName = item_name
  4669. form.Value = value
  4670. formItems = append(formItems, &form)
  4671. }
  4672. }
  4673. }
  4674. if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
  4675. utils.ErrorLog("avatar")
  4676. code = enums.ErrorCodeParamWrong
  4677. return
  4678. }
  4679. avatar, _ := patientBody["avatar"].(string)
  4680. if len(avatar) == 0 {
  4681. utils.ErrorLog("len(avatar) == 0")
  4682. code = enums.ErrorCodeParamWrong
  4683. return
  4684. }
  4685. patient.Avatar = avatar
  4686. if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
  4687. utils.ErrorLog("name")
  4688. code = enums.ErrorCodeParamWrong
  4689. return
  4690. }
  4691. name, _ := patientBody["name"].(string)
  4692. if len(name) == 0 {
  4693. utils.ErrorLog("len(name) == 0")
  4694. code = enums.ErrorCodeParamWrong
  4695. return
  4696. }
  4697. patient.Name = name
  4698. if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
  4699. alias := patientBody["alias"].(string)
  4700. patient.Alias = alias
  4701. }
  4702. if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
  4703. nation := patientBody["nation"].(string)
  4704. patient.Nation = nation
  4705. }
  4706. if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
  4707. native_place := patientBody["native_place"].(string)
  4708. patient.NativePlace = native_place
  4709. }
  4710. if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
  4711. utils.ErrorLog("idCardNo")
  4712. code = enums.ErrorCodeParamWrong
  4713. return
  4714. }
  4715. idCardNo, _ := patientBody["idCardNo"].(string)
  4716. if len(idCardNo) == 0 {
  4717. utils.ErrorLog("len(idCardNo) == 0")
  4718. code = enums.ErrorCodeParamWrong
  4719. return
  4720. }
  4721. patient.IdCardNo = idCardNo
  4722. patient.PatientType = 1
  4723. if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
  4724. utils.ErrorLog("dialysisNo")
  4725. code = enums.ErrorCodeParamWrong
  4726. return
  4727. }
  4728. dialysisNo, _ := patientBody["dialysisNo"].(string)
  4729. if len(dialysisNo) == 0 {
  4730. utils.ErrorLog("len(dialysisNo) == 0")
  4731. code = enums.ErrorCodeParamWrong
  4732. return
  4733. }
  4734. patient.DialysisNo = dialysisNo
  4735. // }
  4736. if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
  4737. utils.ErrorLog("lapseto")
  4738. code = enums.ErrorCodeParamWrong
  4739. return
  4740. }
  4741. lapseto := int64(patientBody["lapseto"].(float64))
  4742. if lapseto <= 0 {
  4743. utils.ErrorLog("lapseto == 0")
  4744. code = enums.ErrorCodeParamWrong
  4745. return
  4746. }
  4747. patient.Lapseto = lapseto
  4748. if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
  4749. utils.ErrorLog("gender")
  4750. code = enums.ErrorCodeParamWrong
  4751. return
  4752. }
  4753. gender := int64(patientBody["gender"].(float64))
  4754. if gender <= 0 {
  4755. utils.ErrorLog("gender <= 0")
  4756. code = enums.ErrorCodeParamWrong
  4757. return
  4758. }
  4759. patient.Gender = gender
  4760. if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
  4761. response_result := patientBody["response_result"].(string)
  4762. patient.ResponseResult = response_result
  4763. }
  4764. if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
  4765. utils.ErrorLog("age")
  4766. code = enums.ErrorCodeParamWrong
  4767. return
  4768. }
  4769. age := int64(patientBody["age"].(float64))
  4770. patient.Age = age
  4771. if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
  4772. user_sys_before_count := patientBody["user_sys_before_count"].(string)
  4773. count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
  4774. patient.UserSysBeforeCount = count
  4775. }
  4776. timeLayout := "2006-01-02"
  4777. loc, _ := time.LoadLocation("Local")
  4778. if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
  4779. utils.ErrorLog("birth")
  4780. code = enums.ErrorCodeParamWrong
  4781. return
  4782. }
  4783. birth, _ := patientBody["birth"].(string)
  4784. if len(birth) == 0 {
  4785. utils.ErrorLog("len(birth) == 0")
  4786. code = enums.ErrorCodeParamWrong
  4787. return
  4788. }
  4789. birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
  4790. if err != nil {
  4791. utils.ErrorLog("birthTime")
  4792. code = enums.ErrorCodeParamWrong
  4793. return
  4794. }
  4795. patient.Birthday = birthTime.Unix()
  4796. if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
  4797. height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
  4798. patient.Height = height
  4799. }
  4800. if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
  4801. maritalStatus := int64(patientBody["maritalStatus"].(float64))
  4802. patient.MaritalStatus = maritalStatus
  4803. }
  4804. if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
  4805. children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
  4806. patient.Children = children
  4807. }
  4808. if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
  4809. admissionNumber, _ := patientBody["admissionNumber"].(string)
  4810. patient.AdmissionNumber = admissionNumber
  4811. }
  4812. if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
  4813. reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
  4814. patient.ReimbursementWayId = reimbursementWayID
  4815. }
  4816. if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
  4817. healthCareNo := patientBody["healthCareNo"].(string)
  4818. patient.HealthCareNo = healthCareNo
  4819. }
  4820. if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
  4821. utils.ErrorLog("phone")
  4822. code = enums.ErrorCodeParamWrong
  4823. return
  4824. }
  4825. phone := patientBody["phone"].(string)
  4826. if len(phone) == 0 {
  4827. utils.ErrorLog("len(phone) == 0")
  4828. code = enums.ErrorCodeParamWrong
  4829. return
  4830. }
  4831. if !utils.CheckMobile(phone) {
  4832. utils.ErrorLog("!phone")
  4833. code = enums.ErrorCodeMobileFormat
  4834. return
  4835. }
  4836. patient.Phone = phone
  4837. if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
  4838. homeTelephone := patientBody["homeTelephone"].(string)
  4839. patient.HomeTelephone = homeTelephone
  4840. }
  4841. if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
  4842. relativePhone := patientBody["relative_phone"].(string)
  4843. patient.RelativePhone = relativePhone
  4844. }
  4845. if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
  4846. relativeRelations := patientBody["relative_relations"].(string)
  4847. patient.RelativeRelations = relativeRelations
  4848. }
  4849. if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
  4850. homeAddress := patientBody["homeAddress"].(string)
  4851. patient.HomeAddress = homeAddress
  4852. }
  4853. if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
  4854. work := patientBody["work"].(string)
  4855. patient.WorkUnit = work
  4856. }
  4857. if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
  4858. unitAddress := patientBody["unit_address"].(string)
  4859. patient.UnitAddress = unitAddress
  4860. }
  4861. if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
  4862. profession := int64(patientBody["profession"].(float64))
  4863. patient.Profession = profession
  4864. }
  4865. if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
  4866. education := int64(patientBody["education"].(float64))
  4867. patient.EducationLevel = education
  4868. }
  4869. if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
  4870. utils.ErrorLog("source")
  4871. code = enums.ErrorCodeParamWrong
  4872. return
  4873. }
  4874. source := int64(patientBody["source"].(float64))
  4875. if source <= 0 {
  4876. utils.ErrorLog("source <= 0")
  4877. code = enums.ErrorCodeParamWrong
  4878. return
  4879. }
  4880. patient.Source = source
  4881. zb_patient_id := patientBody["zb_patient_id"].(string)
  4882. patient.ZbPatientId = zb_patient_id
  4883. if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
  4884. isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
  4885. patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
  4886. }
  4887. if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
  4888. firstDialysisDate := patientBody["firstDialysisDate"].(string)
  4889. firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
  4890. if err == nil {
  4891. patient.FirstDialysisDate = firstDialysisDateTime.Unix()
  4892. }
  4893. }
  4894. if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
  4895. firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
  4896. patient.FirstDialysisHospital = firstDialysisHospital
  4897. }
  4898. if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
  4899. thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
  4900. if len(thePredialysisCondition) > 0 {
  4901. conditions := make([]string, 0)
  4902. for _, item := range thePredialysisCondition {
  4903. if reflect.TypeOf(item).String() != "string" {
  4904. continue
  4905. }
  4906. condition := item.(string)
  4907. if len(condition) > 0 {
  4908. conditions = append(conditions, condition)
  4909. }
  4910. }
  4911. patient.PredialysisCondition = strings.Join(conditions, ",")
  4912. }
  4913. }
  4914. if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
  4915. preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
  4916. patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
  4917. }
  4918. if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
  4919. preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
  4920. patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
  4921. }
  4922. if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
  4923. hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
  4924. hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
  4925. if err == nil {
  4926. patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
  4927. }
  4928. }
  4929. if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
  4930. partition := int64(patientBody["partition"].(float64))
  4931. patient.PartitionId = partition
  4932. }
  4933. if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
  4934. bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
  4935. patient.BedId = bed
  4936. }
  4937. if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
  4938. healthCareDueDate := patientBody["healthCareDueDate"].(string)
  4939. healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
  4940. if err == nil {
  4941. patient.HealthCareDueDate = healthCareDueDateTime.Unix()
  4942. }
  4943. }
  4944. if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
  4945. blood := int64(patientBody["blood"].(float64))
  4946. patient.BloodType = blood
  4947. }
  4948. if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
  4949. rh := int64(patientBody["rh"].(float64))
  4950. patient.Rh = rh
  4951. }
  4952. if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
  4953. healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
  4954. healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
  4955. if err == nil {
  4956. patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
  4957. }
  4958. }
  4959. if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
  4960. receivingDate := patientBody["receivingDate"].(string)
  4961. receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
  4962. if err == nil {
  4963. patient.ReceivingDate = receivingDateTime.Unix()
  4964. }
  4965. }
  4966. if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
  4967. induction := int64(patientBody["induction"].(float64))
  4968. patient.InductionPeriod = induction
  4969. }
  4970. if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
  4971. initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
  4972. patient.InitialDialysis = initial
  4973. }
  4974. if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
  4975. dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
  4976. patient.TotalDialysis = dialysisTotal
  4977. }
  4978. if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
  4979. thisContagions, _ := patientBody["contagions"].([]interface{})
  4980. if len(thisContagions) > 0 {
  4981. for _, item := range thisContagions {
  4982. if reflect.TypeOf(item).String() != "float64" {
  4983. continue
  4984. }
  4985. contagion := int64(item.(float64))
  4986. if contagion > 0 {
  4987. contagions = append(contagions, contagion)
  4988. }
  4989. }
  4990. }
  4991. }
  4992. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  4993. doctor := int64(patientBody["doctor"].(float64))
  4994. patient.AttendingDoctorId = doctor
  4995. }
  4996. if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
  4997. nurse := int64(patientBody["nurse"].(float64))
  4998. patient.HeadNurseId = nurse
  4999. }
  5000. if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
  5001. assessment := patientBody["assessment"].(string)
  5002. patient.Evaluate = assessment
  5003. }
  5004. if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
  5005. thisDiseases, _ := patientBody["diseases"].([]interface{})
  5006. if len(thisDiseases) > 0 {
  5007. for _, item := range thisDiseases {
  5008. if reflect.TypeOf(item).String() != "float64" {
  5009. continue
  5010. }
  5011. disease := int64(item.(float64))
  5012. if disease > 0 {
  5013. diseases = append(diseases, disease)
  5014. }
  5015. }
  5016. }
  5017. }
  5018. if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
  5019. diagnose := patientBody["diagnose"].(string)
  5020. patient.Diagnose = diagnose
  5021. }
  5022. if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
  5023. remark := patientBody["remark"].(string)
  5024. patient.Remark = remark
  5025. }
  5026. if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
  5027. sch_remark := patientBody["sch_remark"].(string)
  5028. patient.SchRemark = sch_remark
  5029. }
  5030. if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
  5031. patient_complains := patientBody["patient_complains"].(string)
  5032. patient.PatientComplains = patient_complains
  5033. }
  5034. if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
  5035. present_history := patientBody["present_history"].(string)
  5036. patient.PresentHistory = present_history
  5037. }
  5038. if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
  5039. past_history := patientBody["past_history"].(string)
  5040. patient.PastHistory = past_history
  5041. }
  5042. if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
  5043. temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
  5044. patient.Temperature = temperature
  5045. }
  5046. if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
  5047. pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
  5048. patient.Pulse = pulse
  5049. }
  5050. if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
  5051. respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
  5052. patient.Respiratory = respiratory
  5053. }
  5054. if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
  5055. sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
  5056. patient.SBP = sbp
  5057. }
  5058. if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
  5059. dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
  5060. patient.DBP = dbp
  5061. }
  5062. if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
  5063. dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
  5064. patient.DialysisAge = dialysis_age
  5065. }
  5066. fmt.Println(patient.DialysisAge)
  5067. if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
  5068. first_treatment_date := patientBody["first_treatment_date"].(string)
  5069. first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  5070. if err == nil {
  5071. patient.FirstTreatmentDate = first_treatment_time.Unix()
  5072. }
  5073. }
  5074. if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
  5075. expense_kind := int64(patientBody["expense_kind"].(float64))
  5076. patient.ExpenseKind = expense_kind
  5077. }
  5078. fmt.Println(patient.ExpenseKind)
  5079. if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
  5080. tell_phone := patientBody["tell_phone"].(string)
  5081. patient.TellPhone = tell_phone
  5082. }
  5083. if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
  5084. contact_name := patientBody["contact_name"].(string)
  5085. patient.ContactName = contact_name
  5086. }
  5087. if patientBody["troble_shoot"] != nil && reflect.TypeOf(patientBody["troble_shoot"]).String() == "float64" {
  5088. troble_shoot := int64(patientBody["troble_shoot"].(float64))
  5089. patient.TrobleShoot = troble_shoot
  5090. }
  5091. if patientBody["treatment_plan"] != nil && reflect.TypeOf(patientBody["treatment_plan"]).String() == "string" {
  5092. treatment_plan := patientBody["treatment_plan"].(string)
  5093. patient.TreatmentPlan = treatment_plan
  5094. }
  5095. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  5096. doctor := int64(patientBody["doctor"].(float64))
  5097. patient.Doctor = doctor
  5098. }
  5099. if patientBody["record_number"] != nil && reflect.TypeOf(patientBody["record_number"]).String() == "string" {
  5100. record_number := patientBody["record_number"].(string)
  5101. patient.RecordNumber = record_number
  5102. }
  5103. patient_source := int64(patientBody["patient_source"].(float64))
  5104. if patient_source <= 0 {
  5105. utils.ErrorLog("patient_source <= 0")
  5106. code = enums.ErrorCodeParamWrong
  5107. return
  5108. }
  5109. patient.PatientSource = patient_source
  5110. if patientBody["patient_start_time"] != nil && reflect.TypeOf(patientBody["patient_start_time"]).String() == "string" {
  5111. patient_start_time := patientBody["patient_start_time"].(string)
  5112. var startTime int64
  5113. if len(patient_start_time) > 0 {
  5114. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_start_time+" 00:00:00", loc)
  5115. startTime = theTime.Unix()
  5116. }
  5117. patient.PatientStartTime = startTime
  5118. }
  5119. if patientBody["patient_end_time"] != nil && reflect.TypeOf(patientBody["patient_end_time"]).String() == "string" {
  5120. patient_end_time := patientBody["patient_end_time"].(string)
  5121. var endTime int64
  5122. if len(patient_end_time) > 0 {
  5123. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_end_time+" 00:00:00", loc)
  5124. endTime = theTime.Unix()
  5125. }
  5126. patient.PatientEndTime = endTime
  5127. }
  5128. if patientBody["infectious_remark"] != nil && reflect.TypeOf(patientBody["infectious_remark"]).String() == "string" {
  5129. record_number := patientBody["infectious_remark"].(string)
  5130. patient.InfectiousRemark = record_number
  5131. }
  5132. if patientBody["allergic_history"] != nil && reflect.TypeOf(patientBody["allergic_history"]).String() == "string" {
  5133. allergic_history := patientBody["allergic_history"].(string)
  5134. patient.AllergicHistory = allergic_history
  5135. }
  5136. if patientBody["patient_address"] != nil && reflect.TypeOf(patientBody["patient_address"]).String() == "string" {
  5137. patient_address := patientBody["patient_address"].(string)
  5138. patient.PatientAddress = patient_address
  5139. }
  5140. if patientBody["print_date"] != nil && reflect.TypeOf(patientBody["print_date"]).String() == "string" {
  5141. print_date := patientBody["print_date"].(string)
  5142. printDateTime, err := time.ParseInLocation(timeLayout, print_date, loc)
  5143. if err == nil {
  5144. patient.PrintDate = printDateTime.Unix()
  5145. }
  5146. }
  5147. return
  5148. }
  5149. func (c *PatientApiController) GetPatientsByKeyWord() {
  5150. keyWord := c.GetString("keyword")
  5151. adminUserInfo := c.GetAdminUserInfo()
  5152. patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  5153. if err != nil {
  5154. utils.ErrorLog(err.Error())
  5155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5156. return
  5157. }
  5158. c.ServeSuccessJSON(map[string]interface{}{
  5159. "patient": patient,
  5160. })
  5161. }
  5162. func (c *PatientApiController) QueryPatientById() {
  5163. id, _ := c.GetInt64("id")
  5164. fmt.Println(id)
  5165. patientInfo := service.QueryPatientById(id)
  5166. c.ServeSuccessJSON(map[string]interface{}{
  5167. "patient": patientInfo,
  5168. })
  5169. return
  5170. }
  5171. func (c *PatientApiController) GetRemindPatientList() {
  5172. page, _ := c.GetInt64("page", 1)
  5173. limit, _ := c.GetInt64("limit", 10)
  5174. adminUserInfo := c.GetAdminUserInfo()
  5175. total, patients, _ := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
  5176. _, errcode := service.GetOrgFollowIsExist(c.GetAdminUserInfo().CurrentOrgId)
  5177. if errcode == gorm.ErrRecordNotFound {
  5178. information, err := service.GetAdminUserRoleInformation(0)
  5179. if err != nil {
  5180. utils.ErrorLog(err.Error())
  5181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5182. return
  5183. }
  5184. c.ServeSuccessJSON(map[string]interface{}{
  5185. "total": total,
  5186. "patients": patients,
  5187. "information": information,
  5188. })
  5189. } else if errcode == nil {
  5190. information, err := service.GetAdminUserRoleInformation(c.GetAdminUserInfo().CurrentOrgId)
  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. }
  5202. }
  5203. func (c *PatientApiController) PostIsOpenRemind() {
  5204. patient_id, _ := c.GetInt64("id", 1)
  5205. is_open_remind, _ := c.GetInt64("is_open_remind", 1)
  5206. adminUserInfo := c.GetAdminUserInfo()
  5207. err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
  5208. if err == nil {
  5209. c.ServeSuccessJSON(map[string]interface{}{
  5210. "msg": "成功",
  5211. "is_open_remind": is_open_remind,
  5212. })
  5213. } else if err != nil {
  5214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5215. }
  5216. }
  5217. func (c *PatientApiController) GetPatientScheduleOne() {
  5218. id, _ := c.GetInt64("id")
  5219. //查询该病人是否当天是排班
  5220. nowDateTime := time.Now()
  5221. nowDate := nowDateTime.Format("2006-01-02")
  5222. nowDate += " 00:00:00"
  5223. timeLayout := "2006-01-02"
  5224. loc, _ := time.LoadLocation("Local")
  5225. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  5226. nowdate := theTime.Unix()
  5227. fmt.Println("nowdate", nowdate)
  5228. adminUser := c.GetAdminUserInfo()
  5229. orgId := adminUser.CurrentOrgId
  5230. fmt.Println("orgid", orgId)
  5231. scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
  5232. if err != nil {
  5233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5234. return
  5235. }
  5236. c.ServeSuccessJSON(map[string]interface{}{
  5237. "scheduls": scheduls,
  5238. })
  5239. }
  5240. func (c *PatientApiController) ExportPatients() {
  5241. dataBody := make(map[string]interface{}, 0)
  5242. all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  5243. //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
  5244. org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
  5245. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5246. if err != nil {
  5247. utils.ErrorLog(err.Error())
  5248. return
  5249. }
  5250. utils.ErrorLog("%v", dataBody)
  5251. export_time := time.Now().Unix()
  5252. var patients []*models.Patients
  5253. var total_patients []interface{}
  5254. if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
  5255. tempPatients := dataBody["patients"].([]interface{})
  5256. total_patients = tempPatients
  5257. for index, patientMap := range tempPatients {
  5258. patientNameM := patientMap.(map[string]interface{})
  5259. var patient models.Patients
  5260. if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
  5261. utils.ErrorLog("name")
  5262. return
  5263. }
  5264. name, _ := patientNameM["name"].(string)
  5265. if len(name) == 0 { //名字为空则生成一条导入错误日志
  5266. err_log := models.ExportErrLog{
  5267. LogType: 1,
  5268. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5269. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
  5270. Status: 1,
  5271. CreateTime: time.Now().Unix(),
  5272. UpdateTime: time.Now().Unix(),
  5273. ExportTime: export_time,
  5274. }
  5275. service.CreateExportErrLog(&err_log)
  5276. continue
  5277. }
  5278. patient.Name = name
  5279. if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
  5280. gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
  5281. if gender == 0 { //性别不符合要求则生成一条导入错误日志
  5282. err_log := models.ExportErrLog{
  5283. LogType: 1,
  5284. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5285. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
  5286. Status: 1,
  5287. CreateTime: time.Now().Unix(),
  5288. UpdateTime: time.Now().Unix(),
  5289. ExportTime: export_time,
  5290. }
  5291. service.CreateExportErrLog(&err_log)
  5292. continue
  5293. } else {
  5294. patient.Gender = gender
  5295. }
  5296. }
  5297. if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
  5298. phone, _ := patientNameM["phone"].(string)
  5299. if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
  5300. if len(phone) == 0 {
  5301. err_log := models.ExportErrLog{
  5302. LogType: 1,
  5303. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5304. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
  5305. Status: 1,
  5306. CreateTime: time.Now().Unix(),
  5307. UpdateTime: time.Now().Unix(),
  5308. ExportTime: export_time,
  5309. }
  5310. service.CreateExportErrLog(&err_log)
  5311. continue
  5312. } else {
  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. }
  5325. } else {
  5326. //var tempPatient *models.Patients
  5327. //for _, item := range all_patient {
  5328. // if item.Phone == phone {
  5329. // tempPatient = item
  5330. // }
  5331. //}
  5332. //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
  5333. count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
  5334. if count >= 1 {
  5335. err_log := models.ExportErrLog{
  5336. LogType: 1,
  5337. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5338. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
  5339. Status: 1,
  5340. CreateTime: time.Now().Unix(),
  5341. UpdateTime: time.Now().Unix(),
  5342. ExportTime: export_time,
  5343. }
  5344. service.CreateExportErrLog(&err_log)
  5345. continue
  5346. }
  5347. patient.Phone = phone
  5348. }
  5349. }
  5350. if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
  5351. id_card_no, _ := patientNameM["id_card_no"].(string)
  5352. if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
  5353. if len(id_card_no) == 0 {
  5354. err_log := models.ExportErrLog{
  5355. LogType: 1,
  5356. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5357. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码不能为空",
  5358. Status: 1,
  5359. CreateTime: time.Now().Unix(),
  5360. UpdateTime: time.Now().Unix(),
  5361. ExportTime: export_time,
  5362. }
  5363. service.CreateExportErrLog(&err_log)
  5364. continue
  5365. } else {
  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. }
  5378. } else {
  5379. //var tempPatient *models.Patients
  5380. //for _, item := range all_patient {
  5381. // if item.IdCardNo == id_card_no {
  5382. // tempPatient = item
  5383. // }
  5384. //}
  5385. count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  5386. if count >= 1 {
  5387. //if tempPatient != nil && tempPatient.ID > 0 {
  5388. err_log := models.ExportErrLog{
  5389. LogType: 1,
  5390. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5391. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
  5392. Status: 1,
  5393. CreateTime: time.Now().Unix(),
  5394. UpdateTime: time.Now().Unix(),
  5395. ExportTime: export_time,
  5396. }
  5397. service.CreateExportErrLog(&err_log)
  5398. continue
  5399. }
  5400. //}
  5401. patient.IdCardNo = id_card_no
  5402. //patient.Birthday = GetBirthDay(id_card_no).Unix()
  5403. if GetBirthDay(id_card_no) == nil {
  5404. patient.Birthday = 0
  5405. } else {
  5406. patient.Birthday = GetBirthDay(id_card_no).Unix()
  5407. }
  5408. }
  5409. }
  5410. fmt.Println("111112222")
  5411. if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
  5412. first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
  5413. timeLayout := "2006/01/02"
  5414. loc, _ := time.LoadLocation("Local")
  5415. first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  5416. if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  5417. if len(first_treatment_date) == 0 {
  5418. err_log := models.ExportErrLog{
  5419. LogType: 1,
  5420. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5421. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  5422. Status: 1,
  5423. CreateTime: time.Now().Unix(),
  5424. UpdateTime: time.Now().Unix(),
  5425. ExportTime: export_time,
  5426. }
  5427. service.CreateExportErrLog(&err_log)
  5428. continue
  5429. } else {
  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. }
  5442. } else {
  5443. if len(first_treatment_date) == 0 {
  5444. err_log := models.ExportErrLog{
  5445. LogType: 1,
  5446. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5447. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  5448. Status: 1,
  5449. CreateTime: time.Now().Unix(),
  5450. UpdateTime: time.Now().Unix(),
  5451. ExportTime: export_time,
  5452. }
  5453. service.CreateExportErrLog(&err_log)
  5454. continue
  5455. } else {
  5456. if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  5457. err_log := models.ExportErrLog{
  5458. LogType: 1,
  5459. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5460. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  5461. Status: 1,
  5462. CreateTime: time.Now().Unix(),
  5463. UpdateTime: time.Now().Unix(),
  5464. ExportTime: export_time,
  5465. }
  5466. service.CreateExportErrLog(&err_log)
  5467. continue
  5468. } else {
  5469. patient.FirstDialysisDate = first_dialysis_date.Unix()
  5470. }
  5471. }
  5472. }
  5473. }
  5474. if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
  5475. source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
  5476. if source == 0 { //患者来源不符合要求则生成一条导入错误日志
  5477. err_log := models.ExportErrLog{
  5478. LogType: 1,
  5479. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5480. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
  5481. Status: 1,
  5482. CreateTime: time.Now().Unix(),
  5483. UpdateTime: time.Now().Unix(),
  5484. ExportTime: export_time,
  5485. }
  5486. service.CreateExportErrLog(&err_log)
  5487. continue
  5488. } else if source == 3 {
  5489. err_log := models.ExportErrLog{
  5490. LogType: 1,
  5491. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5492. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
  5493. Status: 1,
  5494. CreateTime: time.Now().Unix(),
  5495. UpdateTime: time.Now().Unix(),
  5496. ExportTime: export_time,
  5497. }
  5498. service.CreateExportErrLog(&err_log)
  5499. continue
  5500. } else {
  5501. patient.Source = source
  5502. }
  5503. }
  5504. if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
  5505. lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
  5506. if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
  5507. err_log := models.ExportErrLog{
  5508. LogType: 1,
  5509. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5510. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
  5511. Status: 1,
  5512. CreateTime: time.Now().Unix(),
  5513. UpdateTime: time.Now().Unix(),
  5514. ExportTime: export_time,
  5515. }
  5516. service.CreateExportErrLog(&err_log)
  5517. continue
  5518. } else if lapseto == 3 {
  5519. err_log := models.ExportErrLog{
  5520. LogType: 1,
  5521. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5522. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
  5523. Status: 1,
  5524. CreateTime: time.Now().Unix(),
  5525. UpdateTime: time.Now().Unix(),
  5526. ExportTime: export_time,
  5527. }
  5528. service.CreateExportErrLog(&err_log)
  5529. continue
  5530. } else {
  5531. patient.Lapseto = lapseto
  5532. }
  5533. }
  5534. if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
  5535. is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
  5536. if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
  5537. err_log := models.ExportErrLog{
  5538. LogType: 1,
  5539. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5540. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
  5541. Status: 1,
  5542. CreateTime: time.Now().Unix(),
  5543. UpdateTime: time.Now().Unix(),
  5544. ExportTime: export_time,
  5545. }
  5546. service.CreateExportErrLog(&err_log)
  5547. continue
  5548. } else if is_infectious == 3 {
  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 {
  5561. patient.IsInfectious = is_infectious
  5562. }
  5563. }
  5564. if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
  5565. var contagions []int64
  5566. thisContagions, _ := patientNameM["contagions"].([]interface{})
  5567. if len(thisContagions) > 0 {
  5568. for _, item := range thisContagions {
  5569. if reflect.TypeOf(item).String() != "float64" {
  5570. continue
  5571. }
  5572. contagion := int64(item.(float64))
  5573. if contagion > 0 {
  5574. contagions = append(contagions, contagion)
  5575. }
  5576. }
  5577. }
  5578. patient.ContagionIds = contagions
  5579. }
  5580. if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
  5581. diagnose, _ := patientNameM["diagnose"].(string)
  5582. patient.Diagnose = diagnose
  5583. }
  5584. if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
  5585. dialysis_no, _ := patientNameM["dialysis_no"].(string)
  5586. var tempPatient *models.Patients
  5587. for _, item := range all_patient {
  5588. if item.DialysisNo == dialysis_no {
  5589. tempPatient = item
  5590. }
  5591. }
  5592. if tempPatient != nil && tempPatient.ID > 0 {
  5593. patient.DialysisNo = GenerateDialysisNoTwo(patients)
  5594. } else {
  5595. patient.DialysisNo = dialysis_no
  5596. }
  5597. }
  5598. if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
  5599. height, _ := patientNameM["height"].(string)
  5600. heights, _ := strconv.ParseFloat(height, 64)
  5601. patient.Height = int64(heights)
  5602. }
  5603. if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
  5604. home_address, _ := patientNameM["home_address"].(string)
  5605. patient.HomeAddress = home_address
  5606. }
  5607. if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
  5608. dry_weight, _ := patientNameM["dry_weight"].(string)
  5609. dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
  5610. patient.DryWeight = dry_weights
  5611. }
  5612. patient.CreatedTime = time.Now().Unix()
  5613. patient.UpdatedTime = time.Now().Unix()
  5614. patient.Status = 1
  5615. patient.Avatar = "https://images.shengws.com/201809182128111.png"
  5616. patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  5617. patient.IsExcelExport = 1
  5618. patient.PatientType = 1
  5619. patients = append(patients, &patient)
  5620. }
  5621. }
  5622. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  5623. if len(patients) > 0 {
  5624. for _, item := range patients {
  5625. hans := item.Name // 要转换的汉字字符串
  5626. // 创建一个拼音转换器
  5627. p := pinyin.NewArgs()
  5628. // 将汉字转为拼音
  5629. pinyinSlice := pinyin.Pinyin(hans, p)
  5630. // 输出拼音
  5631. fmt.Println("Pinyin:", pinyinSlice)
  5632. // 获取首字母
  5633. firstLetter := ""
  5634. for _, py := range pinyinSlice {
  5635. if len(py) > 0 {
  5636. firstLetter += string(py[0][0])
  5637. }
  5638. }
  5639. item.FirstLetter = firstLetter
  5640. service.CreateExportPatient(item, item.ContagionIds, org.Creator)
  5641. }
  5642. log := models.ExportLog{
  5643. LogType: 1,
  5644. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5645. TotalNum: int64(len(total_patients)),
  5646. FailNum: int64(len(errLogs)),
  5647. SuccessNum: int64(len(patients)),
  5648. CreateTime: time.Now().Unix(),
  5649. UpdateTime: time.Now().Unix(),
  5650. ExportTime: export_time,
  5651. Status: 1,
  5652. }
  5653. service.CreateExportLog(&log)
  5654. c.ServeSuccessJSON(map[string]interface{}{
  5655. "msg": "导入成功",
  5656. "total_num": len(total_patients),
  5657. "success_num": len(patients),
  5658. "fail_num": int64(len(errLogs)),
  5659. })
  5660. } else {
  5661. log := models.ExportLog{
  5662. LogType: 1,
  5663. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5664. TotalNum: int64(len(total_patients)),
  5665. FailNum: int64(len(errLogs)),
  5666. SuccessNum: int64(len(patients)),
  5667. CreateTime: time.Now().Unix(),
  5668. UpdateTime: time.Now().Unix(),
  5669. ExportTime: export_time,
  5670. Status: 1,
  5671. }
  5672. service.CreateExportLog(&log)
  5673. c.ServeSuccessJSON(map[string]interface{}{
  5674. "msg": "导入成功",
  5675. "total_num": len(total_patients),
  5676. "success_num": len(patients),
  5677. "fail_num": int64(len(errLogs)),
  5678. })
  5679. }
  5680. }
  5681. func GetBirthDay(IDCardNo string) *time.Time {
  5682. dayStr := IDCardNo[6:14]
  5683. birthDay, err := time.Parse("20060102", dayStr)
  5684. if err != nil {
  5685. fmt.Println(err)
  5686. return nil
  5687. }
  5688. return &birthDay
  5689. }
  5690. func IsIdCard(id string) (res bool) {
  5691. id = strings.ToUpper(id)
  5692. if len(id) != 15 && len(id) != 18 {
  5693. fmt.Println("1111111")
  5694. return false
  5695. }
  5696. r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
  5697. if !r.MatchString(id) {
  5698. fmt.Println("222222")
  5699. return false
  5700. }
  5701. if len(id) == 15 {
  5702. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
  5703. if tm2.Unix() == 0 {
  5704. fmt.Println("44444443333")
  5705. return false
  5706. }
  5707. return true
  5708. } else {
  5709. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
  5710. fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
  5711. fmt.Println(tm2.Unix())
  5712. if tm2.Unix() == 0 {
  5713. fmt.Println("44445555555")
  5714. return false
  5715. }
  5716. //检验18位身份证的校验码是否正确。
  5717. //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  5718. arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
  5719. arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
  5720. sign := 0
  5721. for k, v := range arr_int {
  5722. int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
  5723. sign += int_temp * v
  5724. }
  5725. n := sign % 11
  5726. val_num := arr_ch[n]
  5727. if val_num != string([]byte(id)[17:18]) {
  5728. fmt.Println("5556666666")
  5729. return false
  5730. }
  5731. return true
  5732. }
  5733. }
  5734. func (c *PatientApiController) SaveEditAdvices() {
  5735. adminInfo := c.GetAdminUserInfo()
  5736. orgid := adminInfo.CurrentOrgId
  5737. startTime := c.GetString("start_time")
  5738. theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
  5739. groupno, _ := c.GetInt64("groupno")
  5740. fmt.Println("组", groupno)
  5741. date, _ := c.GetInt64("date")
  5742. fmt.Println("date", date)
  5743. patient_id, _ := c.GetInt64("patient_id")
  5744. fmt.Println("paitent_id", patient_id)
  5745. advice := models.XtDoctorAdvice{
  5746. StartTime: theTime.Unix(),
  5747. }
  5748. err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
  5749. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(date, 10) + ":doctor_advices"
  5750. redis := service.RedisClient()
  5751. redis.Set(key, "", time.Second)
  5752. keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(date, 10) + ":advice_list_all"
  5753. redis.Set(keyOne, "", time.Second)
  5754. scheduleTime := theTime.Format("2006-01-02")
  5755. keyFour := "scheduals_" + scheduleTime + "_" + strconv.FormatInt(orgid, 10)
  5756. fmt.Println("keyFour323223323232323232", keyFour)
  5757. redis.Set(keyFour, "", time.Second)
  5758. defer redis.Close()
  5759. if err != nil {
  5760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5761. return
  5762. }
  5763. c.ServeSuccessJSON(map[string]interface{}{
  5764. "advice": advice,
  5765. })
  5766. }
  5767. func (c *PatientApiController) GetMaxDialysisNo() {
  5768. dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
  5769. c.ServeSuccessJSON(map[string]interface{}{
  5770. "dialysis_no": dialysisNo,
  5771. })
  5772. }
  5773. func GenerateDialysisNoTwo(patients []*models.Patients) string {
  5774. dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
  5775. var tempPatient *models.Patients
  5776. for _, item := range patients {
  5777. if item.DialysisNo == dialysisNo2 {
  5778. tempPatient = item
  5779. }
  5780. }
  5781. if tempPatient == nil || tempPatient.ID == 0 {
  5782. return dialysisNo2
  5783. }
  5784. return GenerateDialysisNoTwo(patients)
  5785. }
  5786. func (c *PatientApiController) GetBanner() {
  5787. orgId := c.GetAdminUserInfo().CurrentOrgId
  5788. _, errcodes := service.GetOrgFollowIsExist(orgId)
  5789. if errcodes == gorm.ErrRecordNotFound {
  5790. information, err := service.GetAdminUserRoleInformation(0)
  5791. if err != nil {
  5792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5793. return
  5794. }
  5795. c.ServeSuccessJSON(map[string]interface{}{
  5796. "information": information,
  5797. })
  5798. } else if errcodes == nil {
  5799. information, err := service.GetAdminUserRoleInformation(orgId)
  5800. if err != nil {
  5801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5802. return
  5803. }
  5804. c.ServeSuccessJSON(map[string]interface{}{
  5805. "information": information,
  5806. })
  5807. }
  5808. }
  5809. func (c *PatientApiController) GetPatientDialysisLongSolution() {
  5810. patient_id, _ := c.GetInt64("id", 0)
  5811. page, _ := c.GetInt64("page", 0)
  5812. limit, _ := c.GetInt64("limit", 0)
  5813. if patient_id <= 0 {
  5814. c.ServeSuccessJSON(map[string]interface{}{
  5815. "solutions": nil,
  5816. })
  5817. return
  5818. }
  5819. if page <= 0 {
  5820. page = 1
  5821. }
  5822. if limit <= 0 {
  5823. limit = 10
  5824. }
  5825. adminUserInfo := c.GetAdminUserInfo()
  5826. //获取该患者分组的透析模式
  5827. list, _ := service.GetPatientSolutionGroupList(patient_id, adminUserInfo.CurrentOrgId)
  5828. for _, item := range list {
  5829. //获取该模式最新的1条数据
  5830. solution, _ := service.GetNewPatientSolutionByModeId(patient_id, item.ModeId, adminUserInfo.CurrentOrgId)
  5831. //更新状态值
  5832. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, adminUserInfo.CurrentOrgId, patient_id)
  5833. }
  5834. solution, total, err := service.GetPatientDialysisLongSolution(patient_id, page, limit, adminUserInfo.CurrentOrgId)
  5835. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  5836. if err != nil {
  5837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5838. return
  5839. }
  5840. c.ServeSuccessJSON(map[string]interface{}{
  5841. "solutions": solution,
  5842. "total": total,
  5843. "stockType": stockType,
  5844. })
  5845. }
  5846. func (c *PatientApiController) GetDialysisSolutionDetailList() {
  5847. patient_id, _ := c.GetInt64("patient_id")
  5848. mode_id, _ := c.GetInt64("mode_id")
  5849. page, _ := c.GetInt64("page")
  5850. limit, _ := c.GetInt64("limit")
  5851. orgId := c.GetAdminUserInfo().CurrentOrgId
  5852. list, total, err := service.GetDialysisSolutionDetailList(orgId, patient_id, mode_id, page, limit)
  5853. if err != nil {
  5854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5855. return
  5856. }
  5857. c.ServeSuccessJSON(map[string]interface{}{
  5858. "list": list,
  5859. "total": total,
  5860. })
  5861. }
  5862. func (c *PatientApiController) SaveFallOutBedPrint() {
  5863. adminInfo := c.GetAdminUserInfo()
  5864. orgid := adminInfo.CurrentOrgId
  5865. dataBody := make(map[string]interface{}, 0)
  5866. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5867. fmt.Println("err", err)
  5868. content := dataBody["content"].(string)
  5869. outPrint := models.XtFallOutPrint{
  5870. UserOrgId: orgid,
  5871. Content: content,
  5872. Status: 1,
  5873. Ctime: time.Now().Unix(),
  5874. Mtime: time.Now().Unix(),
  5875. }
  5876. //查询该机构是否存在
  5877. list, err := service.GetOutPrintList(orgid)
  5878. if list.ID == 0 {
  5879. service.CreateFallOutBedPrint(outPrint)
  5880. }
  5881. if list.ID > 0 {
  5882. service.UpdateFallOutBedPrint(list.ID, content)
  5883. }
  5884. c.ServeSuccessJSON(map[string]interface{}{
  5885. "list": list,
  5886. })
  5887. }
  5888. func (c *PatientApiController) GetFallOutBedPrintList() {
  5889. adminInfo := c.GetAdminUserInfo()
  5890. orgid := adminInfo.CurrentOrgId
  5891. list, _ := service.GetFallOutBedPrintList(orgid)
  5892. c.ServeSuccessJSON(map[string]interface{}{
  5893. "list": list,
  5894. })
  5895. }
  5896. func (c *PatientApiController) SaveFilterInformed() {
  5897. adminInfo := c.GetAdminUserInfo()
  5898. orgid := adminInfo.CurrentOrgId
  5899. dataBody := make(map[string]interface{}, 0)
  5900. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5901. fmt.Println("err", err)
  5902. content := dataBody["content"].(string)
  5903. informed := models.XtFilterInformed{
  5904. UserOrgId: orgid,
  5905. Content: content,
  5906. Status: 1,
  5907. Ctime: time.Now().Unix(),
  5908. Mtime: time.Now().Unix(),
  5909. }
  5910. filterInformed, _ := service.GetFilterInformed(orgid)
  5911. if filterInformed.ID == 0 {
  5912. service.CreateFilterInformed(informed)
  5913. }
  5914. if filterInformed.ID > 0 {
  5915. service.UpdateFilterInformed(filterInformed.ID, content)
  5916. }
  5917. c.ServeSuccessJSON(map[string]interface{}{
  5918. "informed": informed,
  5919. })
  5920. }
  5921. func (c *PatientApiController) GetFilterInformed() {
  5922. adminInfo := c.GetAdminUserInfo()
  5923. orgid := adminInfo.CurrentOrgId
  5924. filterInformed, _ := service.GetFilterInformed(orgid)
  5925. c.ServeSuccessJSON(map[string]interface{}{
  5926. "list": filterInformed,
  5927. })
  5928. }
  5929. func (c *PatientApiController) SaveProfundaInformed() {
  5930. adminInfo := c.GetAdminUserInfo()
  5931. orgid := adminInfo.CurrentOrgId
  5932. dataBody := make(map[string]interface{}, 0)
  5933. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5934. fmt.Println("err", err)
  5935. content := dataBody["content"].(string)
  5936. informed := models.XtProfundaInformed{
  5937. UserOrgId: orgid,
  5938. Content: content,
  5939. Status: 1,
  5940. Ctime: time.Now().Unix(),
  5941. Mtime: time.Now().Unix(),
  5942. }
  5943. profundaInformed, _ := service.GetProfundaInformed(orgid)
  5944. if profundaInformed.ID == 0 {
  5945. service.CreateProfundaInformed(informed)
  5946. }
  5947. if profundaInformed.ID > 0 {
  5948. service.UpdateProfundaInformed(profundaInformed.ID, content)
  5949. }
  5950. c.ServeSuccessJSON(map[string]interface{}{
  5951. "list": profundaInformed,
  5952. })
  5953. }
  5954. func (c *PatientApiController) GetProfundaInformed() {
  5955. adminInfo := c.GetAdminUserInfo()
  5956. orgid := adminInfo.CurrentOrgId
  5957. profundaInformed, _ := service.GetProfundaInformed(orgid)
  5958. c.ServeSuccessJSON(map[string]interface{}{
  5959. "list": profundaInformed,
  5960. })
  5961. }
  5962. func (c *PatientApiController) SaveArterOvenous() {
  5963. adminInfo := c.GetAdminUserInfo()
  5964. orgid := adminInfo.CurrentOrgId
  5965. dataBody := make(map[string]interface{}, 0)
  5966. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5967. fmt.Println("err", err)
  5968. content := dataBody["content"].(string)
  5969. arterOvenous := models.XtArterOvenous{
  5970. UserOrgId: orgid,
  5971. Content: content,
  5972. Status: 1,
  5973. Ctime: time.Now().Unix(),
  5974. Mtime: time.Now().Unix(),
  5975. }
  5976. list, _ := service.GetArterOvenousList(orgid)
  5977. if list.ID == 0 {
  5978. service.CreateArterOvernous(arterOvenous)
  5979. }
  5980. if list.ID > 0 {
  5981. service.UpdateArterOvernous(list.ID, content)
  5982. }
  5983. c.ServeSuccessJSON(map[string]interface{}{
  5984. "list": list,
  5985. })
  5986. }
  5987. func (c *PatientApiController) GetArterOverNous() {
  5988. adminInfo := c.GetAdminUserInfo()
  5989. orgid := adminInfo.CurrentOrgId
  5990. list, _ := service.GetArterOvenousList(orgid)
  5991. c.ServeSuccessJSON(map[string]interface{}{
  5992. "list": list,
  5993. })
  5994. }
  5995. func (c *PatientApiController) SaveHighRikInformed() {
  5996. adminInfo := c.GetAdminUserInfo()
  5997. orgid := adminInfo.CurrentOrgId
  5998. dataBody := make(map[string]interface{}, 0)
  5999. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6000. fmt.Println("err", err)
  6001. content := dataBody["content"].(string)
  6002. risk := models.XtHightRisk{
  6003. UserOrgId: orgid,
  6004. Content: content,
  6005. Status: 1,
  6006. Ctime: time.Now().Unix(),
  6007. Mtime: time.Now().Unix(),
  6008. }
  6009. highRik, _ := service.GetHightRikInformed(orgid)
  6010. if highRik.ID == 0 {
  6011. service.CreateHighRik(risk)
  6012. }
  6013. if highRik.ID > 0 {
  6014. service.UpdateHighRik(highRik.ID, content)
  6015. }
  6016. c.ServeSuccessJSON(map[string]interface{}{
  6017. "list": risk,
  6018. })
  6019. }
  6020. func (c *PatientApiController) GetHighRiskInformed() {
  6021. orgId := c.GetAdminUserInfo().CurrentOrgId
  6022. rikInformed, _ := service.GetHightRikInformed(orgId)
  6023. c.ServeSuccessJSON(map[string]interface{}{
  6024. "list": rikInformed,
  6025. })
  6026. }
  6027. func (c *PatientApiController) SaveAnticoagulation() {
  6028. orgId := c.GetAdminUserInfo().CurrentOrgId
  6029. dataBody := make(map[string]interface{}, 0)
  6030. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6031. fmt.Println("err", err)
  6032. content := dataBody["content"].(string)
  6033. auticoagutionPrint := models.XtAuticoagutionPrint{
  6034. Content: content,
  6035. UserOrgId: orgId,
  6036. Status: 1,
  6037. Ctime: time.Now().Unix(),
  6038. Mtime: time.Now().Unix(),
  6039. }
  6040. anticoagulation, _ := service.GetAnticoagulation(orgId)
  6041. if anticoagulation.ID == 0 {
  6042. service.CreateAnticoagulation(auticoagutionPrint)
  6043. }
  6044. if anticoagulation.ID > 0 {
  6045. service.UpdateAnticoagulation(anticoagulation.ID, content)
  6046. }
  6047. c.ServeSuccessJSON(map[string]interface{}{
  6048. "list": auticoagutionPrint,
  6049. })
  6050. }
  6051. func (c *PatientApiController) GetAnticoagulationInformed() {
  6052. orgId := c.GetAdminUserInfo().CurrentOrgId
  6053. anticoagulation, _ := service.GetAnticoagulation(orgId)
  6054. c.ServeSuccessJSON(map[string]interface{}{
  6055. "list": anticoagulation,
  6056. })
  6057. }
  6058. func (c *PatientApiController) SaveCriticalInfomed() {
  6059. orgId := c.GetAdminUserInfo().CurrentOrgId
  6060. dataBody := make(map[string]interface{}, 0)
  6061. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6062. fmt.Println("err", err)
  6063. content := dataBody["content"].(string)
  6064. criticalinfomedPrint := models.XtCriticalinfomedPrint{
  6065. UserOrgId: orgId,
  6066. Content: content,
  6067. Status: 1,
  6068. Ctime: time.Now().Unix(),
  6069. Mtime: time.Now().Unix(),
  6070. }
  6071. infomed, _ := service.GetCriticalInfomed(orgId)
  6072. if infomed.ID == 0 {
  6073. service.CreatedCriticalInfomed(criticalinfomedPrint)
  6074. }
  6075. if infomed.ID > 0 {
  6076. service.UpdateCriticalInfomed(infomed.ID, content)
  6077. }
  6078. c.ServeSuccessJSON(map[string]interface{}{
  6079. "list": criticalinfomedPrint,
  6080. })
  6081. }
  6082. func (c *PatientApiController) GetCriticalInformed() {
  6083. orgId := c.GetAdminUserInfo().CurrentOrgId
  6084. infomed, _ := service.GetCriticalInfomed(orgId)
  6085. c.ServeSuccessJSON(map[string]interface{}{
  6086. "list": infomed,
  6087. })
  6088. }
  6089. func (c *PatientApiController) SaveHemoperfusionInformed() {
  6090. orgId := c.GetAdminUserInfo().CurrentOrgId
  6091. dataBody := make(map[string]interface{}, 0)
  6092. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6093. fmt.Println("err", err)
  6094. content := dataBody["content"].(string)
  6095. hemoperfusionmedPrint := models.XtHemoperfusionmedPrint{
  6096. UserOrgId: orgId,
  6097. Content: content,
  6098. Status: 1,
  6099. Ctime: time.Now().Unix(),
  6100. Mtime: time.Now().Unix(),
  6101. }
  6102. informed, _ := service.GetHemoperfusionInformed(orgId)
  6103. if informed.ID == 0 {
  6104. service.CreateHemoperfusionInformed(hemoperfusionmedPrint)
  6105. }
  6106. if informed.ID > 0 {
  6107. service.UpdateHemoperfusionInformed(informed.ID, content)
  6108. }
  6109. c.ServeSuccessJSON(map[string]interface{}{
  6110. "list": hemoperfusionmedPrint,
  6111. })
  6112. }
  6113. func (c *PatientApiController) GetHemoperfusionInformed() {
  6114. orgId := c.GetAdminUserInfo().CurrentOrgId
  6115. informed, _ := service.GetHemoperfusionInformed(orgId)
  6116. c.ServeSuccessJSON(map[string]interface{}{
  6117. "list": informed,
  6118. })
  6119. }
  6120. func (c *PatientApiController) SaveBringInformed() {
  6121. orgId := c.GetAdminUserInfo().CurrentOrgId
  6122. dataBody := make(map[string]interface{}, 0)
  6123. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6124. fmt.Println("err", err)
  6125. content := dataBody["content"].(string)
  6126. bringinformedPrint := models.XtBringinformedPrint{
  6127. Content: content,
  6128. UserOrgId: orgId,
  6129. Ctime: time.Now().Unix(),
  6130. Mtime: time.Now().Unix(),
  6131. Status: 1,
  6132. }
  6133. informed, _ := service.GetBringInformed(orgId)
  6134. if informed.ID == 0 {
  6135. service.CreateBringInformed(bringinformedPrint)
  6136. }
  6137. if informed.ID > 0 {
  6138. service.UpdateBringInformed(informed.ID, content)
  6139. }
  6140. c.ServeSuccessJSON(map[string]interface{}{
  6141. "list": bringinformedPrint,
  6142. })
  6143. }
  6144. func (c *PatientApiController) GetInformedContsent() {
  6145. orgId := c.GetAdminUserInfo().CurrentOrgId
  6146. informed, _ := service.GetBringInformed(orgId)
  6147. c.ServeSuccessJSON(map[string]interface{}{
  6148. "list": informed,
  6149. })
  6150. }
  6151. func (c *PatientApiController) SaveCatheterization() {
  6152. orgId := c.GetAdminUserInfo().CurrentOrgId
  6153. dataBody := make(map[string]interface{}, 0)
  6154. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6155. fmt.Println("err", err)
  6156. content := dataBody["content"].(string)
  6157. cathetercationPrint := models.XtCathetercationPrint{
  6158. UserOrgId: orgId,
  6159. Content: content,
  6160. Status: 1,
  6161. Ctime: time.Now().Unix(),
  6162. Mtime: time.Now().Unix(),
  6163. }
  6164. catheterization, _ := service.GetCatheterization(orgId)
  6165. if cathetercationPrint.ID == 0 {
  6166. service.CreateCatheteriztion(cathetercationPrint)
  6167. }
  6168. if cathetercationPrint.ID > 0 {
  6169. service.UpdateCatheterization(catheterization.ID, content)
  6170. }
  6171. c.ServeSuccessJSON(map[string]interface{}{
  6172. "list": catheterization,
  6173. })
  6174. }
  6175. func (c *PatientApiController) GetCatheterization() {
  6176. orgId := c.GetAdminUserInfo().CurrentOrgId
  6177. catheterization, _ := service.GetCatheterization(orgId)
  6178. c.ServeSuccessJSON(map[string]interface{}{
  6179. "list": catheterization,
  6180. })
  6181. }
  6182. func (c *PatientApiController) SaveDialyzerInformed() {
  6183. orgId := c.GetAdminUserInfo().CurrentOrgId
  6184. dataBody := make(map[string]interface{}, 0)
  6185. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6186. fmt.Println("err", err)
  6187. content := dataBody["content"].(string)
  6188. dialyszerinformedPrint := models.XtDialyszerinformedPrint{
  6189. UserOrgId: orgId,
  6190. Content: content,
  6191. Status: 1,
  6192. Ctime: time.Now().Unix(),
  6193. Mtime: time.Now().Unix(),
  6194. }
  6195. informed, _ := service.GetDialyzerInformed(orgId)
  6196. if informed.ID == 0 {
  6197. service.CreateDialyzerInformed(dialyszerinformedPrint)
  6198. }
  6199. if informed.ID > 0 {
  6200. service.UpdateDialyszerInformed(informed.ID, content)
  6201. }
  6202. c.ServeSuccessJSON(map[string]interface{}{
  6203. "list": dialyszerinformedPrint,
  6204. })
  6205. }
  6206. func (c *PatientApiController) GetDialyzerInformed() {
  6207. orgId := c.GetAdminUserInfo().CurrentOrgId
  6208. informed, _ := service.GetDialyzerInformed(orgId)
  6209. c.ServeSuccessJSON(map[string]interface{}{
  6210. "list": informed,
  6211. })
  6212. }
  6213. func (c *PatientApiController) SaveTheapyInformed() {
  6214. orgId := c.GetAdminUserInfo().CurrentOrgId
  6215. dataBody := make(map[string]interface{}, 0)
  6216. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6217. fmt.Println("err", err)
  6218. content := dataBody["content"].(string)
  6219. theapyinformedPrint := models.XtTheapyinformedPrint{
  6220. Content: content,
  6221. UserOrgId: orgId,
  6222. Status: 1,
  6223. Ctime: time.Now().Unix(),
  6224. Mtime: time.Now().Unix(),
  6225. }
  6226. theapyInformed, _ := service.GetTheapyInformed(orgId)
  6227. if theapyInformed.ID == 0 {
  6228. service.CreateTheapyInformed(theapyinformedPrint)
  6229. }
  6230. if theapyInformed.ID > 0 {
  6231. service.UpdateTheaphInformed(theapyInformed.ID, content)
  6232. }
  6233. c.ServeSuccessJSON(map[string]interface{}{
  6234. "list": theapyinformedPrint,
  6235. })
  6236. }
  6237. func (c *PatientApiController) GetTherapyInformed() {
  6238. orgId := c.GetAdminUserInfo().CurrentOrgId
  6239. theapyInformed, _ := service.GetTheapyInformed(orgId)
  6240. c.ServeSuccessJSON(map[string]interface{}{
  6241. "list": theapyInformed,
  6242. })
  6243. }
  6244. func (c *PatientApiController) SaveMedicalHistory() {
  6245. orgId := c.GetAdminUserInfo().CurrentOrgId
  6246. dataBody := make(map[string]interface{}, 0)
  6247. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6248. fmt.Println("err", err)
  6249. content := dataBody["content"].(string)
  6250. patient_id := int64(dataBody["patient_id"].(float64))
  6251. medicalHistory := models.XtMedicalHistory{
  6252. UserOrgId: orgId,
  6253. PatientId: patient_id,
  6254. Ctime: time.Now().Unix(),
  6255. Mtime: 0,
  6256. Status: 1,
  6257. Content: content,
  6258. }
  6259. //
  6260. history, _ := service.GetPatientMedicalHistory(patient_id, orgId)
  6261. if history.ID > 0 {
  6262. service.UpdatePatientMedicalHistory(history.ID, content)
  6263. }
  6264. if history.ID == 0 {
  6265. service.CreatePatientMedicalHistory(medicalHistory)
  6266. }
  6267. c.ServeSuccessJSON(map[string]interface{}{
  6268. "medicalHistory": medicalHistory,
  6269. })
  6270. }
  6271. func (c *PatientApiController) SavePatientCritaicalInformed() {
  6272. orgId := c.GetAdminUserInfo().CurrentOrgId
  6273. dataBody := make(map[string]interface{}, 0)
  6274. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6275. fmt.Println("err", err)
  6276. content := dataBody["content"].(string)
  6277. patientCritical := models.XtPatientCritical{
  6278. UserOrgId: orgId,
  6279. Content: content,
  6280. Status: 1,
  6281. Ctime: time.Now().Unix(),
  6282. Mtime: time.Now().Unix(),
  6283. }
  6284. patientCritaicalInformed, _ := service.GetPatientCritaicalInformed(orgId)
  6285. if patientCritaicalInformed.ID == 0 {
  6286. service.CreatePatientCritaicalinformed(patientCritical)
  6287. }
  6288. if patientCritaicalInformed.ID > 0 {
  6289. service.UpdatePatientCritaicalInformed(patientCritaicalInformed.ID, content)
  6290. }
  6291. c.ServeSuccessJSON(map[string]interface{}{
  6292. "patientCritical": patientCritical,
  6293. })
  6294. }
  6295. func (c *PatientApiController) GetPatientCriticalList() {
  6296. orgId := c.GetAdminUserInfo().CurrentOrgId
  6297. patientCritaicalInformed, _ := service.GetPatientCritaicalInformed(orgId)
  6298. c.ServeSuccessJSON(map[string]interface{}{
  6299. "patientCritaicalInformed": patientCritaicalInformed,
  6300. })
  6301. }
  6302. func (c *PatientApiController) SavePatientCriticalInformedOne() {
  6303. orgId := c.GetAdminUserInfo().CurrentOrgId
  6304. dataBody := make(map[string]interface{}, 0)
  6305. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6306. fmt.Println("err", err)
  6307. content := dataBody["content"].(string)
  6308. criticalOne := models.XtPatientCriticalOne{
  6309. UserOrgId: orgId,
  6310. Content: content,
  6311. Status: 1,
  6312. Ctime: time.Now().Unix(),
  6313. Mtime: time.Now().Unix(),
  6314. }
  6315. critical, _ := service.GetPatientCriticalByUserOrgId(orgId)
  6316. if critical.ID == 0 {
  6317. service.CreatePatientCritical(criticalOne)
  6318. }
  6319. if critical.ID > 0 {
  6320. service.UpdatePatientCriticalOne(orgId, content)
  6321. }
  6322. c.ServeSuccessJSON(map[string]interface{}{
  6323. "criticalOne": criticalOne,
  6324. })
  6325. }
  6326. func (c *PatientApiController) GetPatientCriticalOneList() {
  6327. orgId := c.GetAdminUserInfo().CurrentOrgId
  6328. list, _ := service.GetPatientCriticalOneList(orgId)
  6329. c.ServeSuccessJSON(map[string]interface{}{
  6330. "list": list,
  6331. })
  6332. }
  6333. func (c *PatientApiController) DeleteSolution() {
  6334. id, _ := c.GetInt64("id")
  6335. solution, _ := service.DeleteSolutionById(id)
  6336. c.ServeSuccessJSON(map[string]interface{}{
  6337. "solution": solution,
  6338. })
  6339. }
  6340. func (c *PatientApiController) SaveTreatmentPlan() {
  6341. orgId := c.GetAdminUserInfo().CurrentOrgId
  6342. dataBody := make(map[string]interface{}, 0)
  6343. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6344. fmt.Println("err", err)
  6345. content := dataBody["content"].(string)
  6346. theapyinformedPrint := models.XtTreatmentPlan{
  6347. Content: content,
  6348. UserOrgId: orgId,
  6349. Status: 1,
  6350. Ctime: time.Now().Unix(),
  6351. Mtime: time.Now().Unix(),
  6352. }
  6353. treamentPlan, _ := service.GetTreamentPland(orgId)
  6354. if treamentPlan.ID == 0 {
  6355. service.CreateTreatqmentPland(theapyinformedPrint)
  6356. }
  6357. if treamentPlan.ID > 0 {
  6358. service.UpdateTheatmentPland(treamentPlan.ID, content)
  6359. }
  6360. c.ServeSuccessJSON(map[string]interface{}{
  6361. "list": theapyinformedPrint,
  6362. })
  6363. }
  6364. func (c *PatientApiController) GetTreatMentPlanList() {
  6365. orgId := c.GetAdminUserInfo().CurrentOrgId
  6366. treamentPlan, _ := service.GetTreamentPland(orgId)
  6367. c.ServeSuccessJSON(map[string]interface{}{
  6368. "treamentPlan": treamentPlan,
  6369. })
  6370. }
  6371. func (c *PatientApiController) GetPatientByPatientId() {
  6372. orgId := c.GetAdminUserInfo().CurrentOrgId
  6373. id, _ := c.GetInt64("id")
  6374. patients, _ := service.GetPatientByIDOne(orgId, id)
  6375. c.ServeSuccessJSON(map[string]interface{}{
  6376. "patients": patients,
  6377. })
  6378. }
  6379. func (c *PatientApiController) SavePatientLapse() {
  6380. dataBody := make(map[string]interface{}, 0)
  6381. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6382. fmt.Println(err)
  6383. patient_id := int64(dataBody["patient_id"].(float64))
  6384. admin_user_id := int64(dataBody["admin_user_id"].(float64))
  6385. lapse_class := int64(dataBody["lapse_class"].(float64))
  6386. lapse_type := int64(dataBody["lapse_type"].(float64))
  6387. lapse_reason := dataBody["lapse_reason"].(string)
  6388. record_date := dataBody["record_date"].(string)
  6389. lapse_type_name := dataBody["lapse_type_name"].(string)
  6390. his_bed := dataBody["his_bed"].(string)
  6391. his_zone := dataBody["his_zone"].(string)
  6392. his_type := int64(dataBody["his_type"].(float64))
  6393. patient_address := dataBody["patient_address"].(string)
  6394. start_time := dataBody["start_time"].(string)
  6395. end_time := dataBody["end_time"].(string)
  6396. start_time_one := dataBody["start_time_one"].(string)
  6397. end_time_one := dataBody["end_time_one"].(string)
  6398. timeLayout := "2006-01-02"
  6399. loc, _ := time.LoadLocation("Local")
  6400. var recordDate int64
  6401. if len(record_date) > 0 {
  6402. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6403. if err != nil {
  6404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6405. return
  6406. }
  6407. recordDate = theTime.Unix()
  6408. }
  6409. var startTime int64
  6410. if len(start_time) > 0 {
  6411. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6412. if err != nil {
  6413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6414. return
  6415. }
  6416. startTime = theTime.Unix()
  6417. }
  6418. var endTime int64
  6419. if len(end_time) > 0 {
  6420. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6421. if err != nil {
  6422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6423. return
  6424. }
  6425. endTime = theTime.Unix()
  6426. }
  6427. var startTimeOne int64
  6428. if len(start_time_one) > 0 {
  6429. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_one+" 00:00:00", loc)
  6430. if err != nil {
  6431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6432. return
  6433. }
  6434. startTimeOne = theTime.Unix()
  6435. }
  6436. var endTimeOne int64
  6437. if len(end_time_one) > 0 {
  6438. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_one+" 00:00:00", loc)
  6439. if err != nil {
  6440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6441. return
  6442. }
  6443. endTimeOne = theTime.Unix()
  6444. }
  6445. remark := dataBody["remark"].(string)
  6446. org_id := c.GetAdminUserInfo().CurrentOrgId
  6447. record := models.XtPatientLaspseRecord{
  6448. PatientId: patient_id,
  6449. RecordDate: recordDate,
  6450. LapseDate: recordDate,
  6451. LapseType: lapse_type,
  6452. LapseClass: lapse_class,
  6453. LapseReason: lapse_reason,
  6454. AdminUserId: admin_user_id,
  6455. Remark: remark,
  6456. UserOrgId: org_id,
  6457. Ctime: time.Now().Unix(),
  6458. Mtime: time.Now().Unix(),
  6459. Status: 1,
  6460. LapseTypeName: lapse_type_name,
  6461. HisBed: his_bed,
  6462. HisType: his_type,
  6463. HisZone: his_zone,
  6464. StartTime: startTime,
  6465. EndTime: endTime,
  6466. StartTimeOne: startTimeOne,
  6467. EndTimeOne: endTimeOne,
  6468. PatientAddress: patient_address,
  6469. }
  6470. //病人转出
  6471. if lapse_type == 2 {
  6472. service.UpdatePatientLapsetoByPatientId(patient_id, recordDate, lapse_reason)
  6473. service.UpdateScheduleByDeathTime(patient_id, recordDate)
  6474. service.UpdateScheduleItemByPatientId(patient_id)
  6475. }
  6476. //病人转出
  6477. if lapse_type == 3 {
  6478. service.UpdatePatientLapsetoByPatientIdOne(patient_id, recordDate, lapse_reason)
  6479. service.UpdateScheduleByDeathTime(patient_id, recordDate)
  6480. service.UpdateScheduleItemByPatientId(patient_id)
  6481. }
  6482. if lapse_type == 11 {
  6483. service.UpdatePatientLasetoType(patient_id, lapse_type)
  6484. }
  6485. //病人转出
  6486. if lapse_type == 1 {
  6487. service.UpdatePatientLapsetoByPatientIdTwo(patient_id, recordDate)
  6488. }
  6489. service.CreatePatientRecord(record)
  6490. c.ServeSuccessJSON(map[string]interface{}{
  6491. "record": record,
  6492. })
  6493. }
  6494. func (c *PatientApiController) GetPatientLapsorecord() {
  6495. id, _ := c.GetInt64("id")
  6496. lapsorecord, _ := service.GetPatientLapsorecord(id)
  6497. c.ServeSuccessJSON(map[string]interface{}{
  6498. "lapsorecord": lapsorecord,
  6499. })
  6500. }
  6501. func (this *DialysisApiController) GetPatientLapseRecord() {
  6502. patient_id, _ := this.GetInt64("patient_id")
  6503. limit, _ := this.GetInt64("limit")
  6504. page, _ := this.GetInt64("page")
  6505. orgId := this.GetAdminUserInfo().CurrentOrgId
  6506. record, total, _ := service.GetPatientLapseRecord(patient_id, limit, page, orgId)
  6507. this.ServeSuccessJSON(map[string]interface{}{
  6508. "record": record,
  6509. "total": total,
  6510. })
  6511. }
  6512. func (c *DialysisApiController) UpdatePatientLapseRecord() {
  6513. dataBody := make(map[string]interface{}, 0)
  6514. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6515. fmt.Println(err)
  6516. patient_id := int64(dataBody["patient_id"].(float64))
  6517. admin_user_id := int64(dataBody["admin_user_id"].(float64))
  6518. lapse_class := int64(dataBody["lapse_class"].(float64))
  6519. lapse_type := int64(dataBody["lapse_type"].(float64))
  6520. lapse_reason := dataBody["lapse_reason"].(string)
  6521. record_date := dataBody["record_date"].(string)
  6522. lapse_type_name := dataBody["lapse_type_name"].(string)
  6523. his_bed := dataBody["his_bed"].(string)
  6524. his_zone := dataBody["his_zone"].(string)
  6525. his_type := int64(dataBody["his_type"].(float64))
  6526. patient_address := dataBody["patient_address"].(string)
  6527. start_time := dataBody["start_time"].(string)
  6528. end_time := dataBody["end_time"].(string)
  6529. start_time_one := dataBody["start_time_one"].(string)
  6530. end_time_one := dataBody["end_time_one"].(string)
  6531. timeLayout := "2006-01-02"
  6532. loc, _ := time.LoadLocation("Local")
  6533. var recordDate int64
  6534. if len(record_date) > 0 {
  6535. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6536. if err != nil {
  6537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6538. return
  6539. }
  6540. recordDate = theTime.Unix()
  6541. }
  6542. var startTime int64
  6543. if len(start_time) > 0 {
  6544. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6545. if err != nil {
  6546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6547. return
  6548. }
  6549. startTime = theTime.Unix()
  6550. }
  6551. var endTime int64
  6552. if len(end_time) > 0 {
  6553. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6554. if err != nil {
  6555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6556. return
  6557. }
  6558. endTime = theTime.Unix()
  6559. }
  6560. var startTimeOne int64
  6561. if len(start_time_one) > 0 {
  6562. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_one+" 00:00:00", loc)
  6563. if err != nil {
  6564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6565. return
  6566. }
  6567. startTimeOne = theTime.Unix()
  6568. }
  6569. var endTimeOne int64
  6570. if len(end_time_one) > 0 {
  6571. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_one+" 00:00:00", loc)
  6572. if err != nil {
  6573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6574. return
  6575. }
  6576. endTimeOne = theTime.Unix()
  6577. }
  6578. remark := dataBody["remark"].(string)
  6579. id := int64(dataBody["id"].(float64))
  6580. org_id := c.GetAdminUserInfo().CurrentOrgId
  6581. record := models.XtPatientLaspseRecord{
  6582. ID: id,
  6583. PatientId: patient_id,
  6584. RecordDate: recordDate,
  6585. LapseDate: recordDate,
  6586. LapseType: lapse_type,
  6587. LapseClass: lapse_class,
  6588. LapseReason: lapse_reason,
  6589. AdminUserId: admin_user_id,
  6590. Remark: remark,
  6591. UserOrgId: org_id,
  6592. Ctime: time.Now().Unix(),
  6593. Mtime: time.Now().Unix(),
  6594. Status: 1,
  6595. LapseTypeName: lapse_type_name,
  6596. HisZone: his_zone,
  6597. HisBed: his_bed,
  6598. HisType: his_type,
  6599. StartTime: startTime,
  6600. StartTimeOne: startTimeOne,
  6601. EndTime: endTime,
  6602. EndTimeOne: endTimeOne,
  6603. PatientAddress: patient_address,
  6604. }
  6605. //病人转出
  6606. if lapse_type == 2 {
  6607. service.UpdatePatientLapsetoByPatientId(patient_id, recordDate, lapse_reason)
  6608. service.UpdateScheduleByDeathTime(patient_id, recordDate)
  6609. service.UpdateScheduleItemByPatientId(patient_id)
  6610. }
  6611. if lapse_type == 3 {
  6612. service.UpdatePatientLapsetoByPatientIdOne(patient_id, recordDate, lapse_reason)
  6613. service.UpdateScheduleByDeathTime(patient_id, recordDate)
  6614. service.UpdateScheduleItemByPatientId(patient_id)
  6615. }
  6616. //病人转出
  6617. if lapse_type == 1 {
  6618. service.UpdatePatientLapsetoByPatientIdTwo(patient_id, recordDate)
  6619. }
  6620. if lapse_type == 11 {
  6621. service.UpdatePatientLasetoType(patient_id, lapse_type)
  6622. }
  6623. service.SavePatientLapseRecord(record)
  6624. c.ServeSuccessJSON(map[string]interface{}{
  6625. "record": record,
  6626. })
  6627. }
  6628. func (c *DialysisApiController) DeletePatientLapseRecord() {
  6629. id, _ := c.GetInt64("id")
  6630. service.DeletePatientLapseRecord(id)
  6631. c.ServeSuccessJSON(map[string]interface{}{
  6632. "msg": "删除成功",
  6633. })
  6634. }
  6635. func (c *DialysisApiController) GetPatientLapseList() {
  6636. fmt.Println("除非哈哈哈哈哈")
  6637. list, _ := service.GetAllpatientFivty()
  6638. if len(list) > 0 {
  6639. for _, item := range list {
  6640. patientLaspseRecord := models.XtPatientLaspseRecord{
  6641. PatientId: item.ID,
  6642. RecordDate: 0,
  6643. LapseDate: item.CreatedTime,
  6644. LapseType: 1,
  6645. LapseClass: 0,
  6646. LapseReason: "",
  6647. AdminUserId: item.RegistrarsId,
  6648. Remark: "",
  6649. UserOrgId: item.UserOrgId,
  6650. Ctime: time.Now().Unix(),
  6651. Mtime: time.Now().Unix(),
  6652. Status: 1,
  6653. LapseTypeName: "",
  6654. HisType: 0,
  6655. HisZone: "",
  6656. HisBed: "",
  6657. PatientAddress: "",
  6658. StartTime: 0,
  6659. EndTime: 0,
  6660. StartTimeOne: 0,
  6661. EndTimeOne: 0,
  6662. }
  6663. service.CreatePatientRecord(patientLaspseRecord)
  6664. }
  6665. }
  6666. //list, _ := service.GetPatientLapsorecordListOne()
  6667. //
  6668. //if len(list) > 0 {
  6669. // for _, item := range list {
  6670. // //查询患者的信息
  6671. // patients, _ := service.GetPatientByIDTwoOne(item.PatientId)
  6672. //
  6673. // if patients.Lapseto == 2 || patients.Lapseto == 3 {
  6674. //
  6675. // patientLaspseRecord := models.XtPatientLaspseRecord{
  6676. // PatientId: item.PatientId,
  6677. // RecordDate: patients.DeathTime,
  6678. // LapseDate: patients.DeathTime,
  6679. // LapseType: patients.Lapseto,
  6680. // LapseClass: patients.Lapseto,
  6681. // LapseReason: patients.OutReason,
  6682. // AdminUserId: 0,
  6683. // Remark: "",
  6684. // UserOrgId: patients.UserOrgId,
  6685. // Ctime: time.Now().Unix(),
  6686. // Mtime: time.Now().Unix(),
  6687. // Status: 1,
  6688. // LapseTypeName: "",
  6689. // HisType: 0,
  6690. // HisZone: "",
  6691. // HisBed: "",
  6692. // PatientAddress: "",
  6693. // StartTime: patients.PatientStartTime,
  6694. // EndTime: patients.PatientEndTime,
  6695. // StartTimeOne: patients.PatientStartTime,
  6696. // EndTimeOne: patients.PatientEndTime,
  6697. // }
  6698. //
  6699. // service.CreatePatientRecord(patientLaspseRecord)
  6700. // }
  6701. // }
  6702. //}
  6703. //fmt.Println("lsit", list)
  6704. //for _, item := range list {
  6705. //
  6706. //
  6707. //}
  6708. }