dialysis_api_controller.go 218KB

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