patient_api_controller.go 294KB

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