dialysis_api_controller.go 233KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101
  1. package controllers
  2. import (
  3. "XT_New/models"
  4. "XT_New/service"
  5. "XT_New/utils"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/jinzhu/gorm"
  9. "math"
  10. "reflect"
  11. "strconv"
  12. "strings"
  13. //"strings"
  14. "time"
  15. "XT_New/enums"
  16. "github.com/astaxie/beego"
  17. )
  18. type DialysisApiController struct {
  19. BaseAuthAPIController
  20. }
  21. func DialysisApiRegistRouters() {
  22. beego.Router("/api/dialysis/device", &DialysisApiController{}, "get:GetDeviceList")
  23. beego.Router("/api/dialysis/patients", &DialysisApiController{}, "get:GetDialysisWatch")
  24. beego.Router("/api/dialysis/zone", &DialysisApiController{}, "get:GetAllDeviceZone")
  25. beego.Router("/api/dialysis/info", &DialysisApiController{}, "get:GetSchedualPatientsInfo")
  26. beego.Router("/api/dialysis/advice/create", &DialysisApiController{}, "Post:CreateDoctorAdvice")
  27. beego.Router("/api/dialysis/advice/get", &DialysisApiController{}, "Get:GetDoctorAdvice")
  28. beego.Router("/api/dialysis/advice/edit", &DialysisApiController{}, "put:EditDoctorAdvice")
  29. beego.Router("/api/dialysis/monitor/create", &DialysisApiController{}, "Post:CreateMonitor")
  30. beego.Router("/api/dialysis/monitor/del", &DialysisApiController{}, "Post:DelMonitor")
  31. beego.Router("/api/dialysis/dialysisorder", &DialysisApiController{}, "Get:GetDialysisOrder")
  32. beego.Router("/api/dialysis/prescription", &DialysisApiController{}, "Post:PostPrescription")
  33. beego.Router("/api/dialysis/soulution", &DialysisApiController{}, "Post:PostSoulution")
  34. beego.Router("/api/dialysis/dobule", &DialysisApiController{}, "Post:PostDouleCheck")
  35. beego.Router("/api/dialysis/accepts", &DialysisApiController{}, "Post:PostReceiveTreatmentAsses")
  36. beego.Router("/api/dialysis/assessmentbeforedislysis", &DialysisApiController{}, "Post:PostAssessmentBeforeDislysis")
  37. beego.Router("/api/dialysis/assessmentafterdislysis", &DialysisApiController{}, "Post:PostAssessmentAfterDislysis")
  38. beego.Router("/api/dialysis/treatmentsummary", &DialysisApiController{}, "Post:PostTreatmentSummary")
  39. beego.Router("/api/dialysis/advice_remind", &DialysisApiController{}, "Get:GetLongAdvice")
  40. beego.Router("/api/dialysis/advice_remind/one", &DialysisApiController{}, "Get:GetLongAdviceOne")
  41. beego.Router("/api/dialysis/advice_remind/two", &DialysisApiController{}, "Get:GetLongAdviceTwo")
  42. beego.Router("/api/advice_remind/create", &DialysisApiController{}, "Post:CreateRemindDoctorAdvice")
  43. beego.Router("/api/solution/get", &DialysisApiController{}, "Get:GetSolution")
  44. beego.Router("/api/schedule/get", &DialysisApiController{}, "Get:GetSchedule")
  45. beego.Router("/api/today_monitor/get", &DialysisApiController{}, "Get:GetTodayMonitor")
  46. beego.Router("/api/dryweight/commit", &DialysisApiController{}, "Post:UploadDryWeight")
  47. beego.Router("/api/func_per/get", &DialysisApiController{}, "Get:GetFuncPurview")
  48. beego.Router("/api/doctoradvice/get", &DialysisApiController{}, "Get:GetLastOrNextDoctorAdvice")
  49. beego.Router("/api/dialysisgoods/get", &DialysisApiController{}, "Get:GetDialysisGoods")
  50. beego.Router("/api/goodstatistics/get", &DialysisApiController{}, "Get:GetDialysisGoodsStatistics")
  51. beego.Router("/api/queue/get", &DialysisApiController{}, "Get:GetQueueCall")
  52. beego.Router("/api/queue/update", &DialysisApiController{}, "Get:UpdateQueueCall")
  53. beego.Router("/api/get/getrolelist", &DialysisApiController{}, "Get:GetRoleList")
  54. beego.Router("/api/getinitprintdata", &DialysisApiController{}, "Get:GetInitPrintData")
  55. beego.Router("/api/schedule/getorderdoctoradvice", &DialysisApiController{}, "Get:GetOrderDoctorAdvice")
  56. beego.Router("/api/getinitprintdateone", &DialysisApiController{}, "Get:GetInitPrintDataOne")
  57. //新接口
  58. beego.Router("/api/patient/getpatientdialysissolutiongrouplist", &DialysisApiController{}, "Get:GetPatientDialysisSolutionGroupList")
  59. beego.Router("/api/patient/getdialysisadvicetemplatelist", &DialysisApiController{}, "Get:GetDialysisAdviceTemplateList")
  60. beego.Router("/api/patient/savedialysissetting", &DialysisApiController{}, "Get:SaveDialysisSetting")
  61. beego.Router("/api/patient/getdialysissetting", &DialysisApiController{}, "Get:GetDialysisSetting")
  62. beego.Router("/api/patient/getdialysisparameter", &DialysisApiController{}, "Get:GetDialysisParameterList")
  63. beego.Router("/api/patient/getdialysisgoodtotalcount", &DialysisApiController{}, "Get:GetDialysisGoodTotalCount")
  64. beego.Router("/api/patient/getdialysisadvicescheduelist", &DialysisApiController{}, "Get:GetDialysisAdviceSchedulist")
  65. beego.Router("/api/patient/getdialysisparametergoodlist", &DialysisApiController{}, "Get:GetDialysisParameterGoodList")
  66. beego.Router("/api/patient/savehisdialysis", &DialysisApiController{}, "Get:SaveHisDialysis")
  67. beego.Router("/api/patient/gethisdialysisgoodcount", &DialysisApiController{}, "Get:GetHisDialysisGoodCount")
  68. beego.Router("/api/schedule/getpatientshedule", &DialysisApiController{}, "Get:GetPatientSchedule")
  69. beego.Router("/api/patient/getscheduleprintlist", &DialysisApiController{}, "Get:GetSchedulePrintList")
  70. beego.Router("/api/patient/getsolutionlistbyorgid", &DialysisApiController{}, "Get:GetSolutionListByOrgId")
  71. beego.Router("/api/schedule/excutiondoctoradvice", &DialysisApiController{}, "Get:ExcutionDoctorAdvice")
  72. beego.Router("/api/schedule/checknewdoctoradvice", &DialysisApiController{}, "Get:CheckNewDoctorAdvice")
  73. beego.Router("/api/schedule/settlenewdoctoradvice", &DialysisApiController{}, "Get:SettleNewDoctorAdvice")
  74. beego.Router("/api/schedule/excutiondoctoradvicebyid", &DialysisApiController{}, "Get:ExcutionDoctorAdviceById")
  75. beego.Router("/api/patient/getdialysisadvicetoday", &DialysisApiController{}, "Get:GetDialysisAdviceToday")
  76. beego.Router("/api/schedule/getmobileschedulelist", &DialysisApiController{}, "Get:GetMobileScheduleList")
  77. }
  78. func (c *DialysisApiController) GetQueueCall() {
  79. adminUserInfo := c.GetAdminUserInfo()
  80. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  81. if queueConfig.ID <= 0 {
  82. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  83. queueConfig.Qhsj = 10
  84. queueConfig.Jzdcbbcs = 3
  85. queueConfig.Jzbbsy = 1
  86. queueConfig.Jzjhyc = 0
  87. queueConfig.Sjdcbbcs = 3
  88. queueConfig.Sjbbsy = 0
  89. queueConfig.Sjjhyc = 0
  90. queueConfig.Txxqyxs = 0
  91. queueConfig.Txglsyxs = 0
  92. }
  93. c.ServeSuccessJSON(map[string]interface{}{
  94. "queue_config": queueConfig,
  95. })
  96. }
  97. func (c *DialysisApiController) UpdateQueueCall() {
  98. adminUserInfo := c.GetAdminUserInfo()
  99. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  100. if queueConfig.ID <= 0 {
  101. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  102. queueConfig.Qhsj = 10
  103. queueConfig.Jzdcbbcs = 3
  104. queueConfig.Jzbbsy = 1
  105. queueConfig.Jzjhyc = 0
  106. queueConfig.Sjdcbbcs = 3
  107. queueConfig.Sjbbsy = 0
  108. queueConfig.Sjjhyc = 0
  109. queueConfig.Txxqyxs = 0
  110. queueConfig.Txglsyxs = 0
  111. queueConfig.CreateTime = time.Now().Unix()
  112. queueConfig.UpdateTime = time.Now().Unix()
  113. }
  114. qhsj, _ := c.GetInt64("qhsj", 0)
  115. if qhsj > 0 {
  116. queueConfig.Qhsj = qhsj
  117. }
  118. jzdcbbcs, _ := c.GetInt64("jzdcbbcs", 0)
  119. if jzdcbbcs > 0 {
  120. queueConfig.Jzdcbbcs = jzdcbbcs
  121. }
  122. jzbbsy, _ := c.GetInt64("jzbbsy", 0)
  123. if jzbbsy > 0 {
  124. queueConfig.Jzbbsy = jzbbsy
  125. }
  126. jzjhyc, _ := c.GetInt64("jzjhyc", 0)
  127. queueConfig.Jzjhyc = jzjhyc
  128. sjdcbbcs, _ := c.GetInt64("sjdcbbcs", 0)
  129. if sjdcbbcs > 0 {
  130. queueConfig.Sjdcbbcs = sjdcbbcs
  131. }
  132. sjbbsy, _ := c.GetInt64("sjbbsy", 0)
  133. if sjbbsy > 0 {
  134. queueConfig.Sjbbsy = sjbbsy
  135. }
  136. sjjhyc, _ := c.GetInt64("sjjhyc", 0)
  137. queueConfig.Sjjhyc = sjjhyc
  138. txxqyxs, _ := c.GetInt64("txxqyxs", 0)
  139. queueConfig.Txxqyxs = txxqyxs
  140. txglsyxs, _ := c.GetInt64("txglsyxs", 0)
  141. queueConfig.Txglsyxs = txglsyxs
  142. queueConfig.UpdateTime = time.Now().Unix()
  143. service.UpDateQueueCallInfo(queueConfig)
  144. c.ServeSuccessJSON(map[string]interface{}{
  145. "queue_config": queueConfig,
  146. })
  147. }
  148. func (c *DialysisApiController) PostPrescription() {
  149. patient, _ := c.GetInt64("patient_id", 0)
  150. recordDateStr := c.GetString("record_date")
  151. if patient <= 0 {
  152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  153. return
  154. }
  155. adminUserInfo := c.GetAdminUserInfo()
  156. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  157. if patientInfo.ID == 0 {
  158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  159. return
  160. }
  161. if len(recordDateStr) == 0 {
  162. recordDateStr = time.Now().Format("2006-01-02")
  163. }
  164. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  165. if parseDateErr != nil {
  166. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. return
  169. }
  170. mode_id, _ := c.GetInt64("mode_id", 0)
  171. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  172. dialyzer, _ := c.GetInt64("dialyzer", 0)
  173. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  174. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  175. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  176. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  177. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  178. replacement_way, _ := c.GetInt64("replacement_way", 0)
  179. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  180. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  181. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  182. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  183. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  184. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  185. kalium, _ := c.GetFloat("kalium", 0)
  186. sodium, _ := c.GetFloat("sodium", 0)
  187. replacement_total, _ := c.GetFloat("replacement_total", 0)
  188. calcium, _ := c.GetFloat("calcium", 0)
  189. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  190. glucose, _ := c.GetFloat("glucose", 0)
  191. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  192. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  193. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  194. conductivity, _ := c.GetFloat("conductivity", 0)
  195. remark := c.GetString("remark")
  196. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  197. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  198. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  199. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  200. body_fluid, _ := c.GetInt64("body_fluid", 0)
  201. special_medicine, _ := c.GetInt64("special_medicine", 0)
  202. special_medicine_other := c.GetString("special_medicine_other")
  203. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  204. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  205. blood_access, _ := c.GetInt64("blood_access", 0)
  206. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  207. body_fluid_other := c.GetString("body_fluid_other")
  208. target_ktv, _ := c.GetFloat("target_ktv", 0)
  209. niprocart, _ := c.GetInt64("niprocart", 0)
  210. jms, _ := c.GetInt64("jms", 0)
  211. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  212. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  213. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  214. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  215. filtryzer, _ := c.GetInt64("filtryzer", 0)
  216. dialyzers, _ := c.GetInt64("dialyzers", 0)
  217. injector, _ := c.GetInt64("injector", 0)
  218. bloodlines, _ := c.GetInt64("bloodlines", 0)
  219. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  220. safe_package, _ := c.GetInt64("package", 0)
  221. a_liquid, _ := c.GetInt64("a_liquid", 0)
  222. preImpules, _ := c.GetFloat("pre_impulse", 0)
  223. fmt.Println("", preImpules)
  224. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  225. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  226. //heparin_sodium := c.GetString("heparin_sodium")
  227. //fmt.Println("肝素钠",heparin_sodium)
  228. //nucleoprotamine := c.GetString("nucleoprotamine")
  229. //fmt.Println("鱼精蛋白",nucleoprotamine)
  230. //push_the_protamine := c.GetString("push_the_protamine")
  231. //fmt.Println("下机前推注鱼精蛋白",push_the_protamine)
  232. // var prescription_doctor int64
  233. blood := c.GetString("blood")
  234. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  235. dialysis_irrigation := c.GetString("dialysis_irrigation")
  236. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  237. displace_speed := c.GetString("displace_speed")
  238. illness, _ := c.GetInt64("illness")
  239. amylaceum := c.GetString("amylaceum")
  240. single_time := c.GetString("single_time")
  241. single_water := c.GetString("single_water")
  242. replacement_flow := c.GetString("replacement_flow")
  243. plasma_separator := c.GetString("plasma_separator")
  244. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  245. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  246. oxygen_flow := c.GetString("oxygen_flow")
  247. oxygen_time := c.GetString("oxygen_time")
  248. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  249. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  250. puncture_needle := c.GetString("puncture_needle")
  251. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  252. epo := c.GetString("epo")
  253. epo_count, _ := c.GetFloat("epo_count", 0)
  254. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  255. admin_user_id, _ := c.GetInt64("admin_user_id")
  256. is_water, _ := c.GetInt64("is_water")
  257. drhy_water := c.GetString("drhy_water")
  258. dry_water_hour := c.GetString("dry_water_hour")
  259. water_machine := c.GetString("water_machine")
  260. add_amount, _ := c.GetFloat("add_amount")
  261. reduce_amount, _ := c.GetFloat("reduce_amount")
  262. dialysis_remark := c.GetString("dialysis_remark")
  263. prescribing_number, _ := c.GetFloat("prescribing_number")
  264. treatment_remark := c.GetString("treatment_remark")
  265. prescription_sodium := c.GetString("prescription_sodium")
  266. start_sodium := c.GetString("start_sodium")
  267. sodium_curve := c.GetString("sodium_curve")
  268. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  269. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  270. prescription_water, _ := c.GetFloat("prescription_water")
  271. dialysis_strainer := c.GetString("dialysis_strainer")
  272. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  273. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  274. //if template.TemplateId == 2 || template.TemplateId == 6 {
  275. // if appRole.UserType == 3 {
  276. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  277. // if getPermissionErr != nil {
  278. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  279. // return
  280. // } else if headNursePermission == nil {
  281. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  282. // return
  283. // }
  284. // }
  285. //}
  286. prescription := models.DialysisPrescription{
  287. UserOrgId: adminUserInfo.CurrentOrgId,
  288. PatientId: patient,
  289. RecordDate: recordDate.Unix(),
  290. ModeId: mode_id,
  291. DialysisDuration: dialysis_duration,
  292. Dialyzer: dialyzer,
  293. ReplacementTotal: replacement_total,
  294. PerfusionApparatus: perfusion_apparatus,
  295. BloodFlowVolume: blood_flow_volume,
  296. DewaterAmount: dewater_amount,
  297. DisplaceLiqui: displace_liqui,
  298. ReplacementWay: replacement_way,
  299. Anticoagulant: anticoagulant,
  300. AnticoagulantShouji: anticoagulant_shouji,
  301. AnticoagulantWeichi: anticoagulant_weichi,
  302. AnticoagulantZongliang: anticoagulant_zongliang,
  303. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  304. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  305. Kalium: kalium,
  306. Sodium: sodium,
  307. Calcium: calcium,
  308. Bicarbonate: bicarbonate,
  309. Glucose: glucose,
  310. // DryWeight: dry_weight,
  311. DialysateFlow: dialysate_flow,
  312. DialysateTemperature: dialysate_temperature,
  313. Conductivity: conductivity,
  314. Remark: remark,
  315. Status: 1,
  316. CreatedTime: time.Now().Unix(),
  317. UpdatedTime: time.Now().Unix(),
  318. DialysisDurationMinute: dialysisDurationMinute,
  319. DialysisDurationHour: dialysisDurationHour,
  320. TargetUltrafiltration: targetUltrafiltration,
  321. DialysateFormulation: dialysateFormulation,
  322. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  323. BodyFluid: body_fluid,
  324. SpecialMedicine: special_medicine,
  325. SpecialMedicineOther: special_medicine_other,
  326. DisplaceLiquiPart: displace_liqui_part,
  327. DisplaceLiquiValue: displace_liqui_value,
  328. BloodAccess: blood_access,
  329. Ultrafiltration: ultrafiltration,
  330. BodyFluidOther: body_fluid_other,
  331. TargetKtv: target_ktv,
  332. Niprocart: niprocart,
  333. Jms: jms,
  334. FistulaNeedleSet: fistula_needle_set,
  335. FistulaNeedleSet16: fistula_needle_set_16,
  336. Hemoperfusion: hemoperfusion,
  337. DialyserSterilised: dialyser_sterilised,
  338. Filtryzer: filtryzer,
  339. Dialyzers: dialyzers,
  340. Injector: injector,
  341. Bloodlines: bloodlines,
  342. TubingHemodialysis: tubing_hemodialysis,
  343. Package: safe_package,
  344. ALiquid: a_liquid,
  345. PreImpulse: preImpules,
  346. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  347. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  348. Blood: blood,
  349. DialysisDialyszers: dialysis_dialyszers,
  350. DialysisIrrigation: dialysis_irrigation,
  351. AntioxidantCommodityName: antioxidant_commodity_name,
  352. DisplaceSpeed: displace_speed,
  353. Illness: illness,
  354. Amylaceum: amylaceum,
  355. SingleTime: single_time,
  356. SingleWater: single_water,
  357. ReplacementFlow: replacement_flow,
  358. PlasmaSeparator: plasma_separator,
  359. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  360. OxygenFlow: oxygen_flow,
  361. OxygenUptake: oxygen_uptake,
  362. OxygenTime: oxygen_time,
  363. HemodialysisPipelines: hemodialysis_pipelines,
  364. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  365. PunctureNeedle: puncture_needle,
  366. PunctureNeedleCount: puncture_needle_count,
  367. Epo: epo,
  368. EpoCount: epo_count,
  369. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  370. AdminUserId: admin_user_id,
  371. IsWater: is_water,
  372. DrhyWater: drhy_water,
  373. DryWaterHour: dry_water_hour,
  374. WaterMachine: water_machine,
  375. AddAmount: add_amount,
  376. ReduceAmount: reduce_amount,
  377. DialysisRemark: dialysis_remark,
  378. PrescribingNumber: prescribing_number,
  379. TreatmentRemark: treatment_remark,
  380. PrescriptionSodium: prescription_sodium,
  381. StartSodium: start_sodium,
  382. SodiumCurve: sodium_curve,
  383. DialysisFluidFlow: dialysis_fluid_flow,
  384. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  385. PrescriptionWater: prescription_water,
  386. DialysisStrainer: dialysis_strainer,
  387. }
  388. //长沙南雅医院,自动生成抗凝剂的临时处方
  389. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  390. if prescribing_number == 0 {
  391. prescribing_number = 1
  392. }
  393. advice := models.DoctorAdvice{
  394. UserOrgId: adminUserInfo.CurrentOrgId,
  395. PatientId: patient,
  396. GroupNo: 0,
  397. AdviceType: 2,
  398. RecordDate: recordDate.Unix(),
  399. AdviceDate: recordDate.Unix(),
  400. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  401. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  402. AdviceDesc: "",
  403. ReminderDate: 0,
  404. SingleDose: anticoagulant_zongliang,
  405. SingleDoseUnit: "iu",
  406. DrugSpec: 0,
  407. DrugSpecUnit: "",
  408. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  409. PrescribingNumberUnit: "支",
  410. DeliveryWay: "静脉注射",
  411. ExecutionFrequency: "上机前",
  412. AdviceDoctor: 0,
  413. Status: 1,
  414. CreatedTime: time.Now().Unix(),
  415. UpdatedTime: time.Now().Unix(),
  416. IsPrescription: 1,
  417. ExecutionState: 2,
  418. StopState: 2,
  419. IsSettle: 2,
  420. }
  421. // 查询排班信息
  422. schedulePatient, _ := service.GetScheduleByPatient(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  423. if schedulePatient.ID > 0 {
  424. if schedulePatient.ScheduleType == 1 {
  425. advice.StartTime = recordDate.Unix() + 6.5*60*60
  426. }
  427. if schedulePatient.ScheduleType == 2 {
  428. advice.StartTime = recordDate.Unix() + 11*60*60
  429. }
  430. }
  431. // 抗凝剂名称
  432. switch anticoagulant {
  433. case 1:
  434. advice.AdviceName = "无肝素"
  435. break
  436. case 2:
  437. advice.AdviceName = "普通肝素"
  438. break
  439. case 3:
  440. advice.AdviceName = "低分子肝素"
  441. break
  442. case 4:
  443. advice.AdviceName = "阿加曲班"
  444. break
  445. case 5:
  446. advice.AdviceName = "枸橼酸钠"
  447. break
  448. case 6:
  449. advice.AdviceName = "低分子肝素钙"
  450. break
  451. case 7:
  452. advice.AdviceName = "低分子肝素钠"
  453. break
  454. case 8:
  455. advice.AdviceName = "依诺肝素"
  456. break
  457. case 9:
  458. advice.AdviceName = "达肝素"
  459. break
  460. case 10:
  461. advice.AdviceName = "体外抗凝"
  462. break
  463. case 11:
  464. advice.AdviceName = "那曲肝素"
  465. break
  466. case 12:
  467. advice.AdviceName = "无抗凝剂"
  468. break
  469. }
  470. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  471. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 {
  472. advice.AdviceDoctor = appRole.AdminUserId
  473. }
  474. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  475. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  476. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  477. advice.AdviceName = "低分子肝素钠注射液"
  478. // 修改患者临时医嘱里的抗凝剂医嘱
  479. advice.ID = advicePrescription.ID
  480. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  481. //service.UpdateDoctorAdvice(&advice)
  482. } else {
  483. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  484. advice.AdviceName = "低分子肝素钠注射液"
  485. // 新增患者临时医嘱里的抗凝剂医嘱
  486. service.CreateDoctorAdvice(&advice)
  487. }
  488. }
  489. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  490. redis := service.RedisClient()
  491. //清空key 值
  492. redis.Set(key, "", time.Second)
  493. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  494. redis.Set(keyOne, "", time.Second)
  495. }
  496. if appRole.UserType == 2 || appRole.UserType == 1 {
  497. prescription.PrescriptionDoctor = appRole.AdminUserId
  498. }
  499. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  500. if dialysisPrescription.ID == 0 { //新增
  501. if mode_id > 0 {
  502. var str string
  503. //查找该机构用的是什么透析器
  504. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  505. if filedConfig.ID > 0 {
  506. str = dialyzerPerfusionApparatus
  507. } else {
  508. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  509. }
  510. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  511. }
  512. prescription.Creater = adminUserInfo.AdminUser.Id
  513. //针对河间咸得
  514. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  515. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  516. prescription.DisplaceLiquiPart = 0
  517. prescription.DisplaceLiquiValue = 0
  518. }
  519. }
  520. if adminUserInfo.CurrentOrgId == 10340 && prescription.AdminUserId == 0 {
  521. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  522. }
  523. err := service.AddSigleRecord(&prescription)
  524. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  525. redis := service.RedisClient()
  526. //清空key 值
  527. redis.Set(key, "", time.Second)
  528. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  529. redis.Set(keyTwo, "", time.Second)
  530. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  531. redis.Set(keyThree, "", time.Second)
  532. defer redis.Close()
  533. if err == nil {
  534. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  535. if updateErr != nil {
  536. utils.ErrorLog("%v", updateErr)
  537. }
  538. c.ServeSuccessJSON(map[string]interface{}{
  539. "prescription": &prescription,
  540. })
  541. } else {
  542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  543. }
  544. } else { //修改
  545. if mode_id > 0 {
  546. var str string
  547. //查找该机构用的是什么透析器
  548. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  549. if filedConfig.ID > 0 {
  550. str = dialyzerPerfusionApparatus
  551. } else {
  552. str = dialysis_dialyszers + "/" + dialysis_irrigation
  553. }
  554. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  555. }
  556. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  557. //if template.TemplateId == 1 {
  558. // if dialysisPrescription.Creater > 0 && dialysisPrescription.Creater != adminUserInfo.AdminUser.Id {
  559. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  560. // if getPermissionErr != nil {
  561. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  562. // return
  563. // } else if headNursePermission == nil {
  564. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  565. // return
  566. // }
  567. // }
  568. //}
  569. if appRole.UserType == 2 || appRole.UserType == 1 {
  570. prescription_doctor := adminUserInfo.AdminUser.Id
  571. prescription.PrescriptionDoctor = prescription_doctor
  572. }
  573. if dialysisPrescription.Creater == 0 { //体重称
  574. prescription.Creater = adminUserInfo.AdminUser.Id
  575. } else {
  576. prescription.Creater = dialysisPrescription.Creater
  577. }
  578. prescription.CreatedTime = dialysisPrescription.CreatedTime
  579. prescription.UpdatedTime = time.Now().Unix()
  580. prescription.Modifier = adminUserInfo.AdminUser.Id
  581. prescription.ID = dialysisPrescription.ID
  582. updateErr := service.UpDateDialysisPrescription(&prescription)
  583. //修改处方
  584. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  585. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  586. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  587. if advicePrescription.ID > 0 {
  588. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  589. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  590. redis := service.RedisClient()
  591. defer redis.Close()
  592. //清空key 值
  593. redis.Set(key, "", time.Second)
  594. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  595. redis.Set(keyOne, "", time.Second)
  596. }
  597. }
  598. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  599. redis := service.RedisClient()
  600. defer redis.Close()
  601. //清空key 值
  602. redis.Set(key, "", time.Second)
  603. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  604. redis.Set(keyOne, "", time.Second)
  605. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  606. redis.Set(keyThree, "", time.Second)
  607. if updateErr == nil {
  608. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  609. if updateErr != nil {
  610. utils.ErrorLog("%v", updateErr)
  611. }
  612. c.ServeSuccessJSON(map[string]interface{}{
  613. "prescription": &prescription,
  614. })
  615. } else {
  616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  617. }
  618. }
  619. }
  620. func (c *DialysisApiController) PostSoulution() {
  621. patient, _ := c.GetInt64("patient", 0)
  622. recordDateStr := c.GetString("record_date")
  623. if patient <= 0 {
  624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  625. return
  626. }
  627. adminUserInfo := c.GetAdminUserInfo()
  628. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  629. if patientInfo.ID == 0 {
  630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  631. return
  632. }
  633. if len(recordDateStr) == 0 {
  634. recordDateStr = time.Now().Format("2006-01-02")
  635. }
  636. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  637. if parseDateErr != nil {
  638. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  640. return
  641. }
  642. mode_id, _ := c.GetInt64("mode_id", 0)
  643. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  644. dialyzer, _ := c.GetInt64("dialyzer", 0)
  645. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  646. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  647. replacement_total, _ := c.GetFloat("replacement_total", 0)
  648. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  649. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  650. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  651. replacement_way, _ := c.GetInt64("replacement_way", 0)
  652. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  653. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  654. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  655. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  656. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  657. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  658. kalium, _ := c.GetFloat("kalium", 0)
  659. sodium, _ := c.GetFloat("sodium", 0)
  660. calcium, _ := c.GetFloat("calcium", 0)
  661. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  662. glucose, _ := c.GetFloat("glucose", 0)
  663. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  664. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  665. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  666. conductivity, _ := c.GetFloat("conductivity", 0)
  667. remark := c.GetString("remark")
  668. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  669. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  670. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  671. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  672. body_fluid, _ := c.GetInt64("body_fluid", 0)
  673. special_medicine, _ := c.GetInt64("special_medicine", 0)
  674. special_medicine_other := c.GetString("special_medicine_other")
  675. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  676. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  677. blood_access, _ := c.GetInt64("blood_access", 0)
  678. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  679. body_fluid_other := c.GetString("body_fluid_other")
  680. target_ktv, _ := c.GetFloat("target_ktv", 0)
  681. niprocart, _ := c.GetInt64("niprocart", 0)
  682. jms, _ := c.GetInt64("jms", 0)
  683. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  684. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  685. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  686. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  687. filtryzer, _ := c.GetInt64("filtryzer", 0)
  688. dialyzers, _ := c.GetInt64("dialyzers", 0)
  689. injector, _ := c.GetInt64("injector", 0)
  690. bloodlines, _ := c.GetInt64("bloodlines", 0)
  691. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  692. safe_package, _ := c.GetInt64("package", 0)
  693. a_liquid, _ := c.GetInt64("a_liquid", 0)
  694. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  695. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  696. blood := c.GetString("blood")
  697. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  698. dialysis_irrigation := c.GetString("dialysis_irrigation")
  699. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  700. displace_speed := c.GetString("displace_speed")
  701. illness, _ := c.GetInt64("illness")
  702. amylaceum := c.GetString("amylaceum")
  703. single_time := c.GetString("single_time")
  704. single_water := c.GetString("single_water")
  705. replacement_flow := c.GetString("replacement_flow")
  706. plasma_separator := c.GetString("plasma_separator")
  707. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  708. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  709. oxygen_flow := c.GetString("oxygen_flow")
  710. oxygen_time := c.GetString("oxygen_time")
  711. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  712. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  713. puncture_needle := c.GetString("puncture_needle")
  714. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  715. epo := c.GetString("epo")
  716. epo_count, _ := c.GetFloat("epo_count", 0)
  717. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  718. impulse := c.GetString("impulse")
  719. preImpules, parseDateErr := strconv.ParseFloat(impulse, 64)
  720. admin_user_id, _ := c.GetInt64("admin_user_id")
  721. fmt.Println("", preImpules)
  722. is_water, _ := c.GetInt64("is_water")
  723. dry_water_hour := c.GetString("dry_water_hour")
  724. drhy_water := c.GetString("drhy_water")
  725. water_machine := c.GetString("water_machine")
  726. add_amount, _ := c.GetFloat("add_amount")
  727. reduce_amount, _ := c.GetFloat("reduce_amount")
  728. dialysis_remark := c.GetString("dialysis_remark")
  729. prescribing_number, _ := c.GetFloat("prescribing_number")
  730. treatment_remark := c.GetString("treatment_remark")
  731. prescription_sodium := c.GetString("prescription_sodium")
  732. start_sodium := c.GetString("start_sodium")
  733. sodium_curve := c.GetString("sodium_curve")
  734. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  735. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  736. prescription_water, _ := c.GetFloat("prescription_water")
  737. dialysis_strainer := c.GetString("dialysis_strainer")
  738. var prescription_doctor int64
  739. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  740. if appRole.UserType == 2 || appRole.UserType == 1 {
  741. prescription_doctor = appRole.AdminUserId
  742. }
  743. if mode_id > 0 {
  744. var str string
  745. //查找该机构用的是什么透析器
  746. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  747. if filedConfig.ID > 0 {
  748. str = dialyzerPerfusionApparatus
  749. } else {
  750. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  751. }
  752. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  753. }
  754. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  755. //
  756. //if template.TemplateId == 2 || template.TemplateId == 6 {
  757. // if appRole.UserType == 3 {
  758. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  759. // if getPermissionErr != nil {
  760. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  761. // return
  762. // } else if headNursePermission == nil {
  763. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  764. // return
  765. // }
  766. // }
  767. //}
  768. prescription := models.DialysisPrescription{
  769. UserOrgId: adminUserInfo.CurrentOrgId,
  770. PatientId: patient,
  771. RecordDate: recordDate.Unix(),
  772. ModeId: mode_id,
  773. DialysisDuration: dialysis_duration,
  774. Dialyzer: dialyzer,
  775. PerfusionApparatus: perfusion_apparatus,
  776. BloodFlowVolume: blood_flow_volume,
  777. DewaterAmount: dewater_amount,
  778. DisplaceLiqui: displace_liqui,
  779. ReplacementWay: replacement_way,
  780. Anticoagulant: anticoagulant,
  781. AnticoagulantShouji: anticoagulant_shouji,
  782. AnticoagulantWeichi: anticoagulant_weichi,
  783. AnticoagulantZongliang: anticoagulant_zongliang,
  784. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  785. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  786. Kalium: kalium,
  787. Sodium: sodium,
  788. Calcium: calcium,
  789. Bicarbonate: bicarbonate,
  790. Glucose: glucose,
  791. // DryWeight: dry_weight,
  792. DialysateFlow: dialysate_flow,
  793. DialysateTemperature: dialysate_temperature,
  794. Conductivity: conductivity,
  795. Remark: remark,
  796. PrescriptionDoctor: prescription_doctor,
  797. Status: 1,
  798. CreatedTime: time.Now().Unix(),
  799. UpdatedTime: time.Now().Unix(),
  800. DialysisDurationMinute: dialysisDurationMinute,
  801. DialysisDurationHour: dialysisDurationHour,
  802. TargetUltrafiltration: targetUltrafiltration,
  803. DialysateFormulation: dialysateFormulation,
  804. ReplacementTotal: replacement_total,
  805. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  806. BodyFluid: body_fluid,
  807. SpecialMedicine: special_medicine,
  808. SpecialMedicineOther: special_medicine_other,
  809. DisplaceLiquiPart: displace_liqui_part,
  810. DisplaceLiquiValue: displace_liqui_value,
  811. BloodAccess: blood_access,
  812. Ultrafiltration: ultrafiltration,
  813. BodyFluidOther: body_fluid_other,
  814. TargetKtv: target_ktv,
  815. Niprocart: niprocart,
  816. Jms: jms,
  817. FistulaNeedleSet: fistula_needle_set,
  818. FistulaNeedleSet16: fistula_needle_set_16,
  819. Hemoperfusion: hemoperfusion,
  820. DialyserSterilised: dialyser_sterilised,
  821. Filtryzer: filtryzer,
  822. Dialyzers: dialyzers,
  823. Injector: injector,
  824. Bloodlines: bloodlines,
  825. TubingHemodialysis: tubing_hemodialysis,
  826. Package: safe_package,
  827. ALiquid: a_liquid,
  828. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  829. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  830. Blood: blood,
  831. DialysisIrrigation: dialysis_irrigation,
  832. DialysisDialyszers: dialysis_dialyszers,
  833. AntioxidantCommodityName: antioxidant_commodity_name,
  834. DisplaceSpeed: displace_speed,
  835. Illness: illness,
  836. Amylaceum: amylaceum,
  837. SingleTime: single_time,
  838. SingleWater: single_water,
  839. ReplacementFlow: replacement_flow,
  840. PlasmaSeparator: plasma_separator,
  841. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  842. OxygenTime: oxygen_time,
  843. OxygenUptake: oxygen_uptake,
  844. OxygenFlow: oxygen_flow,
  845. HemodialysisPipelines: hemodialysis_pipelines,
  846. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  847. PunctureNeedle: puncture_needle,
  848. PunctureNeedleCount: puncture_needle_count,
  849. Epo: epo,
  850. EpoCount: epo_count,
  851. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  852. PreImpulse: preImpules,
  853. AdminUserId: admin_user_id,
  854. IsWater: is_water,
  855. DryWaterHour: dry_water_hour,
  856. DrhyWater: drhy_water,
  857. WaterMachine: water_machine,
  858. AddAmount: add_amount,
  859. ReduceAmount: reduce_amount,
  860. DialysisRemark: dialysis_remark,
  861. PrescribingNumber: prescribing_number,
  862. StartSodium: start_sodium,
  863. PrescriptionSodium: prescription_sodium,
  864. SodiumCurve: sodium_curve,
  865. TreatmentRemark: treatment_remark,
  866. DialysisFluidFlow: dialysis_fluid_flow,
  867. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  868. PrescriptionWater: prescription_water,
  869. DialysisStrainer: dialysis_strainer,
  870. }
  871. //查询最近透析准备表里是否存在 透析器 灌流器
  872. //splitStr := strings.Split(dialysis_dialyszers, ",")
  873. //
  874. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  875. //
  876. //mation, _ := service.GetGoodInfoMation(adminUserInfo.CurrentOrgId)
  877. //if len(mation)>0{
  878. // for _, item := range splitStr {
  879. // for _,it := range mation{
  880. // if(item == it.SpecificationName){
  881. //
  882. // //查询最近一次的透析器
  883. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  884. //
  885. // if errcode == gorm.ErrRecordNotFound{
  886. // //插入数据
  887. // prepare := models.DialysisBeforePrepare{
  888. // UserOrgId: adminUserInfo.CurrentOrgId,
  889. // PatientId: patient,
  890. // RecordDate: recordDate.Unix(),
  891. // GoodTypeId: it.GoodTypeId,
  892. // GoodId: it.ID,
  893. // Count: 1,
  894. // Ctime: time.Now().Unix(),
  895. // Creater: adminUserInfo.AdminUser.Id,
  896. // Status:1,
  897. //
  898. // }
  899. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  900. // fmt.Println("",errcode)
  901. // }
  902. // }
  903. // }
  904. //
  905. // }
  906. //
  907. // for _, item := range splitIrrigation {
  908. // for _,it := range mation{
  909. // if(item == it.SpecificationName){
  910. // //查询最近一次的透析器
  911. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  912. // if errcode == gorm.ErrRecordNotFound{
  913. // //插入数据
  914. // prepare := models.DialysisBeforePrepare{
  915. // UserOrgId: adminUserInfo.CurrentOrgId,
  916. // PatientId: patient,
  917. // RecordDate: recordDate.Unix(),
  918. // GoodTypeId: it.GoodTypeId,
  919. // GoodId: it.ID,
  920. // Count: 1,
  921. // Ctime: time.Now().Unix(),
  922. // Creater: adminUserInfo.AdminUser.Id,
  923. // Status:1,
  924. //
  925. // }
  926. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  927. // fmt.Println(errcode)
  928. // }
  929. // }
  930. // }
  931. // }
  932. //}
  933. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  934. if dialysisPrescription.ID == 0 { //新增
  935. if appRole.UserType == 2 || appRole.UserType == 1 {
  936. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  937. }
  938. prescription.Creater = adminUserInfo.AdminUser.Id
  939. } else { //修改
  940. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  941. //if template.TemplateId == 1 {
  942. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  943. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  944. // if getPermissionErr != nil {
  945. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  946. // return
  947. // } else if headNursePermission == nil {
  948. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  949. // return
  950. // }
  951. // }
  952. //}
  953. if appRole.UserType == 2 || appRole.UserType == 1 {
  954. prescription_doctor := adminUserInfo.AdminUser.Id
  955. prescription.PrescriptionDoctor = prescription_doctor
  956. } else {
  957. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  958. }
  959. if dialysisPrescription.Creater == 0 {
  960. prescription.Creater = adminUserInfo.AdminUser.Id
  961. } else {
  962. prescription.Creater = dialysisPrescription.Creater
  963. }
  964. prescription.CreatedTime = dialysisPrescription.CreatedTime
  965. prescription.UpdatedTime = time.Now().Unix()
  966. prescription.Modifier = adminUserInfo.AdminUser.Id
  967. prescription.ID = dialysisPrescription.ID
  968. }
  969. solution := models.DialysisSolution{
  970. RegistrarsId: adminUserInfo.AdminUser.Id,
  971. UserOrgId: adminUserInfo.CurrentOrgId,
  972. Doctor: prescription_doctor,
  973. PatientId: patient,
  974. ModeId: mode_id,
  975. DialysisDuration: dialysis_duration,
  976. PerfusionApparatus: perfusion_apparatus,
  977. BloodFlowVolume: blood_flow_volume,
  978. Dewater: dewater_amount,
  979. DisplaceLiqui: displace_liqui,
  980. ReplacementWay: replacement_way,
  981. Anticoagulant: anticoagulant,
  982. AnticoagulantShouji: anticoagulant_shouji,
  983. AnticoagulantWeichi: anticoagulant_weichi,
  984. AnticoagulantZongliang: anticoagulant_zongliang,
  985. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  986. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  987. Kalium: kalium,
  988. Sodium: sodium,
  989. Calcium: calcium,
  990. Bicarbonate: bicarbonate,
  991. Glucose: glucose,
  992. // DryWeight: dry_weight,
  993. DialysateFlow: dialysate_flow,
  994. DialysateTemperature: dialysate_temperature,
  995. Conductivity: conductivity,
  996. Remark: remark,
  997. Status: 1,
  998. CreatedTime: time.Now().Unix(),
  999. UpdatedTime: time.Now().Unix(),
  1000. DialysisDurationMinute: dialysisDurationMinute,
  1001. DialysisDurationHour: dialysisDurationHour,
  1002. TargetUltrafiltration: targetUltrafiltration,
  1003. DialysateFormulation: dialysateFormulation,
  1004. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1005. BodyFluid: body_fluid,
  1006. SpecialMedicine: special_medicine,
  1007. SpecialMedicineOther: special_medicine_other,
  1008. DisplaceLiquiPart: displace_liqui_part,
  1009. DisplaceLiquiValue: displace_liqui_value,
  1010. BloodAccess: blood_access,
  1011. Ultrafiltration: ultrafiltration,
  1012. BodyFluidOther: body_fluid_other,
  1013. ReplacementTotal: replacement_total,
  1014. TargetKtv: target_ktv,
  1015. DialysisIrrigation: dialysis_irrigation,
  1016. DialysisDialyszers: dialysis_dialyszers,
  1017. HemodialysisPipelines: hemodialysis_pipelines,
  1018. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1019. PunctureNeedle: puncture_needle,
  1020. PunctureNeedleCount: puncture_needle_count,
  1021. Epo: epo,
  1022. EpoCount: epo_count,
  1023. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1024. OxygenUptake: oxygen_uptake,
  1025. OxygenFlow: oxygen_flow,
  1026. OxygenTime: oxygen_time,
  1027. PreImpulse: preImpules,
  1028. SolutionStatus: 1,
  1029. DialysisRemark: dialysis_remark,
  1030. PrescribingNumber: prescribing_number,
  1031. StartSodium: start_sodium,
  1032. PrescriptionSodium: prescription_sodium,
  1033. SodiumCurve: sodium_curve,
  1034. TreatmentRemark: treatment_remark,
  1035. DialysisFluidFlow: dialysis_fluid_flow,
  1036. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1037. PrescriptionWater: prescribing_number,
  1038. DialysisStrainer: dialysis_strainer,
  1039. }
  1040. //针对河间咸得
  1041. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  1042. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1043. prescription.DisplaceLiquiPart = 0
  1044. prescription.DisplaceLiquiValue = 0
  1045. }
  1046. }
  1047. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  1048. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  1049. solution.DisplaceLiquiPart = 0
  1050. solution.DisplaceLiquiValue = 0
  1051. }
  1052. }
  1053. if adminUserInfo.CurrentOrgId == 10340 && prescription.AdminUserId == 0 {
  1054. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1055. }
  1056. err := service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  1057. //获取最新1条
  1058. dialysisSolution, _ := service.GetLastPatientDialysisSolution(patient, adminUserInfo.CurrentOrgId)
  1059. //更新状态
  1060. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  1061. //长沙南雅医院,自动生成抗凝剂的临时处方
  1062. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  1063. if prescribing_number == 0 {
  1064. prescribing_number = 1
  1065. }
  1066. advice := models.DoctorAdvice{
  1067. UserOrgId: adminUserInfo.CurrentOrgId,
  1068. PatientId: patient,
  1069. GroupNo: 0,
  1070. AdviceType: 2,
  1071. RecordDate: recordDate.Unix(),
  1072. AdviceDate: recordDate.Unix(),
  1073. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1074. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1075. AdviceDesc: "",
  1076. ReminderDate: 0,
  1077. SingleDose: anticoagulant_zongliang,
  1078. SingleDoseUnit: "iu",
  1079. DrugSpec: 0,
  1080. DrugSpecUnit: "",
  1081. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1082. PrescribingNumberUnit: "支",
  1083. DeliveryWay: "静脉注射",
  1084. ExecutionFrequency: "上机前",
  1085. AdviceDoctor: 0,
  1086. Status: 1,
  1087. CreatedTime: time.Now().Unix(),
  1088. UpdatedTime: time.Now().Unix(),
  1089. IsPrescription: 1,
  1090. ExecutionState: 2,
  1091. StopState: 2,
  1092. IsSettle: 2,
  1093. }
  1094. // 查询排班信息
  1095. schedulePatient, _ := service.GetScheduleByPatient(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1096. if schedulePatient.ID > 0 {
  1097. if schedulePatient.ScheduleType == 1 {
  1098. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1099. }
  1100. if schedulePatient.ScheduleType == 2 {
  1101. advice.StartTime = recordDate.Unix() + 11*60*60
  1102. }
  1103. }
  1104. // 抗凝剂名称
  1105. switch anticoagulant {
  1106. case 1:
  1107. advice.AdviceName = "无肝素"
  1108. break
  1109. case 2:
  1110. advice.AdviceName = "普通肝素"
  1111. break
  1112. case 3:
  1113. advice.AdviceName = "低分子肝素"
  1114. break
  1115. case 4:
  1116. advice.AdviceName = "阿加曲班"
  1117. break
  1118. case 5:
  1119. advice.AdviceName = "枸橼酸钠"
  1120. break
  1121. case 6:
  1122. advice.AdviceName = "低分子肝素钙"
  1123. break
  1124. case 7:
  1125. advice.AdviceName = "低分子肝素钠"
  1126. break
  1127. case 8:
  1128. advice.AdviceName = "依诺肝素"
  1129. break
  1130. case 9:
  1131. advice.AdviceName = "达肝素"
  1132. break
  1133. case 10:
  1134. advice.AdviceName = "体外抗凝"
  1135. break
  1136. case 11:
  1137. advice.AdviceName = "那曲肝素"
  1138. break
  1139. case 12:
  1140. advice.AdviceName = "无抗凝剂"
  1141. break
  1142. }
  1143. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1144. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 {
  1145. advice.AdviceDoctor = appRole.AdminUserId
  1146. }
  1147. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1148. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1149. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1150. advice.AdviceName = "低分子肝素钠注射液"
  1151. // 修改患者临时医嘱里的抗凝剂医嘱
  1152. advice.ID = advicePrescription.ID
  1153. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1154. } else {
  1155. // 新增患者临时医嘱里的抗凝剂医嘱
  1156. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1157. advice.AdviceName = "低分子肝素钠注射液"
  1158. service.CreateDoctorAdvice(&advice)
  1159. }
  1160. }
  1161. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1162. redis := service.RedisClient()
  1163. //清空key 值
  1164. redis.Set(key, "", time.Second)
  1165. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1166. redis.Set(keyOne, "", time.Second)
  1167. }
  1168. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1169. redis := service.RedisClient()
  1170. //清空key 值
  1171. redis.Set(key, "", time.Second)
  1172. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1173. //清空key 值
  1174. redis.Set(keyOne, "", time.Second)
  1175. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1176. redis.Set(keyTwo, "", time.Second)
  1177. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1178. redis.Set(keyThree, "", time.Second)
  1179. defer redis.Close()
  1180. if err == nil {
  1181. c.ServeSuccessJSON(map[string]interface{}{
  1182. "solution": &solution,
  1183. "prescription": &prescription,
  1184. })
  1185. } else {
  1186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1187. }
  1188. }
  1189. func (c *DialysisApiController) PostDouleCheck() {
  1190. id, _ := c.GetInt64("patient", 0)
  1191. recordDateStr := c.GetString("record_date")
  1192. checkTimeStr := c.GetString("check_time")
  1193. firstCheckTimeStr := c.GetString("first_check_time")
  1194. creater, _ := c.GetInt64("creater", 0)
  1195. modifier, _ := c.GetInt64("modifier", 0)
  1196. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  1197. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  1198. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  1199. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  1200. dialysis_item_desc := c.GetString("dialysis_item_desc")
  1201. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  1202. vascular_access_desc := c.GetString("vascular_access_desc")
  1203. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  1204. collator, _ := c.GetInt64("collator", 0)
  1205. employee_number := c.GetString("employee_number")
  1206. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  1207. needle_batch_number := c.GetString("needle_batch_number")
  1208. if id <= 0 {
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1210. return
  1211. }
  1212. adminUserInfo := c.GetAdminUserInfo()
  1213. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1214. if patient.ID == 0 {
  1215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1216. return
  1217. }
  1218. if len(recordDateStr) == 0 {
  1219. recordDateStr = time.Now().Format("2006-01-02")
  1220. }
  1221. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1222. if parseDateErr != nil {
  1223. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1225. return
  1226. }
  1227. var checkDate int64
  1228. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1229. list, _ := service.GetRoleList(adminUserInfo.CurrentOrgId, modifier)
  1230. if employee_number != list.JobNumber {
  1231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorEmployeeNumber)
  1232. return
  1233. }
  1234. }
  1235. if len(checkTimeStr) == 0 {
  1236. //checkTimeStr = time.Now().Format("2006-01-02 15:04")
  1237. checkDate = 0
  1238. } else {
  1239. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
  1240. checkDate = checkDateUnix.Unix()
  1241. }
  1242. var firstCheckTimeDate int64
  1243. if len(firstCheckTimeStr) == 0 {
  1244. //firstCheckTimeStr = time.Now().Format("2006-01-02 15:04")
  1245. firstCheckTimeDate = 0
  1246. } else {
  1247. firstCheckTimeDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", firstCheckTimeStr)
  1248. firstCheckTimeDate = firstCheckTimeDateUnix.Unix()
  1249. }
  1250. doubleCheck := models.DoubleCheck{
  1251. UserOrgId: adminUserInfo.CurrentOrgId,
  1252. PatientId: id,
  1253. DialysisItemCheck: dialysis_item_check,
  1254. DialysisParameterCheck: dialysis_parameter_check,
  1255. VascularAccessVerification: vascular_access_verification,
  1256. PipelineConnectionCheck: pipeline_connection_check,
  1257. DialysisItemDesc: dialysis_item_desc,
  1258. DialysisParameterDesc: dialysis_parameter_desc,
  1259. VascularAccessDesc: vascular_access_desc,
  1260. PipelineConnectionDesc: pipeline_connection_desc,
  1261. Collator: collator,
  1262. Status: 1,
  1263. CreatedTime: time.Now().Unix(),
  1264. UpdatedTime: time.Now().Unix(),
  1265. CheckDate: recordDate.Unix(),
  1266. EmployeeNumber: employee_number,
  1267. DialyzerBatchNumber: dialyzer_batch_number,
  1268. NeedleBatchNumber: needle_batch_number,
  1269. }
  1270. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1271. if check.ID == 0 { //新增
  1272. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1273. doubleCheck.CheckTime = checkDate
  1274. doubleCheck.Creater = creater
  1275. doubleCheck.Modifier = modifier
  1276. err := service.AddSigleDoubleCheck(&doubleCheck)
  1277. redis := service.RedisClient()
  1278. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1279. //清空key 值
  1280. redis.Set(key, "", time.Second)
  1281. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1282. redis.Set(keyTwo, "", time.Second)
  1283. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1284. redis.Set(keyThree, "", time.Second)
  1285. defer redis.Close()
  1286. if err == nil {
  1287. c.ServeSuccessJSON(map[string]interface{}{
  1288. "doubleCheck": doubleCheck,
  1289. })
  1290. } else {
  1291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1292. }
  1293. } else { //修改
  1294. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1295. doubleCheck.CheckTime = checkDate
  1296. doubleCheck.Creater = creater
  1297. doubleCheck.Modifier = modifier
  1298. doubleCheck.CreatedTime = check.CreatedTime
  1299. doubleCheck.UpdatedTime = time.Now().Unix()
  1300. doubleCheck.ID = check.ID
  1301. redis := service.RedisClient()
  1302. err := service.UpdateDoubleCheck(&doubleCheck)
  1303. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1304. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1305. redis.Set(keyTwo, "", time.Second)
  1306. //清空key 值
  1307. redis.Set(key, "", time.Second)
  1308. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1309. redis.Set(keyThree, "", time.Second)
  1310. defer redis.Close()
  1311. if err == nil {
  1312. c.ServeSuccessJSON(map[string]interface{}{
  1313. "doubleCheck": doubleCheck,
  1314. })
  1315. } else {
  1316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1317. }
  1318. }
  1319. }
  1320. func (c *DialysisApiController) PostReceiveTreatmentAsses() {
  1321. id, _ := c.GetInt64("patient", 0)
  1322. recordDateStr := c.GetString("record_date")
  1323. way, _ := c.GetInt64("way", 0)
  1324. consciousness, _ := c.GetInt64("consciousness", 0)
  1325. appetite, _ := c.GetInt64("appetite", 0)
  1326. condition, _ := c.GetInt64("condition", 0)
  1327. posture, _ := c.GetInt64("posture")
  1328. score := c.GetString("score")
  1329. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1330. danger_level, _ := c.GetInt64("danger_level", 0)
  1331. intake, _ := c.GetInt64("intake", 0)
  1332. nutrition, _ := c.GetInt64("nutrition", 0)
  1333. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1334. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1335. sick_condition_other := c.GetString("sick_condition_other")
  1336. //precaution, _ := c.GetInt64("precaution", 0)
  1337. precaution := c.GetString("precaution")
  1338. precaution_other := c.GetString("precaution_other")
  1339. psychological_other := c.GetString("psychological_other")
  1340. admission_number := c.GetString("admission_number")
  1341. tumble, _ := c.GetInt64("tumble")
  1342. his_department := c.GetString("his_department")
  1343. his_bed := c.GetString("his_bed")
  1344. diacrisis := c.GetString("diacrisis")
  1345. if id <= 0 {
  1346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1347. return
  1348. }
  1349. adminUserInfo := c.GetAdminUserInfo()
  1350. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1351. if patient.ID == 0 {
  1352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1353. return
  1354. }
  1355. if len(recordDateStr) == 0 {
  1356. recordDateStr = time.Now().Format("2006-01-02")
  1357. }
  1358. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1359. if parseDateErr != nil {
  1360. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1362. return
  1363. }
  1364. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1365. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1366. UserOrgId: adminUserInfo.CurrentOrgId,
  1367. PatientId: id,
  1368. RecordDate: recordDate.Unix(),
  1369. Way: way,
  1370. Consciousness: consciousness,
  1371. Appetite: appetite,
  1372. Condition: condition,
  1373. SickCondition: sick_condition,
  1374. DangerLevel: danger_level,
  1375. Intake: intake,
  1376. Nutrition: nutrition,
  1377. PsychologicalAssessment: psychological_assessment,
  1378. PsychologicalAssessmentOther: psychological_assessment_other,
  1379. SickConditionOther: sick_condition_other,
  1380. Posture: posture,
  1381. CreatedTime: time.Now().Unix(),
  1382. UpdateTime: time.Now().Unix(),
  1383. Status: 1,
  1384. Score: score,
  1385. Precaution: precaution,
  1386. PrecautionOther: precaution_other,
  1387. PsychologicalOther: psychological_other,
  1388. AdmissionNumber: admission_number,
  1389. Tumble: tumble,
  1390. HisDepartment: his_department,
  1391. HisBed: his_bed,
  1392. Diacrisis: diacrisis,
  1393. }
  1394. if receiveTreatment.ID == 0 { //新增
  1395. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1396. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1397. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1398. redis := service.RedisClient()
  1399. //清空key 值
  1400. redis.Set(key, "", time.Second)
  1401. defer redis.Close()
  1402. if err == nil {
  1403. c.ServeSuccessJSON(map[string]interface{}{
  1404. "receiveTreatmentAsses": receiveTreatmentAsses,
  1405. })
  1406. } else {
  1407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1408. }
  1409. } else { //修改
  1410. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1411. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1412. // if getPermissionErr != nil {
  1413. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1414. // return
  1415. // } else if headNursePermission == nil {
  1416. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1417. // return
  1418. // }
  1419. //}
  1420. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1421. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1422. receiveTreatmentAsses.UpdateTime = time.Now().Unix()
  1423. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1424. receiveTreatmentAsses.ID = receiveTreatment.ID
  1425. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1426. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1427. redis := service.RedisClient()
  1428. defer redis.Close()
  1429. redis.Set(keyOne, "", time.Second*60*60*18)
  1430. if err == nil {
  1431. c.ServeSuccessJSON(map[string]interface{}{
  1432. "receiveTreatmentAsses": receiveTreatmentAsses,
  1433. })
  1434. } else {
  1435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1436. }
  1437. }
  1438. }
  1439. func (c *DialysisApiController) PostAssessmentAfterDislysis() {
  1440. patient, _ := c.GetInt64("patient", 0)
  1441. recordDateStr := c.GetString("record_date")
  1442. fmt.Println(recordDateStr)
  1443. if patient <= 0 {
  1444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1445. return
  1446. }
  1447. adminUserInfo := c.GetAdminUserInfo()
  1448. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1449. if patientInfo.ID == 0 {
  1450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1451. return
  1452. }
  1453. if len(recordDateStr) == 0 {
  1454. recordDateStr = time.Now().Format("2006-01-02")
  1455. }
  1456. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1457. if parseDateErr != nil {
  1458. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1460. return
  1461. }
  1462. // data := make(map[string]interface{}, 0)
  1463. var data models.AssessmentAfterDislysis
  1464. var err error
  1465. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  1466. fmt.Println(err)
  1467. if err != nil {
  1468. c.ErrorLog("数据解析错误:%v", err)
  1469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1470. return
  1471. }
  1472. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1473. assessment.DialysisOrderId = data.DialysisOrderId
  1474. assessment.Evaluator = adminUserInfo.AdminUser.Id
  1475. assessment.Status = 1
  1476. assessment.WeightAfter = data.WeightAfter
  1477. assessment.WeightLoss = data.WeightLoss
  1478. assessment.Temperature = data.Temperature
  1479. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  1480. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  1481. assessment.PulseFrequency = data.PulseFrequency
  1482. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  1483. assessment.ActualDisplacement = data.ActualDisplacement
  1484. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  1485. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  1486. assessment.Cruor = data.Cruor
  1487. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  1488. assessment.DialysisIntakes = data.DialysisIntakes
  1489. assessment.InternalFistula = data.InternalFistula
  1490. assessment.BloodAccessPartId = data.BloodAccessPartId
  1491. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  1492. assessment.Catheter = data.Catheter
  1493. assessment.Complication = data.Complication
  1494. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  1495. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  1496. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  1497. assessment.PatientGose = data.PatientGose
  1498. assessment.InpatientDepartment = data.InpatientDepartment
  1499. assessment.ObservationContent = data.ObservationContent
  1500. assessment.ObservationContentOther = data.ObservationContentOther
  1501. assessment.Remark = data.Remark
  1502. assessment.BreathingRate = data.BreathingRate
  1503. assessment.DialysisProcess = data.DialysisProcess
  1504. assessment.InAdvanceMinute = data.InAdvanceMinute
  1505. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  1506. assessment.InAdvanceReason = data.InAdvanceReason
  1507. assessment.HemostasisOpera = data.HemostasisOpera
  1508. assessment.HemostasisMinute = data.HemostasisMinute
  1509. assessment.TremorNoise = data.TremorNoise
  1510. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  1511. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  1512. assessment.ArterialTube = data.ArterialTube
  1513. assessment.IntravenousTube = data.IntravenousTube
  1514. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  1515. assessment.Dialyzer = data.Dialyzer
  1516. assessment.IsEat = data.IsEat
  1517. assessment.CvcA = data.CvcA
  1518. assessment.CvcV = data.CvcV
  1519. assessment.Channel = data.Channel
  1520. assessment.ReturnBlood = data.ReturnBlood
  1521. assessment.RehydrationVolume = data.RehydrationVolume
  1522. assessment.DialysisDuring = data.DialysisDuring
  1523. assessment.StrokeVolume = data.StrokeVolume
  1524. assessment.BloodFlow = data.BloodFlow
  1525. assessment.SealingFluidDispose = data.SealingFluidDispose
  1526. assessment.SealingFluidSpecial = data.SealingFluidSpecial
  1527. assessment.DosageOfAnticoagulants = data.DosageOfAnticoagulants
  1528. assessment.SupineSystolicBloodPressure = data.SupineSystolicBloodPressure
  1529. assessment.SettingPressure = data.SettingPressure
  1530. assessment.SupineDiastolicBloodPressure = data.SupineDiastolicBloodPressure
  1531. assessment.DiastolicPressure = data.DiastolicPressure
  1532. assessment.AdditionalWeight = data.AdditionalWeight
  1533. assessment.OtherComplication = data.OtherComplication
  1534. assessment.Ktv = data.Ktv
  1535. assessment.Urr = data.Urr
  1536. assessment.Hypertenison = data.Hypertenison
  1537. assessment.Hypopiesia = data.Hypopiesia
  1538. assessment.LeaveOfficeMethod = data.LeaveOfficeMethod
  1539. assessment.Lapse = data.Lapse
  1540. assessment.Consciousness = data.Consciousness
  1541. assessment.Fallrisk = data.Fallrisk
  1542. assessment.MachineRun = data.MachineRun
  1543. assessment.AfterUrea = data.AfterUrea
  1544. assessment.PipCoagulation = data.PipCoagulation
  1545. assessment.AccumulatedBloodVolume = data.AccumulatedBloodVolume
  1546. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1547. if assessment.ID > 0 {
  1548. if appRole.UserType == 2 || appRole.UserType == 1 {
  1549. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1550. assessment.AssessmentTime = time.Now().Unix()
  1551. } else {
  1552. if assessment.Creater == 0 {
  1553. assessment.Modifier = adminUserInfo.AdminUser.Id
  1554. assessment.Creater = adminUserInfo.AdminUser.Id
  1555. } else {
  1556. assessment.Modifier = adminUserInfo.AdminUser.Id
  1557. }
  1558. }
  1559. assessment.UpdatedTime = time.Now().Unix()
  1560. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  1561. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1562. redis := service.RedisClient()
  1563. //清空key 值
  1564. redis.Set(key, "", time.Second)
  1565. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1566. redis.Set(keyThree, "", time.Second)
  1567. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1568. redis.Set(keyTwo, "", time.Second)
  1569. defer redis.Close()
  1570. } else {
  1571. if appRole.UserType == 2 || appRole.UserType == 1 {
  1572. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1573. assessment.AssessmentTime = time.Now().Unix()
  1574. } else {
  1575. assessment.Creater = adminUserInfo.AdminUser.Id
  1576. }
  1577. assessment.CreatedTime = time.Now().Unix()
  1578. assessment.UpdatedTime = time.Now().Unix()
  1579. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  1580. assessment.PatientId = patient
  1581. assessment.AssessmentDate = recordDate.Unix()
  1582. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  1583. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1584. redis := service.RedisClient()
  1585. //清空key 值
  1586. redis.Set(key, "", time.Second)
  1587. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1588. redis.Set(keyThree, "", time.Second)
  1589. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1590. redis.Set(keyTwo, "", time.Second)
  1591. defer redis.Close()
  1592. }
  1593. if err != nil {
  1594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1595. return
  1596. }
  1597. c.ServeSuccessJSON(map[string]interface{}{
  1598. "AssessmentAfterDislysis": &assessment,
  1599. })
  1600. }
  1601. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  1602. patient, _ := c.GetInt64("patient", 0)
  1603. recordDateStr := c.GetString("record_date")
  1604. if patient <= 0 {
  1605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1606. return
  1607. }
  1608. adminUserInfo := c.GetAdminUserInfo()
  1609. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1610. if patientInfo.ID == 0 {
  1611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1612. return
  1613. }
  1614. if len(recordDateStr) == 0 {
  1615. recordDateStr = time.Now().Format("2006-01-02")
  1616. }
  1617. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1618. if parseDateErr != nil {
  1619. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1621. return
  1622. }
  1623. weight_before, _ := c.GetFloat("weight_before", 0)
  1624. dry_weight, _ := c.GetFloat("dry_weight", 0)
  1625. additional_weight, _ := c.GetFloat("additional_weight", 0)
  1626. temperature, _ := c.GetFloat("temperature", 0)
  1627. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1628. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1629. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1630. last_post_dialysis := c.GetString("last_post_dialysis")
  1631. dialysis_interphase := c.GetString("dialysis_interphase")
  1632. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  1633. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1634. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  1635. bloodAccessPartId := c.GetString("blood_access_part_id")
  1636. internalFistula := c.GetString("internal_fistula")
  1637. internal_fistula_skin := c.GetString("internal_fistula_skin")
  1638. catheter := c.GetString("catheter")
  1639. catheter_bend, _ := c.GetInt("catheter_bend")
  1640. complication := c.GetString("complication")
  1641. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  1642. hemorrhage := c.GetString("hemorrhage")
  1643. hemorrhage_other := c.GetString("hemorrhage_other")
  1644. remark := c.GetString("remark")
  1645. puncture_method := c.GetString("puncture_method")
  1646. dialysis_count := c.GetString("dialysis_count")
  1647. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  1648. emergency_treatment_other := c.GetString("emergency_treatment_other")
  1649. ductus_arantii := c.GetString("ductus_arantii")
  1650. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  1651. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  1652. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  1653. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  1654. puncture_way := c.GetString("puncture_way")
  1655. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  1656. internal_fistula_other := c.GetString("internal_fistula_other")
  1657. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  1658. breathing_rate := c.GetString("breathing_rate")
  1659. is_infect, _ := c.GetInt64("is_infect", 0)
  1660. exposed, _ := c.GetFloat("exposed", 0)
  1661. skin := c.GetString("skin")
  1662. skin_other := c.GetString("skin_other")
  1663. infect_other := c.GetString("infect_other")
  1664. ductus_arantii_other := c.GetString("ductus_arantii_other")
  1665. machine_type := c.GetString("machine_type")
  1666. puncture_needle := c.GetString("puncture_needle")
  1667. //humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
  1668. humor_excessive_symptom := c.GetString("humor_excessive_symptom")
  1669. phinholing := c.GetString("pinholing")
  1670. catheter_suture := c.GetString("catheter_suture")
  1671. catheter_suture_other := c.GetString("catheter_suture_other")
  1672. edema := c.GetString("edema")
  1673. urine_volume, _ := c.GetFloat("urine_volume", 0)
  1674. special_treatment := c.GetString("special_treatment")
  1675. catheter_maintenance := c.GetString("catheter_maintenance")
  1676. thrombusType := c.GetString("thromubus_type")
  1677. thrombusInt, _ := strconv.ParseInt(thrombusType, 10, 64)
  1678. thrombus_a := c.GetString("thromubus_a")
  1679. thrombus_av := c.GetString("thrombus_av")
  1680. thrombus_v := c.GetString("thromubus_v")
  1681. dehydration := c.GetString("dehydration")
  1682. pre_dialysis_drugs := c.GetString("pre_dialysis_drugs")
  1683. period, _ := c.GetInt64("period")
  1684. estimated_food_intake := c.GetString("estimated_food_intake")
  1685. blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
  1686. urea_befor := c.GetString("urea_befor")
  1687. suction := c.GetString("suction")
  1688. weight_befor_remake := c.GetString("weight_befor_remake")
  1689. height := c.GetString("height")
  1690. age := c.GetString("age")
  1691. his_department := c.GetString("his_department")
  1692. his_bed := c.GetString("his_bed")
  1693. point_puncture := c.GetString("point_puncture")
  1694. assessmentBeforeDislysis := models.PredialysisEvaluation{
  1695. DialysisCount: dialysis_count,
  1696. EmergencyTreatment: emergency_treatment,
  1697. EmergencyTreatmentOther: emergency_treatment_other,
  1698. DuctusArantii: ductus_arantii,
  1699. VenousCatheterization: venous_catheterization,
  1700. VenousCatheterizationPart: venous_catheterization_part,
  1701. VenousCatheterizationPartOther: venous_catheterization_part_other,
  1702. PunctureWay: puncture_way,
  1703. BloodAccessInternalFistula: blood_access_internal_fistula,
  1704. BloodAccessNoise: blood_access_noise,
  1705. InternalFistulaOther: internal_fistula_other,
  1706. Evaluator: adminUserInfo.AdminUser.Id,
  1707. UserOrgId: adminUserInfo.CurrentOrgId,
  1708. PatientId: patient,
  1709. AssessmentDate: recordDate.Unix(),
  1710. Temperature: temperature,
  1711. PulseFrequency: pulse_frequency,
  1712. SystolicBloodPressure: systolic_blood_pressure,
  1713. DiastolicBloodPressure: diastolic_blood_pressure,
  1714. WeightBefore: weight_before,
  1715. DryWeight: dry_weight,
  1716. AdditionalWeight: additional_weight,
  1717. DialysisInterphase: dialysis_interphase,
  1718. LastPostDialysis: last_post_dialysis,
  1719. SymptomBeforeDialysis: symptom_before_dialysis,
  1720. InternalFistula: internalFistula,
  1721. InternalFistulaSkin: internal_fistula_skin,
  1722. Catheter: catheter,
  1723. CatheterBend: catheter_bend,
  1724. Complication: complication,
  1725. CreatedTime: time.Now().Unix(),
  1726. Status: 1,
  1727. Remark: remark,
  1728. IsHemorrhage: is_hemorrhage,
  1729. Hemorrhage: hemorrhage,
  1730. HemorrhageOther: hemorrhage_other,
  1731. BloodAccessPartId: bloodAccessPartId,
  1732. BloodAccessPartOperaId: bloodAccessPartOperaId,
  1733. PunctureMethod: puncture_method,
  1734. BreathingRate: breathing_rate,
  1735. IsInfect: is_infect,
  1736. Exposed: exposed,
  1737. Skin: skin,
  1738. SkinOther: skin_other,
  1739. InfectOther: infect_other,
  1740. DuctusArantiiOther: ductus_arantii_other,
  1741. MachineType: machine_type,
  1742. PunctureNeedle: puncture_needle,
  1743. HumorExcessiveSymptom: humor_excessive_symptom,
  1744. Phinholing: phinholing,
  1745. CatheterSuture: catheter_suture,
  1746. CatheterSutureOther: catheter_suture_other,
  1747. Edema: edema,
  1748. UrineVolume: urine_volume,
  1749. SpecialTreatment: special_treatment,
  1750. CatheterMaintenance: catheter_maintenance,
  1751. ThromubusType: thrombusInt,
  1752. ThrombusAv: thrombus_av,
  1753. ThromubusA: thrombus_a,
  1754. ThromubusV: thrombus_v,
  1755. Dehydration: dehydration,
  1756. PreDialysisDrugs: pre_dialysis_drugs,
  1757. Period: period,
  1758. EstimatedFoodIntake: estimated_food_intake,
  1759. BloodPressureDuringDialysis: blood_pressure_during_dialysis,
  1760. UreaBefor: urea_befor,
  1761. Suction: suction,
  1762. WeightBeforRemake: weight_befor_remake,
  1763. Height: height,
  1764. Age: age,
  1765. HisDepartment: his_department,
  1766. HisBed: his_bed,
  1767. PointPuncture: point_puncture,
  1768. }
  1769. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1770. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1771. if evaluation.ID == 0 { //新增
  1772. if appRole.UserType == 2 || appRole.UserType == 1 {
  1773. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1774. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1775. } else {
  1776. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  1777. }
  1778. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  1779. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10469 {
  1780. var dewater_amount float64
  1781. dewater_amount = 0
  1782. if dry_weight > 0 {
  1783. dewater_amount = weight_before - dry_weight - additional_weight
  1784. dewater_amount = dewater_amount * 1000
  1785. if dewater_amount <= 0 {
  1786. dewater_amount = 0
  1787. }
  1788. } else {
  1789. dewater_amount = 0
  1790. }
  1791. // 计算透析处方的相关超滤量
  1792. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1793. var lastDialysisPrescribe *models.DialysisPrescription
  1794. var dialysisSolution *models.DialysisSolution
  1795. var dialysisPrescribe *models.DialysisPrescription
  1796. var mode_id int64
  1797. if schedual != nil {
  1798. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  1799. if dialysisPrescribe == nil {
  1800. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1801. }
  1802. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1803. // 获取透析模版
  1804. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1805. mode_id = schedual.ModeId
  1806. } else {
  1807. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  1808. // 获取透析模版
  1809. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1810. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  1811. if dialysisPrescribe == nil && dialysisSolution != nil {
  1812. mode_id = dialysisSolution.ModeId
  1813. }
  1814. if dialysisPrescribe == nil && dialysisSolution == nil {
  1815. mode_id = 0
  1816. }
  1817. }
  1818. // 插入透析处方
  1819. if dialysisPrescribe == nil && dialysisSolution != nil {
  1820. var newprescribe models.DialysisPrescription
  1821. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1822. newprescribe.PatientId = dialysisSolution.PatientId
  1823. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1824. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1825. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1826. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1827. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1828. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1829. newprescribe.ModeId = dialysisSolution.ModeId
  1830. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1831. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1832. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1833. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1834. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1835. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1836. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1837. newprescribe.Glucose = dialysisSolution.Glucose
  1838. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1839. newprescribe.Kalium = dialysisSolution.Kalium
  1840. newprescribe.Sodium = dialysisSolution.Sodium
  1841. newprescribe.Calcium = dialysisSolution.Calcium
  1842. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1843. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1844. newprescribe.Conductivity = dialysisSolution.Conductivity
  1845. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1846. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1847. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1848. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1849. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1850. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1851. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1852. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1853. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1854. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1855. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1856. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1857. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1858. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1859. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1860. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1861. newprescribe.CreatedTime = time.Now().Unix()
  1862. newprescribe.UpdatedTime = time.Now().Unix()
  1863. newprescribe.RecordDate = recordDate.Unix()
  1864. newprescribe.DewaterAmount = dewater_amount
  1865. newprescribe.TargetUltrafiltration = dewater_amount
  1866. newprescribe.Status = 1
  1867. err := service.AddSigleRecord(&newprescribe)
  1868. if err != nil {
  1869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1870. }
  1871. }
  1872. if dialysisPrescribe == nil && dialysisSolution == nil {
  1873. if lastDialysisPrescribe != nil {
  1874. var newprescribe models.DialysisPrescription
  1875. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  1876. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  1877. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  1878. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  1879. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  1880. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  1881. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  1882. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  1883. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  1884. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  1885. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  1886. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  1887. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  1888. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  1889. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  1890. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  1891. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  1892. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  1893. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  1894. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  1895. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  1896. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  1897. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  1898. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  1899. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  1900. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  1901. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  1902. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  1903. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  1904. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  1905. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  1906. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  1907. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  1908. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  1909. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  1910. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  1911. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  1912. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  1913. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  1914. newprescribe.CreatedTime = time.Now().Unix()
  1915. newprescribe.UpdatedTime = time.Now().Unix()
  1916. newprescribe.RecordDate = recordDate.Unix()
  1917. newprescribe.DewaterAmount = dewater_amount
  1918. newprescribe.TargetUltrafiltration = dewater_amount
  1919. newprescribe.Status = 1
  1920. newprescribe.Creater = adminUserInfo.AdminUser.Id
  1921. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1922. err := service.AddSigleRecord(&newprescribe)
  1923. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1924. redis := service.RedisClient()
  1925. defer redis.Close()
  1926. //清空key 值
  1927. redis.Set(key, "", time.Second)
  1928. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1929. redis.Set(keyOne, "", time.Second)
  1930. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1931. redis.Set(keyThree, "", time.Second)
  1932. if err != nil {
  1933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1934. }
  1935. } else {
  1936. var newprescribe models.DialysisPrescription
  1937. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  1938. newprescribe.PatientId = patient
  1939. newprescribe.ModeId = mode_id
  1940. newprescribe.CreatedTime = time.Now().Unix()
  1941. newprescribe.UpdatedTime = time.Now().Unix()
  1942. newprescribe.RecordDate = recordDate.Unix()
  1943. newprescribe.DewaterAmount = dewater_amount
  1944. newprescribe.TargetUltrafiltration = dewater_amount
  1945. newprescribe.Status = 1
  1946. newprescribe.Creater = adminUserInfo.AdminUser.Id
  1947. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1948. newprescribe.Modifier = adminUserInfo.AdminUser.Id
  1949. err := service.AddSigleRecord(&newprescribe)
  1950. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1951. redis := service.RedisClient()
  1952. defer redis.Close()
  1953. //清空key 值
  1954. redis.Set(key, "", time.Second)
  1955. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1956. redis.Set(keyOne, "", time.Second)
  1957. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1958. redis.Set(keyThree, "", time.Second)
  1959. if err != nil {
  1960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1961. }
  1962. }
  1963. }
  1964. }
  1965. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1966. redis := service.RedisClient()
  1967. //清空key 值
  1968. redis.Set(key, "", time.Second)
  1969. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1970. redis.Set(keyOne, "", time.Second)
  1971. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1972. redis.Set(keyTwo, "", time.Second)
  1973. defer redis.Close()
  1974. if err == nil {
  1975. c.ServeSuccessJSON(map[string]interface{}{
  1976. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  1977. })
  1978. } else {
  1979. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1981. }
  1982. } else { //修改
  1983. //if appRole.UserType == 3 {
  1984. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  1985. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1986. // if getPermissionErr != nil {
  1987. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1988. // return
  1989. // } else if headNursePermission == nil {
  1990. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1991. // return
  1992. // }
  1993. // }
  1994. //}
  1995. if appRole.UserType == 2 || appRole.UserType == 1 {
  1996. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1997. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1998. } else {
  1999. if evaluation.Creater == 0 {
  2000. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2001. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2002. } else {
  2003. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2004. }
  2005. }
  2006. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  2007. assessmentBeforeDislysis.ID = evaluation.ID
  2008. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  2009. //
  2010. //新增逻辑
  2011. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2012. var dewater_amount float64
  2013. dewater_amount = 0
  2014. if evaluation.DryWeight > 0 {
  2015. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2016. if templateInfo.TemplateId == 17 || templateInfo.TemplateId == 22 || templateInfo.TemplateId == 21 || templateInfo.TemplateId == 34 {
  2017. dewater_amount = dewater_amount * 1000
  2018. }
  2019. if dewater_amount <= 0 {
  2020. dewater_amount = 0
  2021. }
  2022. } else {
  2023. dewater_amount = 0
  2024. }
  2025. // 计算透析处方的相关超滤量
  2026. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2027. var lastDialysisPrescribe *models.DialysisPrescription
  2028. var dialysisSolution *models.DialysisSolution
  2029. var dialysisPrescribe *models.DialysisPrescription
  2030. var mode_id int64
  2031. if schedual != nil {
  2032. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2033. if dialysisPrescribe == nil {
  2034. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2035. }
  2036. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2037. // 获取透析模版
  2038. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2039. mode_id = schedual.ModeId
  2040. } else {
  2041. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2042. // 获取透析模版
  2043. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2044. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  2045. if dialysisPrescribe == nil && dialysisSolution != nil {
  2046. mode_id = dialysisSolution.ModeId
  2047. }
  2048. if dialysisPrescribe == nil && dialysisSolution == nil {
  2049. mode_id = 0
  2050. }
  2051. }
  2052. // 插入透析处方
  2053. if dialysisPrescribe == nil && dialysisSolution != nil {
  2054. var newprescribe models.DialysisPrescription
  2055. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  2056. newprescribe.PatientId = dialysisSolution.PatientId
  2057. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2058. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2059. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2060. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2061. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2062. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2063. newprescribe.ModeId = dialysisSolution.ModeId
  2064. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2065. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2066. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2067. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2068. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2069. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2070. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2071. newprescribe.Glucose = dialysisSolution.Glucose
  2072. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2073. newprescribe.Kalium = dialysisSolution.Kalium
  2074. newprescribe.Sodium = dialysisSolution.Sodium
  2075. newprescribe.Calcium = dialysisSolution.Calcium
  2076. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2077. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2078. newprescribe.Conductivity = dialysisSolution.Conductivity
  2079. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2080. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2081. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2082. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2083. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2084. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2085. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2086. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2087. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2088. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2089. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2090. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2091. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2092. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2093. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2094. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2095. newprescribe.CreatedTime = time.Now().Unix()
  2096. newprescribe.UpdatedTime = time.Now().Unix()
  2097. newprescribe.RecordDate = recordDate.Unix()
  2098. newprescribe.DewaterAmount = dewater_amount
  2099. newprescribe.TargetUltrafiltration = dewater_amount
  2100. newprescribe.Status = 1
  2101. err := service.AddSigleRecord(&newprescribe)
  2102. if err != nil {
  2103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2104. }
  2105. }
  2106. if dialysisPrescribe == nil && dialysisSolution == nil {
  2107. if lastDialysisPrescribe != nil {
  2108. var newprescribe models.DialysisPrescription
  2109. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  2110. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  2111. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2112. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2113. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2114. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2115. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2116. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2117. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2118. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2119. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2120. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2121. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2122. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2123. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2124. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2125. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2126. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2127. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2128. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2129. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2130. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2131. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2132. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2133. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2134. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2135. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2136. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2137. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2138. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2139. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2140. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2141. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2142. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2143. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2144. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2145. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2146. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2147. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2148. newprescribe.CreatedTime = time.Now().Unix()
  2149. newprescribe.UpdatedTime = time.Now().Unix()
  2150. newprescribe.RecordDate = recordDate.Unix()
  2151. newprescribe.DewaterAmount = dewater_amount
  2152. newprescribe.TargetUltrafiltration = dewater_amount
  2153. newprescribe.Status = 1
  2154. err := service.AddSigleRecord(&newprescribe)
  2155. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2156. redis := service.RedisClient()
  2157. defer redis.Close()
  2158. //清空key 值
  2159. redis.Set(key, "", time.Second)
  2160. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2161. redis.Set(keyOne, "", time.Second)
  2162. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2163. redis.Set(keyThree, "", time.Second)
  2164. if err != nil {
  2165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2166. }
  2167. } else {
  2168. var newprescribe models.DialysisPrescription
  2169. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2170. newprescribe.PatientId = patient
  2171. newprescribe.ModeId = mode_id
  2172. newprescribe.CreatedTime = time.Now().Unix()
  2173. newprescribe.UpdatedTime = time.Now().Unix()
  2174. newprescribe.RecordDate = recordDate.Unix()
  2175. newprescribe.DewaterAmount = dewater_amount
  2176. newprescribe.TargetUltrafiltration = dewater_amount
  2177. newprescribe.Status = 1
  2178. err := service.AddSigleRecord(&newprescribe)
  2179. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2180. redis := service.RedisClient()
  2181. defer redis.Close()
  2182. //清空key 值
  2183. redis.Set(key, "", time.Second)
  2184. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2185. redis.Set(keyOne, "", time.Second)
  2186. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2187. redis.Set(keyThree, "", time.Second)
  2188. if err != nil {
  2189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2190. }
  2191. }
  2192. }
  2193. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  2194. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2195. redis := service.RedisClient()
  2196. //清空key 值
  2197. redis.Set(key, "", time.Second)
  2198. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2199. redis.Set(keyOne, "", time.Second)
  2200. defer redis.Close()
  2201. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2202. redis.Set(keyTwo, "", time.Second)
  2203. if err == nil {
  2204. c.ServeSuccessJSON(map[string]interface{}{
  2205. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2206. })
  2207. } else {
  2208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2209. }
  2210. }
  2211. }
  2212. func (c *DialysisApiController) PostTreatmentSummary() {
  2213. patient, _ := c.GetInt64("patient", 0)
  2214. recordDateStr := c.GetString("record_date")
  2215. if patient <= 0 {
  2216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2217. return
  2218. }
  2219. adminUserInfo := c.GetAdminUserInfo()
  2220. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2221. if patientInfo.ID == 0 {
  2222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2223. return
  2224. }
  2225. if len(recordDateStr) == 0 {
  2226. recordDateStr = time.Now().Format("2006-01-02")
  2227. }
  2228. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2229. if parseDateErr != nil {
  2230. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2232. return
  2233. }
  2234. mission := c.GetString("mission")
  2235. dialysis_summary := c.GetString("dialysis_summary")
  2236. nursingRecord := c.GetString("nursing_record")
  2237. specialRecord := c.GetString("special_record")
  2238. sj_nurse := adminUserInfo.AdminUser.Id
  2239. zl_nurse := adminUserInfo.AdminUser.Id
  2240. hd_nurse := adminUserInfo.AdminUser.Id
  2241. xj_nurse := adminUserInfo.AdminUser.Id
  2242. zl_doctor := adminUserInfo.AdminUser.Id
  2243. treatmentSummary := models.TreatmentSummary{
  2244. UserOrgId: adminUserInfo.CurrentOrgId,
  2245. PatientId: patient,
  2246. AssessmentDate: recordDate.Unix(),
  2247. Mission: mission,
  2248. DialysisSummary: dialysis_summary,
  2249. SjNurse: sj_nurse,
  2250. ZlNurse: zl_nurse,
  2251. HdNurse: hd_nurse,
  2252. XjNurse: xj_nurse,
  2253. ZlDoctor: zl_doctor,
  2254. Status: 1,
  2255. CreatedTime: time.Now().Unix(),
  2256. NursingRecord: nursingRecord,
  2257. SpecialRecord: specialRecord,
  2258. }
  2259. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2260. if tempTreatmentSummary.ID == 0 { //新增
  2261. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  2262. err := service.AddSigleSummaryRecord(&treatmentSummary)
  2263. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2264. redis := service.RedisClient()
  2265. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2266. redis.Set(keyOne, "", time.Second)
  2267. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2268. redis.Set(keyThree, "", time.Second)
  2269. defer redis.Close()
  2270. //清空key 值
  2271. redis.Set(key, "", time.Second)
  2272. if err == nil {
  2273. c.ServeSuccessJSON(map[string]interface{}{
  2274. "summary": treatmentSummary,
  2275. })
  2276. } else {
  2277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2278. }
  2279. } else { //修改
  2280. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  2281. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2282. // if getPermissionErr != nil {
  2283. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2284. // return
  2285. // } else if headNursePermission == nil {
  2286. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2287. // return
  2288. // }
  2289. //}
  2290. treatmentSummary.Creater = tempTreatmentSummary.Creater
  2291. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  2292. treatmentSummary.UpdatedTime = time.Now().Unix()
  2293. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  2294. treatmentSummary.ID = tempTreatmentSummary.ID
  2295. err := service.UpdateSummeRecord(&treatmentSummary)
  2296. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2297. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2298. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2299. //清空key 值
  2300. redis := service.RedisClient()
  2301. redis.Set(key, "", time.Second)
  2302. redis.Set(keyOne, "", time.Second)
  2303. redis.Set(keyThree, "", time.Second)
  2304. defer redis.Close()
  2305. if err == nil {
  2306. c.ServeSuccessJSON(map[string]interface{}{
  2307. "summary": treatmentSummary,
  2308. })
  2309. } else {
  2310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2311. }
  2312. }
  2313. }
  2314. func (c *DialysisApiController) GetDeviceList() {
  2315. adminUserInfo := c.GetAdminUserInfo()
  2316. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  2317. c.ServeSuccessJSON(map[string]interface{}{
  2318. "device": device,
  2319. })
  2320. }
  2321. func (c *DialysisApiController) GetAllDeviceZone() {
  2322. adminUserInfo := c.GetAdminUserInfo()
  2323. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  2324. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  2325. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  2326. if err == nil {
  2327. c.ServeSuccessJSON(map[string]interface{}{
  2328. "zone": zone,
  2329. "dics": dics,
  2330. "efs": efs,
  2331. })
  2332. }
  2333. }
  2334. func (c *DialysisApiController) GetDialysisWatch() {
  2335. page, _ := c.GetInt64("page", 1)
  2336. limit, _ := c.GetInt64("limit", 10)
  2337. schedulType, _ := c.GetInt64("schedul_type", 0)
  2338. startTime, _ := c.GetInt64("schedul_time", 0)
  2339. partitionType, _ := c.GetInt64("partition_type", 0)
  2340. keywords := c.GetString("keywords")
  2341. start_time, _ := c.GetInt64("start_time")
  2342. end_time, _ := c.GetInt64("end_time")
  2343. adminUserInfo := c.GetAdminUserInfo()
  2344. if len(keywords) > 0 {
  2345. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2346. if err == nil {
  2347. c.ServeSuccessJSON(map[string]interface{}{
  2348. "schedule": dialysisSchedule,
  2349. "total": total,
  2350. })
  2351. } else {
  2352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2353. }
  2354. } else {
  2355. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2356. if err == nil {
  2357. c.ServeSuccessJSON(map[string]interface{}{
  2358. "schedule": dialysisSchedule,
  2359. "total": total,
  2360. })
  2361. } else {
  2362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2363. }
  2364. }
  2365. }
  2366. //func (c *DialysisApiController) GetDialysisWatch() {
  2367. // page, _ := c.GetInt64("page", 1)
  2368. // limit, _ := c.GetInt64("limit", 10)
  2369. // schedulType, _ := c.GetInt64("schedul_type", 0)
  2370. // startTime, _ := c.GetInt64("schedul_time", 0)
  2371. // partitionType, _ := c.GetInt64("partition_type", 0)
  2372. // keywords := c.GetString("keywords")
  2373. //
  2374. // adminUserInfo := c.GetAdminUserInfo()
  2375. // if len(keywords) > 0 {
  2376. // dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  2377. //
  2378. // //获取所有床位号
  2379. // numberList, _ := service.GetAllDeviceNumberByListSix(adminUserInfo.CurrentOrgId)
  2380. //
  2381. // //获取透析处方
  2382. // prescriptions, _ := service.GetAllPrescriptionByListTwo(adminUserInfo.CurrentOrgId, startTime)
  2383. // //获取透前评估
  2384. // assessmentBefores, _ := service.GetAllAssessmentBeforesByListThree(adminUserInfo.CurrentOrgId, startTime)
  2385. // //获取上机
  2386. // dialysisOrders, _ := service.GetAllDialysisOrdersByListThree(adminUserInfo.CurrentOrgId, startTime)
  2387. // //获取透后
  2388. // AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListThree(adminUserInfo.CurrentOrgId, startTime)
  2389. //
  2390. // //获取透后监测
  2391. // monitorlist, _ := service.GetAllMonitorListThree(adminUserInfo.CurrentOrgId, startTime)
  2392. //
  2393. // //获取所有的患者
  2394. // patients, _ := service.GetAllPatientListByListSix(adminUserInfo.CurrentOrgId,keywords)
  2395. //
  2396. // //获取所有透析模式
  2397. // treatments, _ := service.GetAllTreatModeByList(adminUserInfo.CurrentOrgId)
  2398. //
  2399. // for key, scheduals := range dialysisSchedule {
  2400. // // 获取患者信息
  2401. // for _, patient := range patients {
  2402. // if scheduals.PatientId == patient.ID {
  2403. // dialysisSchedule[key].MonitorPatients = patient
  2404. // break
  2405. // }
  2406. // }
  2407. // // 床位信息
  2408. // for _, device := range numberList {
  2409. // if scheduals.BedId == device.ID {
  2410. // dialysisSchedule[key].DeviceNumber = device
  2411. // break
  2412. // }
  2413. // }
  2414. //
  2415. // // 医嘱信息
  2416. // for _, prescription := range prescriptions {
  2417. // if scheduals.PatientId == prescription.PatientId {
  2418. // dialysisSchedule[key].Prescription = prescription
  2419. // break
  2420. // }
  2421. // }
  2422. //
  2423. // // 透前评估
  2424. // for _, assessmentBefore := range assessmentBefores {
  2425. // if scheduals.PatientId == assessmentBefore.PatientId {
  2426. // dialysisSchedule[key].AssessmentBeforeDislysis = assessmentBefore
  2427. // break
  2428. // }
  2429. // }
  2430. //
  2431. // // 透析上下机
  2432. // for _, dialysisOrder := range dialysisOrders {
  2433. // if scheduals.PatientId == dialysisOrder.PatientId {
  2434. // dialysisSchedule[key].DialysisOrder = dialysisOrder
  2435. // break
  2436. // }
  2437. // }
  2438. //
  2439. // records := make([]*models.MonitoringRecord, 0)
  2440. // // 透析监测
  2441. // for _, it := range monitorlist {
  2442. // records := append(records, it)
  2443. // if scheduals.PatientId == it.PatientId {
  2444. // dialysisSchedule[key].MonitoringRecord = records
  2445. // }
  2446. // }
  2447. //
  2448. // // 透后评估
  2449. // for _, afterDislysis := range AssessmentAfterDislysis {
  2450. // if scheduals.PatientId == afterDislysis.PatientId {
  2451. // dialysisSchedule[key].AssessmentAfterDislysis = afterDislysis
  2452. // break
  2453. // }
  2454. // }
  2455. //
  2456. // //透析模式
  2457. // for _, treatment := range treatments {
  2458. // if scheduals.ModeId == treatment.ID {
  2459. // dialysisSchedule[key].TreatmentMode = treatment
  2460. // break
  2461. // }
  2462. // }
  2463. // }
  2464. // //获取所有床位号
  2465. // if err == nil {
  2466. // c.ServeSuccessJSON(map[string]interface{}{
  2467. // "schedule": dialysisSchedule,
  2468. // "total": total,
  2469. // })
  2470. // } else {
  2471. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2472. // }
  2473. //
  2474. // } else {
  2475. // dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  2476. // if err == nil {
  2477. // c.ServeSuccessJSON(map[string]interface{}{
  2478. // "schedule": dialysisSchedule,
  2479. // "total": total,
  2480. // })
  2481. // } else {
  2482. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2483. // }
  2484. // }
  2485. //}
  2486. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  2487. patientId, _ := c.GetInt64("id", 0)
  2488. record_date, _ := c.GetInt64("record_date", 0)
  2489. adminUserInfo := c.GetAdminUserInfo()
  2490. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2491. var dialysisStatus int64
  2492. if dialysisOrder == nil { //没有透析记录
  2493. dialysisStatus = 0 //未透析
  2494. } else {
  2495. dialysisStatus = dialysisOrder.Stage
  2496. }
  2497. //用户基本信息
  2498. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2499. //接诊评估
  2500. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2501. //透前评估
  2502. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2503. //临时医嘱
  2504. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2505. //双人核对
  2506. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2507. //透析监测
  2508. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  2509. //透后评估
  2510. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2511. //透析小结
  2512. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2513. //透析处方
  2514. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2515. if dialysisPrescription.ID == 0 {
  2516. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  2517. c.ServeSuccessJSON(map[string]interface{}{
  2518. "patientInfo": schedualPatientInfo,
  2519. "dialysisPrescription": solution,
  2520. "receiverTreatmentAccess": receiverTreatmentAccess,
  2521. "predialysisEvaluation": PredialysisEvaluation,
  2522. "doctorAdvice": DoctorAdvice,
  2523. "doubleCheck": DoubleCheck,
  2524. "assessmentAfterDislysis": AssessmentAfterDislysis,
  2525. "treatmentSummary": TreatmentSummary,
  2526. "monitorRecord": Record,
  2527. "dialysisStatus": dialysisStatus,
  2528. "dialysisOrder": dialysisOrder,
  2529. "isSolution": 1,
  2530. })
  2531. } else {
  2532. c.ServeSuccessJSON(map[string]interface{}{
  2533. "patientInfo": schedualPatientInfo,
  2534. "dialysisPrescription": dialysisPrescription,
  2535. "receiverTreatmentAccess": receiverTreatmentAccess,
  2536. "predialysisEvaluation": PredialysisEvaluation,
  2537. "doctorAdvice": DoctorAdvice,
  2538. "doubleCheck": DoubleCheck,
  2539. "assessmentAfterDislysis": AssessmentAfterDislysis,
  2540. "treatmentSummary": TreatmentSummary,
  2541. "monitorRecord": Record,
  2542. "dialysisStatus": dialysisStatus,
  2543. "dialysisOrder": dialysisOrder,
  2544. "isSolution": 2,
  2545. })
  2546. }
  2547. }
  2548. func (c *DialysisApiController) CreateDoctorAdvice() {
  2549. patient, _ := c.GetInt64("id", 0)
  2550. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  2551. record_date, _ := c.GetInt64("record_date", 0)
  2552. if patient <= 0 {
  2553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2554. return
  2555. }
  2556. adminUserInfo := c.GetAdminUserInfo()
  2557. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2558. if patientInfo.ID == 0 {
  2559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2560. return
  2561. }
  2562. var advice models.DoctorAdvice
  2563. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  2564. if code > 0 {
  2565. c.ServeFailJSONWithSGJErrorCode(code)
  2566. return
  2567. }
  2568. if advice.ParentId > 0 {
  2569. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  2570. if old.ID == 0 || old.PatientId != patient {
  2571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2572. return
  2573. }
  2574. if old.StopState == 1 || old.ExecutionState == 1 {
  2575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2576. return
  2577. }
  2578. if old.ParentId > 0 {
  2579. advice.ParentId = old.ParentId
  2580. }
  2581. advice.StartTime = old.StartTime
  2582. advice.AdviceDoctor = old.AdviceDoctor
  2583. advice.DeliveryWay = old.DeliveryWay
  2584. advice.ExecutionFrequency = old.ExecutionFrequency
  2585. }
  2586. advice.RecordDate = record_date
  2587. advice.DialysisOrderId = dialysis_id
  2588. advice.Status = 1
  2589. advice.CreatedTime = time.Now().Unix()
  2590. advice.UpdatedTime = time.Now().Unix()
  2591. advice.StopState = 2
  2592. advice.ExecutionState = 2
  2593. advice.AdviceType = 2
  2594. advice.UserOrgId = adminUserInfo.CurrentOrgId
  2595. advice.PatientId = patient
  2596. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2597. err := service.CreateDoctorAdvice(&advice)
  2598. if err != nil {
  2599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2600. return
  2601. }
  2602. for _, subAdvice := range subAdivice {
  2603. subAdvice.ParentId = advice.ID
  2604. subAdvice.PatientId = patient
  2605. subAdvice.RecordDate = record_date
  2606. subAdvice.CreatedTime = time.Now().Unix()
  2607. subAdvice.UpdatedTime = time.Now().Unix()
  2608. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  2609. }
  2610. service.CreateSubDoctorAdvice(subAdivice)
  2611. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  2612. c.ServeSuccessJSON(map[string]interface{}{
  2613. "msg": "ok",
  2614. "advice": advice,
  2615. "subAdvice": subAdivices,
  2616. })
  2617. return
  2618. }
  2619. func (c *DialysisApiController) EditDoctorAdvice() {
  2620. patient, _ := c.GetInt64("patient", 0)
  2621. id, _ := c.GetInt64("id", 0)
  2622. parent_id, _ := c.GetInt64("parent_id", 0)
  2623. execution_time := c.GetString("execution_time")
  2624. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  2625. // checker, _ := c.GetInt64("checker", 0)
  2626. if id <= 0 || patient <= 0 {
  2627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2628. return
  2629. }
  2630. adminUserInfo := c.GetAdminUserInfo()
  2631. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2632. if advice.ID == 0 || advice.PatientId != patient {
  2633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2634. return
  2635. }
  2636. if len(execution_time) <= 0 {
  2637. utils.ErrorLog("execution_time")
  2638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2639. return
  2640. }
  2641. execution_staff := adminUserInfo.AdminUser.Id
  2642. checker := adminUserInfo.AdminUser.Id
  2643. timeLayout2 := "2006-01-02 15:04"
  2644. loc, _ := time.LoadLocation("Local")
  2645. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  2646. if errs != nil {
  2647. utils.ErrorLog(errs.Error())
  2648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2649. return
  2650. }
  2651. advices := models.DoctorAdvice{
  2652. ExecutionStaff: execution_staff,
  2653. ExecutionTime: theTime.Unix(),
  2654. Checker: checker,
  2655. UpdatedTime: time.Now().Unix(),
  2656. }
  2657. var err error
  2658. if parent_id > 0 {
  2659. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  2660. } else {
  2661. err = service.ExceDoctorAdviceById(&advices, id, patient)
  2662. }
  2663. if err != nil {
  2664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2665. return
  2666. }
  2667. c.ServeSuccessJSON(map[string]interface{}{
  2668. "msg": "ok",
  2669. "advice": advice,
  2670. })
  2671. return
  2672. }
  2673. func (c *DialysisApiController) GetDoctorAdvice() {
  2674. patient, _ := c.GetInt64("patient_id", 0)
  2675. parent_id, _ := c.GetInt64("parent_id", 0)
  2676. adviceId, _ := c.GetInt64("id", 0)
  2677. if patient <= 0 {
  2678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2679. return
  2680. }
  2681. dminUserInfo := c.GetAdminUserInfo()
  2682. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  2683. if patientInfo.ID == 0 {
  2684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2685. return
  2686. }
  2687. var subAdvice []*models.DoctorAdvice
  2688. var advice models.DoctorAdvice
  2689. if parent_id > 0 {
  2690. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  2691. if advice.ID == 0 || advice.PatientId != patient {
  2692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2693. return
  2694. }
  2695. subAdvice = service.FindSubAdivceById(patient, parent_id)
  2696. } else {
  2697. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  2698. if advice.ID == 0 || advice.PatientId != patient {
  2699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2700. return
  2701. }
  2702. subAdvice = service.FindSubAdivceById(patient, adviceId)
  2703. }
  2704. c.ServeSuccessJSON(map[string]interface{}{
  2705. "msg": "ok",
  2706. "advice": advice,
  2707. "subAdvice": subAdvice,
  2708. })
  2709. }
  2710. func (this *DialysisApiController) DelMonitor() {
  2711. recordID, _ := this.GetInt64("record_id")
  2712. patientID, _ := this.GetInt64("patient_id")
  2713. if recordID <= 0 || patientID <= 0 {
  2714. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2715. return
  2716. }
  2717. adminInfo := this.GetAdminUserInfo()
  2718. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  2719. if getPatientErr != nil {
  2720. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2721. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2722. return
  2723. } else if patient == nil {
  2724. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2725. return
  2726. }
  2727. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  2728. if getMonitorErr != nil {
  2729. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2730. return
  2731. }
  2732. //if monitor != nil {
  2733. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  2734. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2735. // if getPermissionErr != nil {
  2736. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2737. // return
  2738. // } else if headNursePermission == nil {
  2739. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2740. // return
  2741. // }
  2742. // }
  2743. //}
  2744. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  2745. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  2746. redis := service.RedisClient()
  2747. //清空key 值
  2748. redis.Set(key, "", time.Second)
  2749. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  2750. redis.Set(keyOne, "", time.Second)
  2751. defer redis.Close()
  2752. if err != nil {
  2753. this.ErrorLog("删除透析监测记录失败:%v", err)
  2754. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  2755. return
  2756. }
  2757. this.ServeSuccessJSON(map[string]interface{}{
  2758. "record_id": monitor.ID,
  2759. })
  2760. }
  2761. func (c *DialysisApiController) CreateMonitor() {
  2762. patient, _ := c.GetInt64("id", 0)
  2763. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  2764. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  2765. operate_time, _ := c.GetInt64("operate_time", 0)
  2766. // monitoring_time := c.GetString("monitoring_time")
  2767. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  2768. breathing_rated := c.GetString("breathing_rated")
  2769. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  2770. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  2771. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  2772. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  2773. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  2774. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  2775. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  2776. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  2777. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  2778. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  2779. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  2780. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  2781. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  2782. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  2783. temperature, _ := c.GetFloat("temperature", 0)
  2784. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  2785. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  2786. conductivity, _ := c.GetFloat("conductivity", 0)
  2787. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  2788. heparin, _ := c.GetFloat("heparin", 0)
  2789. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  2790. ktv, _ := c.GetFloat("ktv", 0)
  2791. symptom := c.GetString("symptom")
  2792. dispose := c.GetString("dispose")
  2793. result := c.GetString("results")
  2794. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  2795. monitor_anticoagulant, _ := c.GetInt64("monitor_anticoagulant")
  2796. monitor_anticoagulant_value := c.GetString("monitor_anticoagulant_value")
  2797. monitoring_date = monitoring_date / 1000
  2798. // operate_time = operate_time / 1000
  2799. if patient <= 0 {
  2800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2801. return
  2802. }
  2803. adminUserInfo := c.GetAdminUserInfo()
  2804. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2805. if patientInfo.ID == 0 {
  2806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2807. return
  2808. }
  2809. monitorRecord := models.MonitoringRecord{
  2810. PatientId: patient,
  2811. MonitoringDate: monitoring_date,
  2812. DialysisOrderId: dialysis_order_id,
  2813. OperateTime: operate_time,
  2814. // MonitoringTime: monitoring_time,
  2815. PulseFrequency: pulse_frequency,
  2816. BreathingRate: breathing_rated,
  2817. SystolicBloodPressure: systolic_blood_pressure,
  2818. DiastolicBloodPressure: diastolic_blood_pressure,
  2819. BloodPressureType: blood_pressure_type,
  2820. BloodFlowVolume: blood_flow_volume,
  2821. VenousPressure: venous_pressure,
  2822. VenousPressureType: venous_pressure_type,
  2823. TransmembranePressure: transmembrane_pressure,
  2824. TransmembranePressureType: transmembrane_pressure_type,
  2825. UltrafiltrationRate: ultrafiltration_rate,
  2826. UltrafiltrationVolume: ultrafiltration_volume,
  2827. SodiumConcentration: sodium_concentration,
  2828. ArterialPressure: arterial_pressure,
  2829. ArterialPressureType: arterial_pressure_type,
  2830. DialysateTemperature: dialysate_temperature,
  2831. Temperature: temperature,
  2832. ReplacementRate: replacement_rate,
  2833. DisplacementQuantity: displacement_quantity,
  2834. Ktv: ktv,
  2835. Symptom: symptom,
  2836. Dispose: dispose,
  2837. Result: result,
  2838. MonitoringNurse: monitoring_nurse,
  2839. Status: 1,
  2840. CreatedTime: time.Now().Unix(),
  2841. UpdatedTime: time.Now().Unix(),
  2842. UserOrgId: adminUserInfo.CurrentOrgId,
  2843. Conductivity: conductivity,
  2844. DisplacementFlowQuantity: displacement_flow_quantity,
  2845. Heparin: heparin,
  2846. DialysateFlow: dialysate_flow,
  2847. MonitorAnticoagulant: monitor_anticoagulant,
  2848. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  2849. }
  2850. err := service.CreateMonitor(&monitorRecord)
  2851. redis := service.RedisClient()
  2852. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_record_list_all"
  2853. redis.Set(key, "", time.Second)
  2854. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  2855. redis.Set(keyOne, "", time.Second)
  2856. redis.Close()
  2857. if err != nil {
  2858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2859. return
  2860. }
  2861. c.ServeSuccessJSON(map[string]interface{}{
  2862. "msg": "ok",
  2863. "monitor": monitorRecord,
  2864. })
  2865. return
  2866. }
  2867. // 已弃用
  2868. // func (c *DialysisApiController) CreateRecordData() {
  2869. // patient, _ := c.GetInt64("id", 0)
  2870. // status, _ := c.GetInt64("status", 0)
  2871. // now := time.Now()
  2872. // year, month, day := now.Date()
  2873. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2874. // todayTimeStamp := today_time.Unix()
  2875. // if patient <= 0 {
  2876. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2877. // return
  2878. // }
  2879. // adminUserInfo := c.GetAdminUserInfo()
  2880. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2881. // if patientInfo.ID == 0 {
  2882. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2883. // return
  2884. // }
  2885. // record := &models.DialysisOrder{
  2886. // DialysisDate: todayTimeStamp,
  2887. // UserOrgId: adminUserInfo.CurrentOrgId,
  2888. // PatientId: patient,
  2889. // Stage: status,
  2890. // Status: 1,
  2891. // CreatedTime: time.Now().Unix(),
  2892. // UpdatedTime: time.Now().Unix(),
  2893. // }
  2894. // if status == 1 {
  2895. // //创建透析记录
  2896. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  2897. // if err == nil {
  2898. // c.ServeSuccessJSON(map[string]interface{}{
  2899. // "dialysisOrder": record,
  2900. // })
  2901. // } else {
  2902. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2903. // }
  2904. // } else {
  2905. // record_id, _ := c.GetInt64("record_id", 0)
  2906. // //修改透析记录状态
  2907. // errs := service.ModifyDialysisRecord(record_id)
  2908. // //结束时候透析次数加1
  2909. // service.UpdateSolutionByPatientId(patient)
  2910. // if errs == nil {
  2911. // c.ServeSuccessJSON(map[string]interface{}{
  2912. // "dialysisOrder": record,
  2913. // })
  2914. // } else {
  2915. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2916. // }
  2917. // }
  2918. // }
  2919. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  2920. dataBody := make(map[string]interface{}, 0)
  2921. err := json.Unmarshal(data, &dataBody)
  2922. if err != nil {
  2923. utils.ErrorLog(err.Error())
  2924. code = enums.ErrorCodeParamWrong
  2925. return
  2926. }
  2927. timeLayout := "2006-01-02 "
  2928. timeLayout2 := "2006-01-02 15:04"
  2929. loc, _ := time.LoadLocation("Local")
  2930. if action == "create" {
  2931. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2932. utils.ErrorLog("advice_type")
  2933. code = enums.ErrorCodeParamWrong
  2934. return
  2935. }
  2936. adviceType := int64(dataBody["advice_type"].(float64))
  2937. if adviceType != 1 && adviceType != 2 {
  2938. utils.ErrorLog("advice_type != 1&&2")
  2939. code = enums.ErrorCodeParamWrong
  2940. return
  2941. }
  2942. advice.AdviceType = adviceType
  2943. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2944. utils.ErrorLog("advice_date")
  2945. code = enums.ErrorCodeParamWrong
  2946. return
  2947. }
  2948. adviceDate, _ := dataBody["advice_date"].(string)
  2949. if len(adviceDate) == 0 {
  2950. utils.ErrorLog("len(adviceDate) == 0")
  2951. code = enums.ErrorCodeParamWrong
  2952. return
  2953. }
  2954. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2955. if err != nil {
  2956. utils.ErrorLog(err.Error())
  2957. code = enums.ErrorCodeParamWrong
  2958. return
  2959. }
  2960. advice.AdviceDate = theTime.Unix()
  2961. }
  2962. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2963. utils.ErrorLog("start_time")
  2964. code = enums.ErrorCodeParamWrong
  2965. return
  2966. }
  2967. startDate, _ := dataBody["start_time"].(string)
  2968. if len(startDate) == 0 {
  2969. utils.ErrorLog("len(startDate) == 0")
  2970. code = enums.ErrorCodeParamWrong
  2971. return
  2972. }
  2973. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  2974. if err != nil {
  2975. utils.ErrorLog(err.Error())
  2976. code = enums.ErrorCodeParamWrong
  2977. return
  2978. }
  2979. advice.StartTime = theTime.Unix()
  2980. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2981. utils.ErrorLog("advice_name")
  2982. code = enums.ErrorCodeParamWrong
  2983. return
  2984. }
  2985. adviceName, _ := dataBody["advice_name"].(string)
  2986. if len(adviceName) == 0 {
  2987. utils.ErrorLog("len(advice_name) == 0")
  2988. code = enums.ErrorCodeParamWrong
  2989. return
  2990. }
  2991. advice.AdviceName = adviceName
  2992. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  2993. utils.ErrorLog("delivery_way")
  2994. code = enums.ErrorCodeParamWrong
  2995. return
  2996. }
  2997. deliveryWay, _ := dataBody["delivery_way"].(string)
  2998. if len(deliveryWay) == 0 {
  2999. utils.ErrorLog("len(deliveryWay) == 0")
  3000. code = enums.ErrorCodeParamWrong
  3001. return
  3002. }
  3003. advice.DeliveryWay = deliveryWay
  3004. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  3005. utils.ErrorLog("execution_frequency")
  3006. code = enums.ErrorCodeParamWrong
  3007. return
  3008. }
  3009. execution_frequency, _ := dataBody["execution_frequency"].(string)
  3010. if len(execution_frequency) == 0 {
  3011. utils.ErrorLog("len(execution_frequency) == 0")
  3012. code = enums.ErrorCodeParamWrong
  3013. return
  3014. }
  3015. advice.ExecutionFrequency = execution_frequency
  3016. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3017. adviceDsc, _ := dataBody["advice_desc"].(string)
  3018. advice.AdviceDesc = adviceDsc
  3019. }
  3020. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3021. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3022. advice.DrugSpecUnit = drugSpecUnit
  3023. }
  3024. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3025. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3026. advice.SingleDose = singleDose
  3027. }
  3028. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3029. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3030. advice.SingleDoseUnit = singleDoseUnit
  3031. }
  3032. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3033. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3034. advice.PrescribingNumber = prescribingNumber
  3035. }
  3036. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3037. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3038. advice.PrescribingNumberUnit = prescribingNumberUnit
  3039. }
  3040. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  3041. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  3042. if len(thisContagions) > 0 {
  3043. for _, item := range thisContagions {
  3044. items := item.(map[string]interface{})
  3045. advice_name, _ := items["advice_name"].(string)
  3046. advice_desc, _ := items["advice_desc"].(string)
  3047. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  3048. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  3049. single_dose_unit, _ := items["single_dose_unit"].(string)
  3050. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  3051. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  3052. advice := &models.DoctorAdvice{
  3053. AdviceName: advice_name,
  3054. AdviceDesc: advice_desc,
  3055. SingleDose: single_dose,
  3056. SingleDoseUnit: single_dose_unit,
  3057. DrugSpecUnit: drug_spec_unit,
  3058. PrescribingNumber: prescribing_number,
  3059. PrescribingNumberUnit: prescribing_number_unit,
  3060. }
  3061. subAdvice = append(subAdvice, advice)
  3062. }
  3063. }
  3064. }
  3065. return
  3066. }
  3067. func (c *DialysisApiController) GetDialysisOrder() {
  3068. //xtno := c.GetString("xtno")
  3069. xtdate := c.GetString("xtdate")
  3070. patient_id, _ := c.GetInt64("patient_id")
  3071. timeLayout := "2006-01-02"
  3072. loc, _ := time.LoadLocation("Local")
  3073. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  3074. if err != nil {
  3075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3076. return
  3077. }
  3078. xttime := theTime.Unix()
  3079. operatorIDs := make([]int64, 0)
  3080. adminUserInfo := c.GetAdminUserInfo()
  3081. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  3082. patientInfo, _ := service.FindPatientWithDeviceByPatientId(adminUserInfo.CurrentOrgId, patient_id, xttime)
  3083. //透析单
  3084. dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3085. if dialysisOrder != nil {
  3086. if dialysisOrder.FinishNurse > 0 {
  3087. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  3088. }
  3089. if dialysisOrder.StartNurse > 0 {
  3090. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  3091. }
  3092. }
  3093. //透前评估
  3094. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3095. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  3096. //透后评估
  3097. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3098. if AssessmentAfterDislysis.Modifier > 0 {
  3099. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  3100. }
  3101. //上次透前评估
  3102. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3103. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3104. //透析处方
  3105. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3106. if dialysisPrescription.PrescriptionDoctor > 0 {
  3107. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  3108. }
  3109. //获取病人的透析模式
  3110. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3111. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3112. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3113. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3114. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3115. //获取透析处方
  3116. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3117. //获取临时医嘱
  3118. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3119. //config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3120. //获取医嘱内容
  3121. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3122. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3123. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3124. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3125. //获取上次的透后体重
  3126. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3127. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3128. //获取透析次数
  3129. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  3130. if len(DoctorAdvice) > 0 {
  3131. for _, item := range DoctorAdvice {
  3132. if item.AdviceDoctor > 0 {
  3133. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3134. }
  3135. if item.ExecutionStaff > 0 {
  3136. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3137. }
  3138. if item.Checker > 0 {
  3139. operatorIDs = append(operatorIDs, item.Checker)
  3140. }
  3141. }
  3142. }
  3143. //透析监测
  3144. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3145. //透析检测
  3146. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3147. //透析小结
  3148. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3149. //接诊评估
  3150. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3151. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3152. if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 10345 {
  3153. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3154. patientInfo.TotalDialysis = dialysis_count
  3155. }
  3156. if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 10345 {
  3157. if xttime <= 1672416000 {
  3158. dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3159. patientInfo.TotalDialysis = dialysis_count
  3160. }
  3161. if xttime >= 1672502400 {
  3162. dialysis_count, _ := service.GetDialysisOrderCountTwo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3163. patientInfo.TotalDialysis = dialysis_count
  3164. }
  3165. }
  3166. //相关操作对应的操作人
  3167. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3168. operators, err := service.GetAdminUserEsOne(adminUserInfo.CurrentOrgId)
  3169. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  3170. //获取当前日期月份的第一天
  3171. firstmonth := service.GetFirstDateOfMonth(theTime)
  3172. firstMonthDate := firstmonth.Unix()
  3173. //获取当前月份的病人透析次数
  3174. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  3175. //获取his数据
  3176. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3177. //hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3178. config, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3179. project_config, _ := service.GetHisProjectConfig(adminUserInfo.CurrentOrgId)
  3180. projects, _ := service.FindAllHisProjectById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3181. //if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  3182. // for _, item := range projects {
  3183. // var advice *models.HisDoctorAdviceInfo
  3184. // advice.ID = item.ID
  3185. // advice.Checker = item.Checker
  3186. // advice.CheckTime = item.CheckTime
  3187. // advice.CheckState = item.CheckState
  3188. // advice.ExecutionState = item.ExecutionState
  3189. // advice.ExecutionStaff = item.ExecutionStaff
  3190. // advice.PrescribingNumber = float64(item.Count)
  3191. // advice.PrescribingNumberUnit = item.Unit
  3192. // advice.AdviceDoctor = item.Doctor
  3193. // if item.Type == 3 {
  3194. // advice.AdviceName = item.GoodInfo.GoodName
  3195. // } else if item.Type == 2 {
  3196. // advice.AdviceName = item.HisProject.ProjectName
  3197. // }
  3198. // advice.StartTime = item.StartTime
  3199. // hisAdvice = append(hisAdvice, advice)
  3200. // }
  3201. //}
  3202. if config.IsOpen == 1 {
  3203. c.ServeSuccessJSON(map[string]interface{}{
  3204. "xtdate": xtdate,
  3205. "users": adminUser,
  3206. "patientInfo": patientInfo,
  3207. "PredialysisEvaluation": PredialysisEvaluation,
  3208. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3209. "dialysisPrescription": dialysisPrescription,
  3210. "advices": hisAdvice,
  3211. "monitors": Record,
  3212. "summary": TreatmentSummary,
  3213. "receiverTreatmentAccess": receiverTreatmentAccess,
  3214. "dialysisOrder": dialysisOrder,
  3215. "operators": operators,
  3216. "org_template_info": templateInfo,
  3217. "check": check,
  3218. "schedule": schedule,
  3219. "dialysisway": dialysisway,
  3220. "order": order,
  3221. "doctorAdvice": doctorAdvice,
  3222. "doctor": doctor,
  3223. "nurse": nurse,
  3224. "doctorAdevieInfo": doctorAdevieInfo,
  3225. "total": total,
  3226. "startNuse": startNuse,
  3227. "DoctorName": DoctorName,
  3228. "assessmentAfterDislysis": assessmentAfterDislysis,
  3229. "predialysName": predialysName,
  3230. "FinishNuse": FinishNuse,
  3231. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3232. "dialysiscount": dialysiscount,
  3233. "last_order": lastOrder,
  3234. "project_config": project_config,
  3235. "projects": projects,
  3236. })
  3237. }
  3238. if config.IsOpen == 0 || config.IsOpen == 2 {
  3239. c.ServeSuccessJSON(map[string]interface{}{
  3240. "xtdate": xtdate,
  3241. "users": adminUser,
  3242. "patientInfo": patientInfo,
  3243. "PredialysisEvaluation": PredialysisEvaluation,
  3244. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3245. "dialysisPrescription": dialysisPrescription,
  3246. "advices": DoctorAdvice,
  3247. "monitors": Record,
  3248. "summary": TreatmentSummary,
  3249. "receiverTreatmentAccess": receiverTreatmentAccess,
  3250. "dialysisOrder": dialysisOrder,
  3251. "operators": operators,
  3252. "org_template_info": templateInfo,
  3253. "check": check,
  3254. "schedule": schedule,
  3255. "dialysisway": dialysisway,
  3256. "order": order,
  3257. "doctorAdvice": doctorAdvice,
  3258. "doctor": doctor,
  3259. "nurse": nurse,
  3260. "doctorAdevieInfo": doctorAdevieInfo,
  3261. "total": total,
  3262. "startNuse": startNuse,
  3263. "DoctorName": DoctorName,
  3264. "assessmentAfterDislysis": assessmentAfterDislysis,
  3265. "predialysName": predialysName,
  3266. "FinishNuse": FinishNuse,
  3267. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3268. "dialysiscount": dialysiscount,
  3269. "last_order": lastOrder,
  3270. "project_config": project_config,
  3271. "projects": projects,
  3272. })
  3273. }
  3274. }
  3275. func (c *DialysisApiController) GetLongAdvice() {
  3276. patient_id, _ := c.GetInt64("patient_id")
  3277. adminUserInfo := c.GetAdminUserInfo()
  3278. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3279. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3280. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3281. c.ServeSuccessJSON(map[string]interface{}{
  3282. "status": "1",
  3283. })
  3284. return
  3285. } else { //开启推送提醒
  3286. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3287. var advice_three []*models.DoctorAdvice
  3288. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3289. recordDateStr := time.Now().Format("2006-01-02")
  3290. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3291. nowtime := recordDate.Unix()
  3292. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  3293. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  3294. for _, advice := range advices {
  3295. if advice.FrequencyType == 3 {
  3296. t := time.Now()
  3297. week := int(t.Weekday())
  3298. switch week {
  3299. case 1:
  3300. if strings.Index(advice.WeekDay, "周一") == -1 {
  3301. advice_three = append(advice_three, advice)
  3302. }
  3303. break
  3304. case 2:
  3305. if strings.Index(advice.WeekDay, "周二") == -1 {
  3306. advice_three = append(advice_three, advice)
  3307. }
  3308. break
  3309. case 3:
  3310. if strings.Index(advice.WeekDay, "周三") == -1 {
  3311. advice_three = append(advice_three, advice)
  3312. }
  3313. break
  3314. case 4:
  3315. if strings.Index(advice.WeekDay, "周四") == -1 {
  3316. advice_three = append(advice_three, advice)
  3317. }
  3318. break
  3319. case 5:
  3320. if strings.Index(advice.WeekDay, "周五") == -1 {
  3321. advice_three = append(advice_three, advice)
  3322. }
  3323. break
  3324. case 6:
  3325. if strings.Index(advice.WeekDay, "周六") == -1 {
  3326. advice_three = append(advice_three, advice)
  3327. }
  3328. break
  3329. case 0:
  3330. if strings.Index(advice.WeekDay, "周日") == -1 {
  3331. advice_three = append(advice_three, advice)
  3332. }
  3333. break
  3334. }
  3335. }
  3336. }
  3337. for _, advice := range advices_two {
  3338. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3339. now := p.Unix()
  3340. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3341. dayStr2 := "-" + dayStr
  3342. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3343. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3344. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3345. for _, ad := range advices {
  3346. advice_three = append(advice_three, ad)
  3347. }
  3348. }
  3349. if err == nil {
  3350. c.ServeSuccessJSON(map[string]interface{}{
  3351. "status": "2",
  3352. "advices": advices,
  3353. "advices_two": RemoveRepeatedElement(advice_three),
  3354. "is_open_remind": config.IsOpenRemind,
  3355. })
  3356. }
  3357. }
  3358. }
  3359. func (c *DialysisApiController) GetLongAdviceOne() {
  3360. patient_id, _ := c.GetInt64("patient_id")
  3361. schedule_date := c.GetString("schedule_date")
  3362. adminUserInfo := c.GetAdminUserInfo()
  3363. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3364. timeLayout := "2006-01-02"
  3365. loc, _ := time.LoadLocation("Local")
  3366. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  3367. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3368. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3369. c.ServeSuccessJSON(map[string]interface{}{
  3370. "status": "1",
  3371. })
  3372. return
  3373. } else { //开启推送提醒
  3374. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3375. var advice_three []*models.DoctorAdvice
  3376. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3377. //recordDateStr := time.Now().Format("2006-01-02")
  3378. //recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3379. //
  3380. //nowtime := recordDate.Unix()
  3381. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  3382. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  3383. for _, advice := range advices {
  3384. if advice.FrequencyType == 3 {
  3385. t := time.Now()
  3386. week := int(t.Weekday())
  3387. switch week {
  3388. case 1:
  3389. if strings.Index(advice.WeekDay, "周一") == -1 {
  3390. advice_three = append(advice_three, advice)
  3391. }
  3392. break
  3393. case 2:
  3394. if strings.Index(advice.WeekDay, "周二") == -1 {
  3395. advice_three = append(advice_three, advice)
  3396. }
  3397. break
  3398. case 3:
  3399. if strings.Index(advice.WeekDay, "周三") == -1 {
  3400. advice_three = append(advice_three, advice)
  3401. }
  3402. break
  3403. case 4:
  3404. if strings.Index(advice.WeekDay, "周四") == -1 {
  3405. advice_three = append(advice_three, advice)
  3406. }
  3407. break
  3408. case 5:
  3409. if strings.Index(advice.WeekDay, "周五") == -1 {
  3410. advice_three = append(advice_three, advice)
  3411. }
  3412. break
  3413. case 6:
  3414. if strings.Index(advice.WeekDay, "周六") == -1 {
  3415. advice_three = append(advice_three, advice)
  3416. }
  3417. break
  3418. case 0:
  3419. if strings.Index(advice.WeekDay, "周日") == -1 {
  3420. advice_three = append(advice_three, advice)
  3421. }
  3422. break
  3423. }
  3424. }
  3425. }
  3426. for _, advice := range advices_two {
  3427. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3428. now := p.Unix()
  3429. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3430. dayStr2 := "-" + dayStr
  3431. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3432. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3433. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3434. for _, ad := range advices {
  3435. advice_three = append(advice_three, ad)
  3436. }
  3437. }
  3438. if err == nil {
  3439. c.ServeSuccessJSON(map[string]interface{}{
  3440. "status": "2",
  3441. "advices": advices,
  3442. "advices_two": RemoveRepeatedElement(advice_three),
  3443. "is_open_remind": config.IsOpenRemind,
  3444. })
  3445. }
  3446. }
  3447. }
  3448. func (c *DialysisApiController) GetLongAdviceTwo() {
  3449. patient_id, _ := c.GetInt64("patient_id")
  3450. schedule_date, _ := c.GetInt64("schedule_date")
  3451. adminUserInfo := c.GetAdminUserInfo()
  3452. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3453. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3454. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3455. c.ServeSuccessJSON(map[string]interface{}{
  3456. "status": "1",
  3457. })
  3458. return
  3459. } else { //开启推送提醒
  3460. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3461. var advice_three []*models.DoctorAdvice
  3462. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3463. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  3464. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  3465. for _, advice := range advices {
  3466. if advice.FrequencyType == 3 {
  3467. t := time.Now()
  3468. week := int(t.Weekday())
  3469. switch week {
  3470. case 1:
  3471. if strings.Index(advice.WeekDay, "周一") == -1 {
  3472. advice_three = append(advice_three, advice)
  3473. }
  3474. break
  3475. case 2:
  3476. if strings.Index(advice.WeekDay, "周二") == -1 {
  3477. advice_three = append(advice_three, advice)
  3478. }
  3479. break
  3480. case 3:
  3481. if strings.Index(advice.WeekDay, "周三") == -1 {
  3482. advice_three = append(advice_three, advice)
  3483. }
  3484. break
  3485. case 4:
  3486. if strings.Index(advice.WeekDay, "周四") == -1 {
  3487. advice_three = append(advice_three, advice)
  3488. }
  3489. break
  3490. case 5:
  3491. if strings.Index(advice.WeekDay, "周五") == -1 {
  3492. advice_three = append(advice_three, advice)
  3493. }
  3494. break
  3495. case 6:
  3496. if strings.Index(advice.WeekDay, "周六") == -1 {
  3497. advice_three = append(advice_three, advice)
  3498. }
  3499. break
  3500. case 0:
  3501. if strings.Index(advice.WeekDay, "周日") == -1 {
  3502. advice_three = append(advice_three, advice)
  3503. }
  3504. break
  3505. }
  3506. }
  3507. }
  3508. for _, advice := range advices_two {
  3509. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3510. now := p.Unix()
  3511. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3512. dayStr2 := "-" + dayStr
  3513. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3514. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3515. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3516. for _, ad := range advices {
  3517. advice_three = append(advice_three, ad)
  3518. }
  3519. }
  3520. if err == nil {
  3521. c.ServeSuccessJSON(map[string]interface{}{
  3522. "status": "2",
  3523. "advices": advices,
  3524. "advices_two": RemoveRepeatedElement(advice_three),
  3525. "is_open_remind": config.IsOpenRemind,
  3526. })
  3527. }
  3528. }
  3529. }
  3530. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  3531. newArr = make([]*models.DoctorAdvice, 0)
  3532. for i := 0; i < len(arr); i++ {
  3533. repeat := false
  3534. for j := i + 1; j < len(arr); j++ {
  3535. if arr[i].ID == arr[j].ID {
  3536. repeat = true
  3537. break
  3538. }
  3539. }
  3540. if !repeat {
  3541. newArr = append(newArr, arr[i])
  3542. }
  3543. }
  3544. return
  3545. }
  3546. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  3547. patient, _ := c.GetInt64("id", 0)
  3548. groupNo, _ := c.GetInt64("groupno", 0)
  3549. if patient <= 0 {
  3550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3551. return
  3552. }
  3553. adminUserInfo := c.GetAdminUserInfo()
  3554. dataBody := make(map[string]interface{}, 0)
  3555. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3556. if err != nil {
  3557. utils.ErrorLog(err.Error())
  3558. return
  3559. }
  3560. utils.ErrorLog("%v", dataBody)
  3561. timeLayout := "2006-01-02 15:04"
  3562. loc, _ := time.LoadLocation("Local")
  3563. timeLayout2 := "2006-01-02"
  3564. loc2, _ := time.LoadLocation("Local")
  3565. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3566. utils.ErrorLog("advice_type")
  3567. return
  3568. }
  3569. adviceType := int64(2)
  3570. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3571. utils.ErrorLog("advice_date")
  3572. return
  3573. }
  3574. adviceDate, _ := dataBody["advice_date"].(string)
  3575. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  3576. AdviceDate := theTime.Unix()
  3577. RecordDate := theTime.Unix()
  3578. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3579. utils.ErrorLog("start_time")
  3580. return
  3581. }
  3582. startTime, _ := dataBody["start_time"].(string)
  3583. if len(startTime) == 0 {
  3584. utils.ErrorLog("len(start_time) == 0")
  3585. return
  3586. }
  3587. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  3588. if err != nil {
  3589. utils.ErrorLog(err.Error())
  3590. return
  3591. }
  3592. StartTime := theTimeUnix.Unix()
  3593. fmt.Println("startTIME", StartTime)
  3594. Remark := ""
  3595. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3596. remark, _ := dataBody["remark"].(string)
  3597. Remark = remark
  3598. }
  3599. var advices []*models.GroupAdvice
  3600. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  3601. utils.ErrorLog("advices")
  3602. return
  3603. }
  3604. adviceNames := dataBody["advices"].([]interface{})
  3605. for _, adviceNameMap := range adviceNames {
  3606. adviceNameM := adviceNameMap.(map[string]interface{})
  3607. var advice models.GroupAdvice
  3608. advice.Remark = Remark
  3609. advice.AdviceType = adviceType
  3610. advice.StartTime = StartTime
  3611. advice.AdviceDate = AdviceDate
  3612. advice.RecordDate = RecordDate
  3613. advice.Status = 1
  3614. advice.CreatedTime = time.Now().Unix()
  3615. advice.UpdatedTime = time.Now().Unix()
  3616. advice.StopState = 2
  3617. advice.ExecutionState = 2
  3618. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3619. advice.PatientId = patient
  3620. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3621. advice.IsSettle = 2
  3622. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  3623. utils.ErrorLog("advice_name")
  3624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3625. return
  3626. }
  3627. adviceName, _ := adviceNameM["advice_name"].(string)
  3628. if len(adviceName) == 0 {
  3629. utils.ErrorLog("len(advice_name) == 0")
  3630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3631. return
  3632. }
  3633. advice.AdviceName = adviceName
  3634. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  3635. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  3636. advice.DrugSpec = drugSpec
  3637. }
  3638. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  3639. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  3640. advice.AdviceDesc = adviceDesc
  3641. }
  3642. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  3643. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  3644. advice.DrugSpecUnit = drugSpecUnit
  3645. }
  3646. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  3647. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  3648. // advice.SingleDose = singleDose
  3649. //}
  3650. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  3651. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3652. advice.SingleDose = adviceNameM["single_dose"].(float64)
  3653. }
  3654. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  3655. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  3656. advice.SingleDoseUnit = singleDoseUnit
  3657. }
  3658. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  3659. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  3660. // advice.PrescribingNumber = prescribingNumber
  3661. //}
  3662. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  3663. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  3664. }
  3665. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  3666. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  3667. advice.PrescribingNumberUnit = prescribingNumberUnit
  3668. }
  3669. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  3670. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  3671. advice.DeliveryWay = deliveryWay
  3672. }
  3673. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3674. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3675. advice.ExecutionFrequency = executionFrequency
  3676. }
  3677. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  3678. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  3679. advice.FrequencyType = frequency_type
  3680. }
  3681. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  3682. day_count := int64(adviceNameM["day_count"].(float64))
  3683. advice.DayCount = day_count
  3684. }
  3685. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  3686. way := int64(adviceNameM["way"].(float64))
  3687. advice.Way = way
  3688. }
  3689. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  3690. drug_id := int64(adviceNameM["drug_id"].(float64))
  3691. advice.DrugId = drug_id
  3692. }
  3693. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  3694. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  3695. advice.DrugNameId = drug_name_id
  3696. }
  3697. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  3698. week_day, _ := adviceNameM["week_day"].(string)
  3699. advice.WeekDay = week_day
  3700. }
  3701. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  3702. template_id, _ := adviceNameM["template_id"].(string)
  3703. advice.TemplateId = template_id
  3704. }
  3705. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3706. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3707. advice.ExecutionFrequency = executionFrequency
  3708. }
  3709. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  3710. children := adviceNameM["child"].([]interface{})
  3711. if len(children) > 0 {
  3712. for _, childrenMap := range children {
  3713. childMap := childrenMap.(map[string]interface{})
  3714. var child models.GroupAdvice
  3715. child.Remark = Remark
  3716. child.AdviceType = adviceType
  3717. child.StartTime = StartTime
  3718. child.AdviceDate = AdviceDate
  3719. child.RecordDate = RecordDate
  3720. child.Status = 1
  3721. child.CreatedTime = time.Now().Unix()
  3722. child.UpdatedTime = time.Now().Unix()
  3723. child.StopState = 2
  3724. child.ExecutionState = 2
  3725. child.UserOrgId = adminUserInfo.CurrentOrgId
  3726. child.PatientId = patient
  3727. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  3728. child.IsSettle = 2
  3729. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  3730. utils.ErrorLog("child advice_name")
  3731. return
  3732. }
  3733. childAdviceName, _ := childMap["advice_name"].(string)
  3734. if len(childAdviceName) == 0 {
  3735. utils.ErrorLog("len(child advice_name) == 0")
  3736. return
  3737. }
  3738. child.AdviceName = childAdviceName
  3739. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  3740. childAdviceDesc, _ := childMap["advice_desc"].(string)
  3741. child.AdviceDesc = childAdviceDesc
  3742. }
  3743. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  3744. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  3745. child.DrugSpec = childDrugSpec
  3746. }
  3747. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  3748. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  3749. child.DrugSpecUnit = childDrugSpecUnit
  3750. }
  3751. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  3752. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3753. child.SingleDose = childSingleDose
  3754. }
  3755. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  3756. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3757. child.SingleDose = childMap["single_dose"].(float64)
  3758. }
  3759. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  3760. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3761. child.Remark = childMap["remark"].(string)
  3762. }
  3763. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  3764. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3765. child.DrugId = int64(childMap["drug_id"].(float64))
  3766. }
  3767. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  3768. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  3769. child.SingleDoseUnit = childSingleDoseUnit
  3770. }
  3771. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  3772. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  3773. child.PrescribingNumber = childPrescribingNumber
  3774. }
  3775. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  3776. //childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  3777. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  3778. }
  3779. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  3780. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  3781. child.PrescribingNumberUnit = childPrescribingNumberUnit
  3782. }
  3783. child.DeliveryWay = advice.DeliveryWay
  3784. child.ExecutionFrequency = advice.ExecutionFrequency
  3785. advice.Children = append(advice.Children, &child)
  3786. }
  3787. }
  3788. }
  3789. advices = append(advices, &advice)
  3790. }
  3791. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  3792. redis := service.RedisClient()
  3793. formatAdviceDate := theTime.Format("2006-01-02")
  3794. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3795. redis.Set(key, "", time.Second)
  3796. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  3797. redis.Set(keyOne, "", time.Second)
  3798. keyFour := "scheduals_" + formatAdviceDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3799. redis.Set(keyFour, "", time.Second)
  3800. defer redis.Close()
  3801. if err != nil {
  3802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3803. return
  3804. }
  3805. c.ServeSuccessJSON(map[string]interface{}{
  3806. "msg": "ok",
  3807. "advices": list,
  3808. })
  3809. return
  3810. }
  3811. func (c *DialysisApiController) GetSolution() {
  3812. patient_id, _ := c.GetInt64("patient_id")
  3813. mode_id, _ := c.GetInt64("mode_id")
  3814. adminUserInfo := c.GetAdminUserInfo()
  3815. solution, err := service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  3816. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  3817. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, mode_id)
  3818. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.CurrentOrgId)
  3819. if err != nil {
  3820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3821. return
  3822. }
  3823. c.ServeSuccessJSON(map[string]interface{}{
  3824. "solution": solution,
  3825. "prescription": prescription,
  3826. "system_prescription": system_prescription,
  3827. "dialysisPrescription": dialysisPrescription,
  3828. })
  3829. }
  3830. func (c *DialysisApiController) GetSchedule() {
  3831. schedual_type, _ := c.GetInt64("schedual_type")
  3832. adminUserInfo := c.GetAdminUserInfo()
  3833. //timeLayout := "2006-01-02 15:04:05"
  3834. //
  3835. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  3836. //loc, _ := time.LoadLocation("Local")
  3837. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  3838. //scheduleTime := theStartTime.Unix()
  3839. scheduleTime, _ := c.GetInt64("record_date")
  3840. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  3841. c.ServeSuccessJSON(map[string]interface{}{
  3842. "number": deviceNumber,
  3843. })
  3844. }
  3845. func (this *DialysisApiController) GetTodayMonitor() {
  3846. thisTime := time.Now()
  3847. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3848. timeLayout := "2006-01-02 15:04:05"
  3849. loc, _ := time.LoadLocation("Local")
  3850. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3851. theAssessmentDateTime := theStartTime.Unix()
  3852. patientID, _ := this.GetInt64("patient_id")
  3853. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3854. adminInfo := this.GetAdminUserInfo()
  3855. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  3856. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  3857. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  3858. var ultrafiltration_rate float64
  3859. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  3860. //针对福建医师汇 获取透前评估预增脱水量
  3861. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  3862. fmt.Println("透前评估数据", evaluation)
  3863. if prescription.ID > 0 {
  3864. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3865. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3866. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  3867. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3868. record.UltrafiltrationRate = ultrafiltration_rate
  3869. }
  3870. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10121 {
  3871. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3872. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3873. record.UltrafiltrationRate = ultrafiltration_rate
  3874. }
  3875. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10234 {
  3876. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3877. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3878. record.UltrafiltrationRate = ultrafiltration_rate
  3879. }
  3880. if template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.CurrentOrgId == 9538
  3881. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3882. record.UltrafiltrationRate = ultrafiltration_rate
  3883. }
  3884. if template.TemplateId == 41 { //adminInfo.CurrentOrgId == 9538
  3885. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3886. record.UltrafiltrationRate = ultrafiltration_rate
  3887. }
  3888. if template.TemplateId == 43 { //adminInfo.CurrentOrgId == 9538
  3889. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3890. record.UltrafiltrationRate = ultrafiltration_rate
  3891. }
  3892. if template.TemplateId == 46 || template.TemplateId == 54 { //adminInfo.CurrentOrgId == 9538
  3893. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3894. record.UltrafiltrationRate = ultrafiltration_rate
  3895. }
  3896. if template.TemplateId == 47 { //adminInfo.CurrentOrgId == 9538
  3897. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3898. record.UltrafiltrationRate = ultrafiltration_rate
  3899. }
  3900. // 只针对方济医院
  3901. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  3902. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3903. ultrafiltration_rate = value
  3904. record.UltrafiltrationRate = ultrafiltration_rate
  3905. }
  3906. //长沙南雅
  3907. if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10340 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 9829 || adminInfo.CurrentOrgId == 10440 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
  3908. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3909. record.UltrafiltrationRate = ultrafiltration_rate
  3910. }
  3911. }
  3912. }
  3913. // record.UltrafiltrationRate = ultrafiltration_rate
  3914. record.UltrafiltrationVolume = 0
  3915. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  3916. if ultrafiltration_rate > 0 {
  3917. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3918. record.UltrafiltrationVolume = value
  3919. }
  3920. }
  3921. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 {
  3922. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  3923. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3924. record.UltrafiltrationVolume = ultrafiltration_volume
  3925. }
  3926. }
  3927. //长沙南雅
  3928. if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
  3929. if ultrafiltration_rate > 0 {
  3930. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3931. record.UltrafiltrationVolume = ultrafiltration_volume
  3932. }
  3933. }
  3934. if template.TemplateId == 47 || template.TemplateId == 54 {
  3935. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3936. }
  3937. this.ServeSuccessJSON(map[string]interface{}{
  3938. "monitor": record,
  3939. })
  3940. }
  3941. func (c *DialysisApiController) UploadDryWeight() {
  3942. patient_id, _ := c.GetInt64("id")
  3943. dry_weight, _ := c.GetFloat("dry_weight")
  3944. doctor_id, _ := c.GetInt64("doctor_id")
  3945. remark := c.GetString("remark")
  3946. adminUserInfo := c.GetAdminUserInfo()
  3947. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  3948. fmt.Println(err)
  3949. if err == gorm.ErrRecordNotFound {
  3950. dryWeight := &models.SgjPatientDryweight{
  3951. PatientId: patient_id,
  3952. DryWeight: dry_weight,
  3953. Remakes: remark,
  3954. Ctime: time.Now().Unix(),
  3955. Mtime: time.Now().Unix(),
  3956. Creator: doctor_id,
  3957. Status: 1,
  3958. UserOrgId: adminUserInfo.CurrentOrgId,
  3959. AdjustedValue: "/",
  3960. UserId: adminUserInfo.AdminUser.Id,
  3961. }
  3962. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3963. loc, _ := time.LoadLocation("Local")
  3964. nowTime := time.Now()
  3965. nowDay := nowTime.Format("2006-01-02")
  3966. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3967. redis := service.RedisClient()
  3968. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  3969. redis.Set(keyOne, "", time.Second)
  3970. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3971. redis.Set(key, "", time.Second)
  3972. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3973. redis.Set(keyTwo, "", time.Second)
  3974. redis.Close()
  3975. if createErr == nil {
  3976. c.ServeSuccessJSON(map[string]interface{}{
  3977. "msg": "提交成功",
  3978. "weight": dryWeight,
  3979. })
  3980. }
  3981. } else {
  3982. dryWeight := &models.SgjPatientDryweight{
  3983. PatientId: patient_id,
  3984. DryWeight: dry_weight,
  3985. Remakes: remark,
  3986. Ctime: time.Now().Unix(),
  3987. Mtime: time.Now().Unix(),
  3988. Creator: doctor_id,
  3989. Status: 1,
  3990. UserOrgId: adminUserInfo.CurrentOrgId,
  3991. AdjustedValue: "/",
  3992. UserId: adminUserInfo.AdminUser.Id,
  3993. }
  3994. var value float64
  3995. value = dry_weight - weightAdjust.DryWeight
  3996. fmt.Println(value)
  3997. if value < 0 {
  3998. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  3999. } else if value == 0 {
  4000. dryWeight.AdjustedValue = "/"
  4001. } else if value > 0 {
  4002. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4003. }
  4004. fmt.Println(value)
  4005. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4006. loc, _ := time.LoadLocation("Local")
  4007. nowTime := time.Now()
  4008. nowDay := nowTime.Format("2006-01-02")
  4009. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4010. redis := service.RedisClient()
  4011. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4012. redis.Set(keyOne, "", time.Second)
  4013. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4014. redis.Set(key, "", time.Second)
  4015. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4016. redis.Set(keyTwo, "", time.Second)
  4017. redis.Close()
  4018. if createErr == nil {
  4019. c.ServeSuccessJSON(map[string]interface{}{
  4020. "msg": "提交成功",
  4021. "weight": dryWeight,
  4022. })
  4023. }
  4024. }
  4025. }
  4026. func (this *DialysisApiController) GetFuncPurview() {
  4027. adminUserInfo := this.GetAdminUserInfo()
  4028. user_id := adminUserInfo.AdminUser.Id
  4029. app_id := adminUserInfo.CurrentAppId
  4030. org_id := adminUserInfo.CurrentOrgId
  4031. create_url := this.GetString("create_url")
  4032. modify_url := this.GetString("modify_url")
  4033. modify_other_url := this.GetString("modify_other_url")
  4034. del_url := this.GetString("del_url")
  4035. del_other_url := this.GetString("del_other_url")
  4036. exce_url := this.GetString("exce_url")
  4037. check_url := this.GetString("check_url")
  4038. modify_exce_url := this.GetString("modify_exce_url")
  4039. module, _ := this.GetInt64("module", 0)
  4040. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  4041. var is_has_create bool
  4042. var is_has_modify bool
  4043. var is_has_modify_other bool
  4044. var is_has_del bool
  4045. var is_has_del_other bool
  4046. var is_has_exce bool
  4047. var is_has_check bool
  4048. var is_has_modify_exce bool
  4049. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  4050. if adminUserInfo.AdminUser.Id != org.Creator {
  4051. if app_role != nil {
  4052. if len(app_role.RoleIds) > 0 {
  4053. roles := strings.Split(app_role.RoleIds, ",")
  4054. var userRolePurviews string
  4055. for _, item := range roles {
  4056. role_id, _ := strconv.ParseInt(item, 10, 64)
  4057. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  4058. if len(userRolePurviews) == 0 {
  4059. userRolePurviews = purviews
  4060. } else {
  4061. userRolePurviews = userRolePurviews + "," + purviews
  4062. }
  4063. }
  4064. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  4065. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  4066. for _, item := range funcPurviews {
  4067. //for _, url := range strings.Split(item.Urlfor,","){
  4068. if strings.Split(item.Urlfor, ",")[1] == create_url {
  4069. is_has_create = true
  4070. }
  4071. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  4072. is_has_modify = true
  4073. }
  4074. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  4075. is_has_modify_other = true
  4076. }
  4077. if strings.Split(item.Urlfor, ",")[1] == del_url {
  4078. is_has_del = true
  4079. }
  4080. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  4081. is_has_del_other = true
  4082. }
  4083. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  4084. is_has_exce = true
  4085. }
  4086. if strings.Split(item.Urlfor, ",")[1] == check_url {
  4087. is_has_check = true
  4088. }
  4089. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  4090. is_has_modify_exce = true
  4091. }
  4092. }
  4093. } else {
  4094. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  4095. return
  4096. }
  4097. this.ServeSuccessJSON(map[string]interface{}{
  4098. "is_has_create": is_has_create,
  4099. "is_has_modify": is_has_modify,
  4100. "is_has_modify_other": is_has_modify_other,
  4101. "is_has_del": is_has_del,
  4102. "is_has_del_other": is_has_del_other,
  4103. "is_has_exce": is_has_exce,
  4104. "is_has_check": is_has_check,
  4105. "is_has_modify_exce": is_has_modify_exce,
  4106. "module": module,
  4107. })
  4108. } else {
  4109. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  4110. return
  4111. }
  4112. } else {
  4113. this.ServeSuccessJSON(map[string]interface{}{
  4114. "is_has_create": true,
  4115. "is_has_modify": true,
  4116. "is_has_modify_other": true,
  4117. "is_has_del": true,
  4118. "is_has_del_other": true,
  4119. "is_has_exce": true,
  4120. "is_has_check": true,
  4121. "is_has_modify_exce": true,
  4122. "module": true,
  4123. })
  4124. }
  4125. }
  4126. func (this *DialysisApiController) GetOrderDoctorAdvice() {
  4127. patient_id, _ := this.GetInt64("patient_id", 0)
  4128. advice_date, _ := this.GetInt64("advice_date")
  4129. adminUserInfo := this.GetAdminUserInfo()
  4130. doctorAdvice, _ := service.GetBloodDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4131. hisDoctorAdvice, _ := service.GetHisDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4132. this.ServeSuccessJSON(map[string]interface{}{
  4133. "doctorAdvice": doctorAdvice,
  4134. "hisDoctorAdvice": hisDoctorAdvice,
  4135. })
  4136. }
  4137. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  4138. change_type, _ := this.GetInt64("type", 0)
  4139. record_date := this.GetString("record_time")
  4140. patient_id, _ := this.GetInt64("patient_id", 0)
  4141. timeLayout := "2006-01-02"
  4142. loc, _ := time.LoadLocation("Local")
  4143. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4144. record_time := theAdviceRecordTime.Unix()
  4145. adminUserInfo := this.GetAdminUserInfo()
  4146. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  4147. if err == nil {
  4148. if len(advices) == 0 {
  4149. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4150. return
  4151. } else {
  4152. this.ServeSuccessJSON(map[string]interface{}{
  4153. "advices": advices,
  4154. "schedule": sch,
  4155. })
  4156. return
  4157. }
  4158. } else {
  4159. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4160. return
  4161. }
  4162. }
  4163. func (c *DialysisApiController) GetDialysisGoods() {
  4164. schedualDate := c.GetString("schedule_date")
  4165. schedule_type, _ := c.GetInt64("schedule_type")
  4166. partition_id, _ := c.GetInt64("partition_id")
  4167. page, _ := c.GetInt("page")
  4168. limit, _ := c.GetInt("limit")
  4169. keywords := c.GetString("keywords")
  4170. patient_id, _ := c.GetInt64("patient_id")
  4171. good_type, _ := c.GetInt64("good_type")
  4172. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  4173. if parseDateErr != nil && len(schedualDate) != 0 {
  4174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4175. return
  4176. }
  4177. schedualEndDate := int64(0)
  4178. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  4179. if parseDateErr != nil && len(schedualDate) != 0 {
  4180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4181. return
  4182. }
  4183. schedualEndDate = endDate.Unix()
  4184. adminUser := c.GetAdminUserInfo()
  4185. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  4186. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  4187. if err == gorm.ErrRecordNotFound {
  4188. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4189. var ids []int64
  4190. for _, item := range list {
  4191. ids = append(ids, item.PatientId)
  4192. }
  4193. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4194. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4195. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4196. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4197. item.LastAutomaticReduceDetail = goodUser
  4198. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4199. }
  4200. c.ServeSuccessJSON(map[string]interface{}{
  4201. "dialysis_goods": dialysisGoods,
  4202. "good_type": goodTypes,
  4203. "total": total,
  4204. })
  4205. return
  4206. } else if err == nil {
  4207. //获取当天排班的每个患者的库存使用情况
  4208. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4209. var ids []int64
  4210. for _, item := range list {
  4211. ids = append(ids, item.PatientId)
  4212. }
  4213. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4214. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4215. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4216. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4217. fmt.Println(goodUser)
  4218. fmt.Println(lastGoodUserDetial)
  4219. item.LastAutomaticReduceDetail = goodUser
  4220. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4221. }
  4222. if err == nil {
  4223. c.ServeSuccessJSON(map[string]interface{}{
  4224. "dialysis_goods": dialysisGoods,
  4225. "good_type": goodTypes,
  4226. "total": total,
  4227. })
  4228. return
  4229. } else {
  4230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4231. return
  4232. }
  4233. } else if err != nil {
  4234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4235. return
  4236. }
  4237. }
  4238. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  4239. start_time := c.GetString("start_time")
  4240. end_time := c.GetString("end_time")
  4241. timeLayout := "2006-01-02"
  4242. loc, _ := time.LoadLocation("Local")
  4243. var theStartTime int64
  4244. if len(start_time) > 0 {
  4245. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4246. if err != nil {
  4247. utils.ErrorLog(err.Error())
  4248. }
  4249. theStartTime = theTime.Unix()
  4250. }
  4251. var theEndtTime int64
  4252. if len(end_time) > 0 {
  4253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4254. if err != nil {
  4255. utils.ErrorLog(err.Error())
  4256. }
  4257. theEndtTime = theTime.Unix()
  4258. }
  4259. adminUser := c.GetAdminUserInfo()
  4260. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  4261. if err == nil {
  4262. c.ServeSuccessJSON(map[string]interface{}{
  4263. "stock_out": outInfo,
  4264. })
  4265. return
  4266. } else {
  4267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4268. return
  4269. }
  4270. }
  4271. func (c *DialysisApiController) GetRoleList() {
  4272. orgId := c.GetAdminUserInfo().CurrentOrgId
  4273. admin_user_id, _ := c.GetInt64("admin_user_id")
  4274. list, err := service.GetRoleList(orgId, admin_user_id)
  4275. if err == nil {
  4276. c.ServeSuccessJSON(map[string]interface{}{
  4277. "adminRole": list,
  4278. })
  4279. return
  4280. } else {
  4281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4282. return
  4283. }
  4284. }
  4285. func (c *DialysisApiController) GetInitPrintData() {
  4286. patient_id, _ := c.GetInt64("patient_id")
  4287. record_date, _ := c.GetInt64("record_date")
  4288. orgId := c.GetAdminUserInfo().CurrentOrgId
  4289. list, err := service.GetInitPrintData(patient_id, record_date, orgId)
  4290. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, record_date, orgId)
  4291. if err == nil {
  4292. c.ServeSuccessJSON(map[string]interface{}{
  4293. "list": list,
  4294. "assessmentAfterDislysis": assessmentAfterDislysis,
  4295. })
  4296. return
  4297. } else {
  4298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4299. return
  4300. }
  4301. }
  4302. func (c *DialysisApiController) GetInitPrintDataOne() {
  4303. patient_id, _ := c.GetInt64("patient_id")
  4304. start_time := c.GetString("record_date")
  4305. timeLayout := "2006-01-02"
  4306. loc, _ := time.LoadLocation("Local")
  4307. var theStartTime int64
  4308. if len(start_time) > 0 {
  4309. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4310. if err != nil {
  4311. utils.ErrorLog(err.Error())
  4312. }
  4313. theStartTime = theTime.Unix()
  4314. }
  4315. orgId := c.GetAdminUserInfo().CurrentOrgId
  4316. list, err := service.GetInitPrintData(patient_id, theStartTime, orgId)
  4317. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, theStartTime, orgId)
  4318. if err == nil {
  4319. c.ServeSuccessJSON(map[string]interface{}{
  4320. "list": list,
  4321. "assessmentAfterDislysis": assessmentAfterDislysis,
  4322. })
  4323. return
  4324. } else {
  4325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4326. return
  4327. }
  4328. }
  4329. // 新接口
  4330. func (this *DialysisApiController) GetPatientDialysisSolutionGroupList() {
  4331. keyword := this.GetString("keywords")
  4332. limit, _ := this.GetInt64("limit")
  4333. page, _ := this.GetInt64("page")
  4334. partition_id, _ := this.GetInt64("partition_id")
  4335. schedule_type, _ := this.GetInt64("schedule_type")
  4336. start_time := this.GetString("schedule_date")
  4337. advice_ids := this.GetString("ids")
  4338. var ids []string
  4339. if advice_ids != "" {
  4340. ids = strings.Split(advice_ids, ",")
  4341. }
  4342. timeLayout := "2006-01-02"
  4343. loc, _ := time.LoadLocation("Local")
  4344. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4345. orgId := this.GetAdminUserInfo().CurrentOrgId
  4346. _, config := service.FindXTHisRecordByOrgId(orgId)
  4347. goodType, _ := service.GetAllGoodType(orgId)
  4348. if config.IsOpen != 1 {
  4349. list, total, err := service.GetPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4350. if err == nil {
  4351. this.ServeSuccessJSON(map[string]interface{}{
  4352. "list": list,
  4353. "total": total,
  4354. "config": config,
  4355. "goodType": goodType,
  4356. })
  4357. return
  4358. } else {
  4359. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4360. return
  4361. }
  4362. }
  4363. if config.IsOpen == 1 {
  4364. list, total, err := service.GetHisPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4365. if err == nil {
  4366. this.ServeSuccessJSON(map[string]interface{}{
  4367. "list": list,
  4368. "total": total,
  4369. "config": config,
  4370. "goodType": goodType,
  4371. })
  4372. return
  4373. }
  4374. }
  4375. }
  4376. func (this *DialysisApiController) GetDialysisAdviceTemplateList() {
  4377. keyword := this.GetString("keywords")
  4378. limit, _ := this.GetInt64("limit")
  4379. page, _ := this.GetInt64("page")
  4380. partition_id, _ := this.GetInt64("partition_id")
  4381. schedule_type, _ := this.GetInt64("schedule_type")
  4382. start_time := this.GetString("schedule_date")
  4383. ids := this.GetString("ids")
  4384. var idArray []string
  4385. if ids != "" {
  4386. idArray = strings.Split(ids, ",")
  4387. }
  4388. timeLayout := "2006-01-02"
  4389. loc, _ := time.LoadLocation("Local")
  4390. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4391. orgId := this.GetAdminUserInfo().CurrentOrgId
  4392. list, total, err := service.GetDialysisAdviceTemplateList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  4393. tablelist, _, err := service.GetDialysisAdviceSchedulistSix(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  4394. //获取长期医嘱
  4395. adviceList, _ := service.GetAllLongAdviceList(orgId)
  4396. _, config := service.FindXTHisRecordByOrgId(orgId)
  4397. drugList, _ := service.GetAllBaseDrugListTwenty(orgId)
  4398. if err == nil {
  4399. this.ServeSuccessJSON(map[string]interface{}{
  4400. "list": list,
  4401. "total": total,
  4402. "adviceList": adviceList,
  4403. "config": config,
  4404. "drugList": drugList,
  4405. "tablelist": tablelist,
  4406. })
  4407. return
  4408. } else {
  4409. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4410. return
  4411. }
  4412. }
  4413. func (this *DialysisApiController) SaveDialysisSetting() {
  4414. orgId := this.GetAdminUserInfo().CurrentOrgId
  4415. device_number_set, _ := this.GetInt64("device_number_set")
  4416. device_type_set, _ := this.GetInt64("device_type_set")
  4417. name_set, _ := this.GetInt64("name_set")
  4418. admission_number_set, _ := this.GetInt64("admission_number_set")
  4419. dialysis_no_set, _ := this.GetInt64("dialysis_no_set")
  4420. weight_befor_set, _ := this.GetInt64("weight_befor_set")
  4421. dry_weight_set, _ := this.GetInt64("dry_weight_set")
  4422. blood_pressure_set, _ := this.GetInt64("blood_pressure_set")
  4423. ultrafiltration_volume_set, _ := this.GetInt64("ultrafiltration_volume_set")
  4424. internal_fistula_set, _ := this.GetInt64("internal_fistula_set")
  4425. blood_flow_volume_set, _ := this.GetInt64("blood_flow_volume_set")
  4426. anticoagulant_set, _ := this.GetInt64("anticoagulant_set")
  4427. sealing_fluid_dispose_set, _ := this.GetInt64("sealing_fluid_dispose_set")
  4428. mode_id_set, _ := this.GetInt64("mode_id_set")
  4429. dialysis_time_set, _ := this.GetInt64("dialysis_time_set")
  4430. dialysis_dialyszers_set, _ := this.GetInt64("dialysis_dialyszers_set")
  4431. dialysis_irrigation_set, _ := this.GetInt64("dialysis_irrigation_set")
  4432. gaijiliang_set, _ := this.GetInt64("gaijiliang_set")
  4433. kalium_set, _ := this.GetInt64("kalium_set")
  4434. displace_liqui_value_set, _ := this.GetInt64("displace_liqui_value_set")
  4435. bicarbonate_set, _ := this.GetInt64("bicarbonate_set")
  4436. glucose_set, _ := this.GetInt64("glucose_set")
  4437. sodium_set, _ := this.GetInt64("sodium_set")
  4438. calcium_set, _ := this.GetInt64("calcium_set")
  4439. blood_access_set, _ := this.GetInt64("blood_access_set")
  4440. dialyzer_perfusion_apparatus_set, _ := this.GetInt64("dialyzer_perfusion_apparatus_set")
  4441. displace_liqui_part_set, _ := this.GetInt64("displace_liqui_part_set")
  4442. dialysisSetting := models.XtDialysisSetting{
  4443. Sodium: sodium_set,
  4444. Calcium: calcium_set,
  4445. BloodAccess: blood_access_set,
  4446. DialyzerPerfusionApparatus: dialyzer_perfusion_apparatus_set,
  4447. DisplaceLiquiPart: displace_liqui_part_set,
  4448. UserOrgId: orgId,
  4449. Status: 1,
  4450. DeviceNumber: device_number_set,
  4451. DeviceType: device_type_set,
  4452. Name: name_set,
  4453. AdmissionNumber: admission_number_set,
  4454. DialysisNo: dialysis_no_set,
  4455. WeightBefor: weight_befor_set,
  4456. DryWeight: dry_weight_set,
  4457. BloodPressure: blood_pressure_set,
  4458. UltrafiltrationVolume: ultrafiltration_volume_set,
  4459. InternalFistula: internal_fistula_set,
  4460. BloodFlowVolume: blood_flow_volume_set,
  4461. Anticoagulant: anticoagulant_set,
  4462. SealingFluidDispose: sealing_fluid_dispose_set,
  4463. ModeId: mode_id_set,
  4464. DialysisTime: dialysis_time_set,
  4465. DialysisDialyszers: dialysis_dialyszers_set,
  4466. DialysisIrrigation: dialysis_irrigation_set,
  4467. Gaijiliang: gaijiliang_set,
  4468. Kalium: kalium_set,
  4469. DisplaceLiquiValue: displace_liqui_value_set,
  4470. Bicarbonate: bicarbonate_set,
  4471. Glucose: glucose_set,
  4472. Ctime: time.Now().Unix(),
  4473. Mtime: time.Now().Unix(),
  4474. }
  4475. err := service.SaveDialysisSetting(dialysisSetting)
  4476. if err == nil {
  4477. this.ServeSuccessJSON(map[string]interface{}{
  4478. "dialysisSetting": dialysisSetting,
  4479. })
  4480. return
  4481. } else {
  4482. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4483. return
  4484. }
  4485. }
  4486. func (this *DialysisApiController) GetDialysisSetting() {
  4487. orgId := this.GetAdminUserInfo().CurrentOrgId
  4488. dialysisSett, _ := service.GetDialysisSetting(orgId)
  4489. this.ServeSuccessJSON(map[string]interface{}{
  4490. "dialysisSett": dialysisSett,
  4491. })
  4492. return
  4493. }
  4494. func (this *DialysisApiController) GetDialysisParameterList() {
  4495. keyword := this.GetString("keywords")
  4496. limit, _ := this.GetInt64("limit")
  4497. page, _ := this.GetInt64("page")
  4498. //partition_id, _ := this.GetInt64("partition_id")
  4499. partion_type := this.GetString("partition_id")
  4500. idSplit := strings.Split(partion_type, ",")
  4501. schedule_type, _ := this.GetInt64("schedule_type")
  4502. start_time := this.GetString("schedule_date")
  4503. timeLayout := "2006-01-02"
  4504. loc, _ := time.LoadLocation("Local")
  4505. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4506. orgId := this.GetAdminUserInfo().CurrentOrgId
  4507. scheduids := this.GetString("ids")
  4508. var ids []string
  4509. if scheduids != "" {
  4510. ids = strings.Split(scheduids, ",")
  4511. }
  4512. list, total, err := service.GetDialysisParameterList(keyword, limit, page, idSplit, schedule_type, startTime.Unix(), orgId, ids)
  4513. dialysisSett, _ := service.GetDialysisSetting(orgId)
  4514. if err == nil {
  4515. this.ServeSuccessJSON(map[string]interface{}{
  4516. "list": list,
  4517. "total": total,
  4518. "dialysisSett": dialysisSett,
  4519. })
  4520. return
  4521. } else {
  4522. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4523. return
  4524. }
  4525. }
  4526. func (this *DialysisApiController) GetDialysisGoodTotalCount() {
  4527. orgId := this.GetAdminUserInfo().CurrentOrgId
  4528. schedule_type, _ := this.GetInt64("schedule_type")
  4529. //partion_type, _ := this.GetInt64("partion_type")
  4530. start_time := this.GetString("selected_date")
  4531. partion_type := this.GetString("partion_type")
  4532. var ids []string
  4533. ids = strings.Split(partion_type, ",")
  4534. timeLayout := "2006-01-02"
  4535. loc, _ := time.LoadLocation("Local")
  4536. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4537. list, err := service.GetDialysisGoodTotalCount(orgId, schedule_type, ids, startTime.Unix())
  4538. if err == nil {
  4539. this.ServeSuccessJSON(map[string]interface{}{
  4540. "list": list,
  4541. })
  4542. return
  4543. } else {
  4544. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4545. return
  4546. }
  4547. }
  4548. func (this *DialysisApiController) GetDialysisAdviceSchedulist() {
  4549. orgId := this.GetAdminUserInfo().CurrentOrgId
  4550. schedule_type, _ := this.GetInt64("schedule_type")
  4551. //partion_type, _ := this.GetInt64("partion_type")
  4552. partion_type := this.GetString("partion_type")
  4553. var ids []string
  4554. ids = strings.Split(partion_type, ",")
  4555. start_time := this.GetString("selected_date")
  4556. timeLayout := "2006-01-02"
  4557. loc, _ := time.LoadLocation("Local")
  4558. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4559. list, err := service.GetDialysisAdviceSchedulist(orgId, schedule_type, ids, startTime.Unix())
  4560. tablelist, _ := service.GetDialysisAdviceSchedulistTwo(orgId, schedule_type, ids, startTime.Unix())
  4561. //获取长期医嘱
  4562. adviceList, _ := service.GetAllLongAdviceList(orgId)
  4563. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  4564. _, config := service.FindXTHisRecordByOrgId(orgId)
  4565. if err == nil {
  4566. this.ServeSuccessJSON(map[string]interface{}{
  4567. "list": list,
  4568. "drug": drug,
  4569. "adviceList": adviceList,
  4570. "config": config,
  4571. "tablelist": tablelist,
  4572. })
  4573. return
  4574. } else {
  4575. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4576. return
  4577. }
  4578. }
  4579. func (this *DialysisApiController) GetDialysisParameterGoodList() {
  4580. orgId := this.GetAdminUserInfo().CurrentOrgId
  4581. schedule_type, _ := this.GetInt64("schedule_type")
  4582. partion_type, _ := this.GetInt64("partion_type")
  4583. start_time := this.GetString("selected_date")
  4584. timeLayout := "2006-01-02"
  4585. loc, _ := time.LoadLocation("Local")
  4586. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4587. list, err := service.GetDialysisParameterGoodList(orgId, schedule_type, partion_type, startTime.Unix())
  4588. if err == nil {
  4589. this.ServeSuccessJSON(map[string]interface{}{
  4590. "list": list,
  4591. })
  4592. return
  4593. } else {
  4594. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4595. return
  4596. }
  4597. }
  4598. func (this *DialysisApiController) SaveHisDialysis() {
  4599. var ids []string
  4600. advice_ids := this.GetString("ids")
  4601. ids = strings.Split(advice_ids, ",")
  4602. orgId := this.GetAdminUserInfo().CurrentOrgId
  4603. service.SaveHisDialysis(orgId, ids)
  4604. returnData := make(map[string]interface{}, 0)
  4605. returnData["msg"] = "ok"
  4606. this.ServeSuccessJSON(returnData)
  4607. return
  4608. }
  4609. func (this *DialysisApiController) GetHisDialysisGoodCount() {
  4610. orgId := this.GetAdminUserInfo().CurrentOrgId
  4611. schedule_type, _ := this.GetInt64("schedule_type")
  4612. //partion_type, _ := this.GetInt64("partion_type")
  4613. partion_type := this.GetString("partion_type")
  4614. var ids []string
  4615. ids = strings.Split(partion_type, ",")
  4616. start_time := this.GetString("selected_date")
  4617. timeLayout := "2006-01-02"
  4618. loc, _ := time.LoadLocation("Local")
  4619. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4620. list, _ := service.GetHisDialysisGoodCountTwo(orgId, schedule_type, ids, startTime.Unix())
  4621. this.ServeSuccessJSON(map[string]interface{}{
  4622. "list": list,
  4623. })
  4624. return
  4625. }
  4626. func (this *DialysisApiController) GetPatientSchedule() {
  4627. orgId := this.GetAdminUserInfo().CurrentOrgId
  4628. patient_id, _ := this.GetInt64("patient_id")
  4629. schedule_date, _ := this.GetInt64("schedule_date")
  4630. schedulePatient, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgId)
  4631. this.ServeSuccessJSON(map[string]interface{}{
  4632. "schedulePatient": schedulePatient,
  4633. })
  4634. }
  4635. func (c *DialysisApiController) GetSchedulePrintList() {
  4636. page, _ := c.GetInt64("page", 1)
  4637. limit, _ := c.GetInt64("limit", 10)
  4638. schedulType, _ := c.GetInt64("schedule_type", 0)
  4639. partitionType, _ := c.GetInt64("partition_type", 0)
  4640. keywords := c.GetString("keywords")
  4641. schedule_date := c.GetString("schedule_date")
  4642. timeLayout := "2006-01-02"
  4643. loc, _ := time.LoadLocation("Local")
  4644. var theStartTime int64
  4645. if len(schedule_date) > 0 {
  4646. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  4647. if err != nil {
  4648. utils.ErrorLog(err.Error())
  4649. }
  4650. theStartTime = theTime.Unix()
  4651. }
  4652. adminUserInfo := c.GetAdminUserInfo()
  4653. list, total, _ := service.GetSchedulePrintList(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  4654. for _, item := range list {
  4655. order, _ := service.GetLastOrder(item.UserOrgId, item.PatientId, item.ScheduleDate)
  4656. item.DialysisOrderTwenty = order
  4657. }
  4658. listOne, _ := service.GetSchedulePrintListOne(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  4659. numberList, _ := service.GetAllBedNumberSix(adminUserInfo.CurrentOrgId)
  4660. c.ServeSuccessJSON(map[string]interface{}{
  4661. "list": list,
  4662. "total": total,
  4663. "numberList": numberList,
  4664. "listOne": listOne,
  4665. })
  4666. }
  4667. func (this *DialysisApiController) GetSolutionListByOrgId() {
  4668. orgId := this.GetAdminUserInfo().CurrentOrgId
  4669. list, _ := service.GetSolutionListByOrgId(orgId)
  4670. for _, item := range list {
  4671. //获取该模式最新的1条数据
  4672. solution, _ := service.GetNewPatientSolutionByModeId(item.PatientId, item.ModeId, orgId)
  4673. //更新状态值
  4674. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, orgId, item.PatientId)
  4675. }
  4676. this.ServeSuccessJSON(map[string]interface{}{
  4677. "list": list,
  4678. })
  4679. }
  4680. func (this *DialysisApiController) ExcutionDoctorAdvice() {
  4681. orgId := this.GetAdminUserInfo().CurrentOrgId
  4682. is_open, _ := this.GetInt64("is_open")
  4683. idsStr := this.GetString("str")
  4684. recordIDStrs := strings.Split(idsStr, ",")
  4685. start_time := this.GetString("advice_date")
  4686. exec_time, _ := this.GetInt64("exec_time")
  4687. timeLayout := "2006-01-02"
  4688. loc, _ := time.LoadLocation("Local")
  4689. var startTime int64
  4690. if len(start_time) > 0 {
  4691. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4692. if err != nil {
  4693. //fmt.Println(err)
  4694. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4695. return
  4696. }
  4697. startTime = theTime.Unix()
  4698. }
  4699. config, _ := service.GetDrugOpenConfigOne(orgId)
  4700. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  4701. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  4702. //his医嘱
  4703. if is_open == 1 {
  4704. groupList, _ := service.GetHisExcutionDoctorAdviceListGroupList(recordIDStrs, startTime, orgId)
  4705. //查找未执行医嘱
  4706. list, _ := service.GetHisExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  4707. for _, item := range list {
  4708. if item.Checker == this.GetAdminUserInfo().AdminUser.Id {
  4709. this.ServeSuccessJSON(map[string]interface{}{
  4710. "msg": "3",
  4711. })
  4712. return
  4713. }
  4714. }
  4715. for _, item := range groupList {
  4716. for _, it := range list {
  4717. if item.DrugId == it.DrugId {
  4718. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  4719. }
  4720. }
  4721. }
  4722. for _, item := range groupList {
  4723. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4724. var sum_out_count int64
  4725. for _, it := range item.ChildDoctorAdvice {
  4726. var prescribing_number int64
  4727. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  4728. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  4729. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4730. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  4731. }
  4732. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4733. prescribing_number = parseIntPrescribingNumber
  4734. }
  4735. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  4736. prescribing_number = parseIntPrescribingNumber
  4737. }
  4738. sum_out_count += prescribing_number
  4739. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  4740. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  4741. //库存不足
  4742. if sum_out_count > drugStockOut.FlushCount {
  4743. this.ServeSuccessJSON(map[string]interface{}{
  4744. "msg": "2",
  4745. "drug": medical,
  4746. })
  4747. return
  4748. }
  4749. }
  4750. }
  4751. creater := this.GetAdminUserInfo().AdminUser.Id
  4752. //执行出库逻辑
  4753. for _, item := range list {
  4754. hisadvice := &models.HisDoctorAdviceInfo{
  4755. ID: item.ID,
  4756. UserOrgId: item.UserOrgId,
  4757. PatientId: item.PatientId,
  4758. AdviceType: item.AdviceType,
  4759. AdviceDate: item.AdviceDate,
  4760. StartTime: item.StartTime,
  4761. AdviceName: item.AdviceName,
  4762. AdviceDesc: item.AdviceDesc,
  4763. ReminderDate: item.ReminderDate,
  4764. SingleDose: item.SingleDose,
  4765. SingleDoseUnit: item.SingleDoseUnit,
  4766. DrugSpec: item.DrugSpec,
  4767. DrugSpecUnit: item.DrugSpecUnit,
  4768. PrescribingNumber: item.PrescribingNumber,
  4769. PrescribingNumberUnit: item.PrescribingNumberUnit,
  4770. DeliveryWay: item.DeliveryWay,
  4771. ExecutionFrequency: item.ExecutionFrequency,
  4772. AdviceDoctor: item.AdviceDoctor,
  4773. Status: 1,
  4774. CreatedTime: item.CreatedTime,
  4775. UpdatedTime: item.UpdatedTime,
  4776. AdviceAffirm: item.AdviceAffirm,
  4777. Remark: item.Remark,
  4778. StopTime: item.StopTime,
  4779. StopReason: item.StopReason,
  4780. StopDoctor: item.StopDoctor,
  4781. StopState: item.StopState,
  4782. ParentId: item.ParentId,
  4783. ExecutionTime: item.ExecutionTime,
  4784. ExecutionStaff: creater,
  4785. ExecutionState: item.ExecutionState,
  4786. Checker: item.Checker,
  4787. RecordDate: item.RecordDate,
  4788. DialysisOrderId: item.DialysisOrderId,
  4789. CheckTime: item.CheckTime,
  4790. CheckState: item.CheckState,
  4791. RemindType: item.RemindType,
  4792. FrequencyType: item.FrequencyType,
  4793. DayCount: item.DayCount,
  4794. WeekDay: item.WeekDay,
  4795. TemplateId: item.TemplateId,
  4796. Modifier: item.Modifier,
  4797. Way: item.Way,
  4798. DrugId: item.DrugId,
  4799. ExecutionFrequencyId: item.ExecutionFrequencyId,
  4800. }
  4801. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4802. if medical.IsUse == 2 {
  4803. if config.IsOpen != 1 {
  4804. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  4805. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  4806. }
  4807. //不通过药房发药
  4808. if pharmacyConfig.IsOpen != 1 {
  4809. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  4810. }
  4811. //查询默认仓库
  4812. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4813. //查询默认仓库剩余多少库存
  4814. var sum_count int64
  4815. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4816. for _, its := range stockInfo {
  4817. if its.MaxUnit == medical.MaxUnit {
  4818. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  4819. }
  4820. sum_count += its.StockMaxNumber + its.StockMinNumber
  4821. }
  4822. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4823. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  4824. }
  4825. }
  4826. info := models.HisDoctorAdviceInfo{
  4827. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  4828. ExecutionTime: exec_time,
  4829. ExecutionState: 1,
  4830. UpdatedTime: time.Now().Unix(),
  4831. }
  4832. //执行医嘱
  4833. service.UpdateHisDoctorAdviceExecution(info, item.ID)
  4834. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  4835. redis := service.RedisClient()
  4836. //清空key 值
  4837. redis.Set(key, "", time.Second)
  4838. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  4839. redis.Set(keyTwo, "", time.Second)
  4840. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4841. redis.Set(keyThree, "", time.Second)
  4842. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4843. theTime := toTime.Format("2006-01-02")
  4844. fmt.Println("theTIME", theTime)
  4845. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  4846. redis.Set(keyFour, "", time.Second)
  4847. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4848. redis.Set(keyFive, "", time.Second)
  4849. }
  4850. } else {
  4851. groupList, _ := service.GetExcutionDoctorAdviceGroupList(recordIDStrs, startTime, orgId)
  4852. //查找未执行医嘱
  4853. list, _ := service.GetExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  4854. for _, item := range groupList {
  4855. for _, it := range list {
  4856. if item.DrugId == it.DrugId {
  4857. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  4858. }
  4859. }
  4860. }
  4861. for _, item := range groupList {
  4862. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4863. var sum_out_count int64
  4864. for _, it := range item.ChildDoctorAdvice {
  4865. var prescribing_number int64
  4866. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  4867. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  4868. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4869. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  4870. }
  4871. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4872. prescribing_number = parseIntPrescribingNumber
  4873. }
  4874. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  4875. prescribing_number = parseIntPrescribingNumber
  4876. }
  4877. sum_out_count += prescribing_number
  4878. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  4879. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  4880. //库存不足
  4881. if sum_out_count > drugStockOut.FlushCount {
  4882. this.ServeSuccessJSON(map[string]interface{}{
  4883. "msg": "2",
  4884. "drug": medical,
  4885. })
  4886. return
  4887. }
  4888. }
  4889. }
  4890. for _, item := range list {
  4891. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4892. dadvice := &models.DoctorAdvice{
  4893. ID: item.ID,
  4894. UserOrgId: item.UserOrgId,
  4895. PatientId: item.PatientId,
  4896. AdviceType: item.AdviceType,
  4897. AdviceDate: item.AdviceDate,
  4898. StartTime: item.StartTime,
  4899. AdviceName: item.AdviceName,
  4900. AdviceDesc: item.AdviceDesc,
  4901. ReminderDate: item.ReminderDate,
  4902. SingleDose: item.SingleDose,
  4903. SingleDoseUnit: item.SingleDoseUnit,
  4904. DrugSpec: item.DrugSpec,
  4905. DrugSpecUnit: item.DrugSpecUnit,
  4906. PrescribingNumber: item.PrescribingNumber,
  4907. PrescribingNumberUnit: item.PrescribingNumberUnit,
  4908. DeliveryWay: item.DeliveryWay,
  4909. ExecutionFrequency: item.ExecutionFrequency,
  4910. AdviceDoctor: item.AdviceDoctor,
  4911. Status: 1,
  4912. CreatedTime: item.CreatedTime,
  4913. UpdatedTime: item.UpdatedTime,
  4914. AdviceAffirm: item.AdviceAffirm,
  4915. Remark: item.Remark,
  4916. StopTime: item.StopTime,
  4917. StopReason: item.StopReason,
  4918. StopDoctor: item.StopDoctor,
  4919. StopState: item.StopState,
  4920. ParentId: item.ParentId,
  4921. ExecutionTime: item.ExecutionTime,
  4922. ExecutionStaff: item.ExecutionStaff,
  4923. ExecutionState: item.ExecutionState,
  4924. Checker: item.Checker,
  4925. RecordDate: item.ReminderDate,
  4926. DialysisOrderId: item.DialysisOrderId,
  4927. CheckTime: item.CheckTime,
  4928. CheckState: item.CheckState,
  4929. RemindType: item.RemindType,
  4930. FrequencyType: item.FrequencyType,
  4931. DayCount: item.DayCount,
  4932. WeekDay: item.WeekDay,
  4933. TemplateId: item.TemplateId,
  4934. Modifier: item.Modifier,
  4935. Way: item.Way,
  4936. DrugId: item.DrugId,
  4937. }
  4938. if medical.IsUse == 2 {
  4939. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  4940. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  4941. }
  4942. if pharmacyConfig.IsOpen != 1 {
  4943. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  4944. }
  4945. //更新字典里面的库存
  4946. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4947. var sum_count int64
  4948. for _, its := range stockInfo {
  4949. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4950. if its.MaxUnit == baseDrug.MaxUnit {
  4951. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4952. }
  4953. sum_count += its.StockMaxNumber + its.StockMinNumber
  4954. }
  4955. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4956. //剩余库存
  4957. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  4958. }
  4959. info := models.DoctorAdvice{
  4960. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  4961. ExecutionTime: exec_time,
  4962. ExecutionState: 1,
  4963. UpdatedTime: time.Now().Unix(),
  4964. }
  4965. //执行医嘱
  4966. service.UpdateDoctorAdviceExecution(info, item.ID)
  4967. }
  4968. }
  4969. this.ServeSuccessJSON(map[string]interface{}{
  4970. "msg": "1",
  4971. })
  4972. return
  4973. }
  4974. func (this *DialysisApiController) CheckNewDoctorAdvice() {
  4975. orgId := this.GetAdminUserInfo().CurrentOrgId
  4976. idsStr := this.GetString("str")
  4977. recordIDStrs := strings.Split(idsStr, ",")
  4978. start_time := this.GetString("advice_date")
  4979. timeLayout := "2006-01-02"
  4980. loc, _ := time.LoadLocation("Local")
  4981. var startTime int64
  4982. if len(start_time) > 0 {
  4983. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4984. if err != nil {
  4985. //fmt.Println(err)
  4986. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4987. return
  4988. }
  4989. startTime = theTime.Unix()
  4990. }
  4991. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  4992. if config.IsOpen == 1 {
  4993. creater := this.GetAdminUserInfo().AdminUser.Id
  4994. //查询未核对的医嘱
  4995. advicelist, _ := service.GetHisCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  4996. for _, item := range advicelist {
  4997. if item.ExecutionStaff == creater {
  4998. this.ServeSuccessJSON(map[string]interface{}{
  4999. "msg": "2",
  5000. "advice": item,
  5001. })
  5002. return
  5003. }
  5004. service.CheckHisDoctorAdvice(item.ID, creater)
  5005. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5006. redis := service.RedisClient()
  5007. //清空key 值
  5008. redis.Set(key, "", time.Second)
  5009. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5010. redis.Set(keyTwo, "", time.Second)
  5011. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5012. redis.Set(keyThree, "", time.Second)
  5013. theTime := time.Now()
  5014. recordDate := theTime.Format("2006-01-02")
  5015. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5016. redis.Set(keyFour, "", time.Second)
  5017. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5018. redis.Set(keyFive, "", time.Second)
  5019. }
  5020. } else {
  5021. //查询未核对的医嘱
  5022. advicelist, _ := service.GetCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  5023. creater := this.GetAdminUserInfo().AdminUser.Id
  5024. for _, item := range advicelist {
  5025. if item.ExecutionStaff == creater {
  5026. this.ServeSuccessJSON(map[string]interface{}{
  5027. "msg": "2",
  5028. "advice": item,
  5029. })
  5030. return
  5031. }
  5032. service.CheckDoctorAdvice(item.ID, creater)
  5033. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5034. redis := service.RedisClient()
  5035. //清空key 值
  5036. redis.Set(key, "", time.Second)
  5037. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5038. redis.Set(keyTwo, "", time.Second)
  5039. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5040. redis.Set(keyThree, "", time.Second)
  5041. theTime := time.Now()
  5042. recordDate := theTime.Format("2006-01-02")
  5043. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5044. redis.Set(keyFour, "", time.Second)
  5045. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5046. redis.Set(keyFive, "", time.Second)
  5047. }
  5048. }
  5049. this.ServeSuccessJSON(map[string]interface{}{
  5050. "msg": "1",
  5051. })
  5052. return
  5053. }
  5054. func (this *DialysisApiController) SettleNewDoctorAdvice() {
  5055. orgId := this.GetAdminUserInfo().CurrentOrgId
  5056. is_open, _ := this.GetInt64("is_open")
  5057. idsStr := this.GetString("str")
  5058. recordIDStrs := strings.Split(idsStr, ",")
  5059. start_time := this.GetString("advice_date")
  5060. timeLayout := "2006-01-02"
  5061. loc, _ := time.LoadLocation("Local")
  5062. var startTime int64
  5063. if len(start_time) > 0 {
  5064. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5065. if err != nil {
  5066. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5067. return
  5068. }
  5069. startTime = theTime.Unix()
  5070. }
  5071. if is_open == 1 {
  5072. service.SettleHisNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5073. } else {
  5074. service.SettleNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5075. }
  5076. this.ServeSuccessJSON(map[string]interface{}{
  5077. "msg": "1",
  5078. })
  5079. return
  5080. }
  5081. func (this *DialysisApiController) ExcutionDoctorAdviceById() {
  5082. advice_id, _ := this.GetInt64("advice_id")
  5083. start_time := this.GetString("advice_date")
  5084. orgId := this.GetAdminUserInfo().CurrentOrgId
  5085. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  5086. exec_time, _ := this.GetInt64("exec_time")
  5087. //his医嘱
  5088. if config.IsOpen == 1 {
  5089. //查询医嘱
  5090. advice, _ := service.GetHisDocById(advice_id, orgId)
  5091. if advice.Checker == this.GetAdminUserInfo().AdminUser.Id {
  5092. this.ServeSuccessJSON(map[string]interface{}{
  5093. "msg": "3",
  5094. })
  5095. return
  5096. }
  5097. medical, _ := service.GetBaseDrugMedical(orgId)
  5098. var prescribing_number int64
  5099. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5100. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5101. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5102. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5103. }
  5104. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5105. prescribing_number = parseIntPrescribingNumber
  5106. }
  5107. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5108. prescribing_number = parseIntPrescribingNumber
  5109. }
  5110. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5111. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5112. //库存不足
  5113. if prescribing_number > drugStockOut.FlushCount {
  5114. this.ServeSuccessJSON(map[string]interface{}{
  5115. "msg": "2",
  5116. "drug": medical,
  5117. })
  5118. return
  5119. }
  5120. info := models.HisDoctorAdviceInfo{
  5121. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5122. ExecutionTime: exec_time,
  5123. ExecutionState: 1,
  5124. UpdatedTime: time.Now().Unix(),
  5125. }
  5126. //执行医嘱
  5127. service.UpdateHisDoctorAdviceExecution(info, advice.ID)
  5128. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  5129. redis := service.RedisClient()
  5130. //清空key 值
  5131. redis.Set(key, "", time.Second)
  5132. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  5133. redis.Set(keyTwo, "", time.Second)
  5134. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5135. redis.Set(keyThree, "", time.Second)
  5136. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5137. theTime := toTime.Format("2006-01-02")
  5138. fmt.Println("theTIME", theTime)
  5139. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  5140. redis.Set(keyFour, "", time.Second)
  5141. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5142. redis.Set(keyFive, "", time.Second)
  5143. //出库
  5144. if prescribing_number <= drugStockOut.FlushCount {
  5145. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5146. //执行出库逻辑
  5147. hisadvice := &models.HisDoctorAdviceInfo{
  5148. ID: advice.ID,
  5149. UserOrgId: advice.UserOrgId,
  5150. PatientId: advice.PatientId,
  5151. AdviceType: advice.AdviceType,
  5152. AdviceDate: advice.AdviceDate,
  5153. StartTime: advice.StartTime,
  5154. AdviceName: advice.AdviceName,
  5155. AdviceDesc: advice.AdviceDesc,
  5156. ReminderDate: advice.ReminderDate,
  5157. SingleDose: advice.SingleDose,
  5158. SingleDoseUnit: advice.SingleDoseUnit,
  5159. DrugSpec: advice.DrugSpec,
  5160. DrugSpecUnit: advice.DrugSpecUnit,
  5161. PrescribingNumber: advice.PrescribingNumber,
  5162. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  5163. DeliveryWay: advice.DeliveryWay,
  5164. ExecutionFrequency: advice.ExecutionFrequency,
  5165. AdviceDoctor: advice.AdviceDoctor,
  5166. Status: 1,
  5167. CreatedTime: advice.CreatedTime,
  5168. UpdatedTime: advice.UpdatedTime,
  5169. AdviceAffirm: advice.AdviceAffirm,
  5170. Remark: advice.Remark,
  5171. StopTime: advice.StopTime,
  5172. StopReason: advice.StopReason,
  5173. StopDoctor: advice.StopDoctor,
  5174. StopState: advice.StopState,
  5175. ParentId: advice.ParentId,
  5176. ExecutionTime: advice.ExecutionTime,
  5177. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5178. ExecutionState: advice.ExecutionState,
  5179. Checker: advice.Checker,
  5180. RecordDate: advice.RecordDate,
  5181. DialysisOrderId: advice.DialysisOrderId,
  5182. CheckTime: advice.CheckTime,
  5183. CheckState: advice.CheckState,
  5184. RemindType: advice.RemindType,
  5185. FrequencyType: advice.FrequencyType,
  5186. DayCount: advice.DayCount,
  5187. WeekDay: advice.WeekDay,
  5188. TemplateId: advice.TemplateId,
  5189. Modifier: advice.Modifier,
  5190. Way: advice.Way,
  5191. DrugId: advice.DrugId,
  5192. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  5193. }
  5194. if medical.IsUse == 2 {
  5195. if config.IsOpen != 1 {
  5196. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5197. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5198. }
  5199. //不通过药房发药
  5200. if pharmacyConfig.IsOpen != 1 {
  5201. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5202. }
  5203. //查询默认仓库
  5204. storeHouseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  5205. //查询默认仓库剩余多少库存
  5206. var sum_count int64
  5207. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  5208. for _, its := range stockInfo {
  5209. if its.MaxUnit == medical.MaxUnit {
  5210. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5211. }
  5212. sum_count += its.StockMaxNumber + its.StockMinNumber
  5213. }
  5214. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  5215. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5216. }
  5217. }
  5218. }
  5219. this.ServeSuccessJSON(map[string]interface{}{
  5220. "msg": "1",
  5221. })
  5222. return
  5223. }
  5224. if config.IsOpen == 2 || config.IsOpen == 0 {
  5225. advice, _ := service.GetBloodDocById(advice_id, orgId)
  5226. medical, _ := service.GetBaseDrugMedical(orgId)
  5227. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5228. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5229. var prescribing_number int64
  5230. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5231. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5232. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5233. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5234. }
  5235. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5236. prescribing_number = parseIntPrescribingNumber
  5237. }
  5238. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5239. prescribing_number = parseIntPrescribingNumber
  5240. }
  5241. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5242. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5243. //库存不足
  5244. if prescribing_number > drugStockOut.FlushCount {
  5245. this.ServeSuccessJSON(map[string]interface{}{
  5246. "msg": "2",
  5247. "drug": medical,
  5248. })
  5249. return
  5250. }
  5251. info := models.DoctorAdvice{
  5252. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5253. ExecutionTime: exec_time,
  5254. ExecutionState: 1,
  5255. UpdatedTime: time.Now().Unix(),
  5256. }
  5257. //执行医嘱
  5258. service.UpdateDoctorAdviceExecution(info, advice.ID)
  5259. dadvice := &models.DoctorAdvice{
  5260. ID: advice.ID,
  5261. UserOrgId: advice.UserOrgId,
  5262. PatientId: advice.PatientId,
  5263. AdviceType: advice.AdviceType,
  5264. AdviceDate: advice.AdviceDate,
  5265. StartTime: advice.StartTime,
  5266. AdviceName: advice.AdviceName,
  5267. AdviceDesc: advice.AdviceDesc,
  5268. ReminderDate: advice.ReminderDate,
  5269. SingleDose: advice.SingleDose,
  5270. SingleDoseUnit: advice.SingleDoseUnit,
  5271. DrugSpec: advice.DrugSpec,
  5272. DrugSpecUnit: advice.DrugSpecUnit,
  5273. PrescribingNumber: advice.PrescribingNumber,
  5274. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  5275. DeliveryWay: advice.DeliveryWay,
  5276. ExecutionFrequency: advice.ExecutionFrequency,
  5277. AdviceDoctor: advice.AdviceDoctor,
  5278. Status: 1,
  5279. CreatedTime: advice.CreatedTime,
  5280. UpdatedTime: advice.UpdatedTime,
  5281. AdviceAffirm: advice.AdviceAffirm,
  5282. Remark: advice.Remark,
  5283. StopTime: advice.StopTime,
  5284. StopReason: advice.StopReason,
  5285. StopDoctor: advice.StopDoctor,
  5286. StopState: advice.StopState,
  5287. ParentId: advice.ParentId,
  5288. ExecutionTime: advice.ExecutionTime,
  5289. ExecutionStaff: advice.ExecutionStaff,
  5290. ExecutionState: advice.ExecutionState,
  5291. Checker: advice.Checker,
  5292. RecordDate: advice.ReminderDate,
  5293. DialysisOrderId: advice.DialysisOrderId,
  5294. CheckTime: advice.CheckTime,
  5295. CheckState: advice.CheckState,
  5296. RemindType: advice.RemindType,
  5297. FrequencyType: advice.FrequencyType,
  5298. DayCount: advice.DayCount,
  5299. WeekDay: advice.WeekDay,
  5300. TemplateId: advice.TemplateId,
  5301. Modifier: advice.Modifier,
  5302. Way: advice.Way,
  5303. DrugId: advice.DrugId,
  5304. }
  5305. if medical.IsUse == 2 {
  5306. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5307. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  5308. }
  5309. if pharmacyConfig.IsOpen != 1 {
  5310. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  5311. }
  5312. //更新字典里面的库存
  5313. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  5314. var sum_count int64
  5315. for _, its := range stockInfo {
  5316. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5317. if its.MaxUnit == baseDrug.MaxUnit {
  5318. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5319. }
  5320. sum_count += its.StockMaxNumber + its.StockMinNumber
  5321. }
  5322. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  5323. //剩余库存
  5324. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5325. }
  5326. }
  5327. this.ServeSuccessJSON(map[string]interface{}{
  5328. "msg": "1",
  5329. })
  5330. return
  5331. }
  5332. func (this *DialysisApiController) GetDialysisAdviceToday() {
  5333. orgId := this.GetAdminUserInfo().CurrentOrgId
  5334. schedule_type, _ := this.GetInt64("schedule_type")
  5335. //partion_type, _ := this.GetInt64("partion_type")
  5336. partion_type := this.GetString("partion_type")
  5337. var ids []string
  5338. ids = strings.Split(partion_type, ",")
  5339. start_time := this.GetString("selected_date")
  5340. timeLayout := "2006-01-02"
  5341. loc, _ := time.LoadLocation("Local")
  5342. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5343. list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
  5344. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  5345. _, config := service.FindXTHisRecordByOrgId(orgId)
  5346. appId := this.GetAdminUserInfo().CurrentAppId
  5347. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  5348. if err == nil {
  5349. this.ServeSuccessJSON(map[string]interface{}{
  5350. "list": list,
  5351. "drug": drug,
  5352. "config": config,
  5353. "doctorList": doctorList,
  5354. })
  5355. return
  5356. } else {
  5357. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5358. return
  5359. }
  5360. }
  5361. func (this *DialysisApiController) GetMobileScheduleList() {
  5362. orgId := this.GetAdminUserInfo().CurrentOrgId
  5363. schedule, _ := service.GetMobileScheduleList(orgId)
  5364. if len(schedule) > 0 {
  5365. for _, its := range schedule {
  5366. //prescription, _ := service.GetPrescriptionList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5367. //its.DialysisPrescription = prescription
  5368. //monitor, _ := service.GetLastMonitorRecordList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5369. //its.MonitoringRecord = monitor
  5370. //after, _ := service.GetLastAfter(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5371. //its.XtAssessmentAfterDislysis = after
  5372. order, _ := service.GetLastOrder(its.UserOrgId, its.PatientId, its.ScheduleDate)
  5373. service.UpdateDoctorSix(order.StartTime, order.PatientId, order.DialysisDate, order.UserOrgId)
  5374. }
  5375. }
  5376. this.ServeSuccessJSON(map[string]interface{}{
  5377. "schedule": schedule,
  5378. })
  5379. return
  5380. }