dialysis_api_controller.go 167KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442
  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. }
  65. func (c *DialysisApiController) GetQueueCall() {
  66. adminUserInfo := c.GetAdminUserInfo()
  67. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  68. if queueConfig.ID <= 0 {
  69. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  70. queueConfig.Qhsj = 10
  71. queueConfig.Jzdcbbcs = 3
  72. queueConfig.Jzbbsy = 1
  73. queueConfig.Jzjhyc = 0
  74. queueConfig.Sjdcbbcs = 3
  75. queueConfig.Sjbbsy = 0
  76. queueConfig.Sjjhyc = 0
  77. queueConfig.Txxqyxs = 0
  78. queueConfig.Txglsyxs = 0
  79. }
  80. c.ServeSuccessJSON(map[string]interface{}{
  81. "queue_config": queueConfig,
  82. })
  83. }
  84. func (c *DialysisApiController) UpdateQueueCall() {
  85. adminUserInfo := c.GetAdminUserInfo()
  86. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  87. if queueConfig.ID <= 0 {
  88. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  89. queueConfig.Qhsj = 10
  90. queueConfig.Jzdcbbcs = 3
  91. queueConfig.Jzbbsy = 1
  92. queueConfig.Jzjhyc = 0
  93. queueConfig.Sjdcbbcs = 3
  94. queueConfig.Sjbbsy = 0
  95. queueConfig.Sjjhyc = 0
  96. queueConfig.Txxqyxs = 0
  97. queueConfig.Txglsyxs = 0
  98. queueConfig.CreateTime = time.Now().Unix()
  99. queueConfig.UpdateTime = time.Now().Unix()
  100. }
  101. qhsj, _ := c.GetInt64("qhsj", 0)
  102. if qhsj > 0 {
  103. queueConfig.Qhsj = qhsj
  104. }
  105. jzdcbbcs, _ := c.GetInt64("jzdcbbcs", 0)
  106. if jzdcbbcs > 0 {
  107. queueConfig.Jzdcbbcs = jzdcbbcs
  108. }
  109. jzbbsy, _ := c.GetInt64("jzbbsy", 0)
  110. if jzbbsy > 0 {
  111. queueConfig.Jzbbsy = jzbbsy
  112. }
  113. jzjhyc, _ := c.GetInt64("jzjhyc", 0)
  114. queueConfig.Jzjhyc = jzjhyc
  115. sjdcbbcs, _ := c.GetInt64("sjdcbbcs", 0)
  116. if sjdcbbcs > 0 {
  117. queueConfig.Sjdcbbcs = sjdcbbcs
  118. }
  119. sjbbsy, _ := c.GetInt64("sjbbsy", 0)
  120. if sjbbsy > 0 {
  121. queueConfig.Sjbbsy = sjbbsy
  122. }
  123. sjjhyc, _ := c.GetInt64("sjjhyc", 0)
  124. queueConfig.Sjjhyc = sjjhyc
  125. txxqyxs, _ := c.GetInt64("txxqyxs", 0)
  126. queueConfig.Txxqyxs = txxqyxs
  127. txglsyxs, _ := c.GetInt64("txglsyxs", 0)
  128. queueConfig.Txglsyxs = txglsyxs
  129. queueConfig.UpdateTime = time.Now().Unix()
  130. service.UpDateQueueCallInfo(queueConfig)
  131. c.ServeSuccessJSON(map[string]interface{}{
  132. "queue_config": queueConfig,
  133. })
  134. }
  135. func (c *DialysisApiController) PostPrescription() {
  136. patient, _ := c.GetInt64("patient_id", 0)
  137. recordDateStr := c.GetString("record_date")
  138. if patient <= 0 {
  139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. adminUserInfo := c.GetAdminUserInfo()
  143. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  144. if patientInfo.ID == 0 {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  146. return
  147. }
  148. if len(recordDateStr) == 0 {
  149. recordDateStr = time.Now().Format("2006-01-02")
  150. }
  151. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  152. if parseDateErr != nil {
  153. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  155. return
  156. }
  157. mode_id, _ := c.GetInt64("mode_id", 0)
  158. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  159. dialyzer, _ := c.GetInt64("dialyzer", 0)
  160. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  161. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  162. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  163. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  164. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  165. replacement_way, _ := c.GetInt64("replacement_way", 0)
  166. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  167. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  168. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  169. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  170. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  171. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  172. kalium, _ := c.GetFloat("kalium", 0)
  173. sodium, _ := c.GetFloat("sodium", 0)
  174. replacement_total, _ := c.GetFloat("replacement_total", 0)
  175. calcium, _ := c.GetFloat("calcium", 0)
  176. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  177. glucose, _ := c.GetFloat("glucose", 0)
  178. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  179. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  180. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  181. conductivity, _ := c.GetFloat("conductivity", 0)
  182. remark := c.GetString("remark")
  183. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  184. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  185. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  186. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  187. body_fluid, _ := c.GetInt64("body_fluid", 0)
  188. special_medicine, _ := c.GetInt64("special_medicine", 0)
  189. special_medicine_other := c.GetString("special_medicine_other")
  190. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  191. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  192. blood_access, _ := c.GetInt64("blood_access", 0)
  193. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  194. body_fluid_other := c.GetString("body_fluid_other")
  195. target_ktv, _ := c.GetFloat("target_ktv", 0)
  196. niprocart, _ := c.GetInt64("niprocart", 0)
  197. jms, _ := c.GetInt64("jms", 0)
  198. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  199. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  200. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  201. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  202. filtryzer, _ := c.GetInt64("filtryzer", 0)
  203. dialyzers, _ := c.GetInt64("dialyzers", 0)
  204. injector, _ := c.GetInt64("injector", 0)
  205. bloodlines, _ := c.GetInt64("bloodlines", 0)
  206. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  207. safe_package, _ := c.GetInt64("package", 0)
  208. a_liquid, _ := c.GetInt64("a_liquid", 0)
  209. preImpules, _ := c.GetFloat("pre_impulse", 0)
  210. fmt.Println("", preImpules)
  211. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  212. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  213. //heparin_sodium := c.GetString("heparin_sodium")
  214. //fmt.Println("肝素钠",heparin_sodium)
  215. //nucleoprotamine := c.GetString("nucleoprotamine")
  216. //fmt.Println("鱼精蛋白",nucleoprotamine)
  217. //push_the_protamine := c.GetString("push_the_protamine")
  218. //fmt.Println("下机前推注鱼精蛋白",push_the_protamine)
  219. // var prescription_doctor int64
  220. blood := c.GetString("blood")
  221. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  222. dialysis_irrigation := c.GetString("dialysis_irrigation")
  223. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  224. displace_speed := c.GetString("displace_speed")
  225. illness, _ := c.GetInt64("illness")
  226. amylaceum := c.GetString("amylaceum")
  227. single_time := c.GetString("single_time")
  228. single_water := c.GetString("single_water")
  229. replacement_flow := c.GetString("replacement_flow")
  230. plasma_separator := c.GetString("plasma_separator")
  231. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  232. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  233. oxygen_flow := c.GetString("oxygen_flow")
  234. oxygen_time := c.GetString("oxygen_time")
  235. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  236. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  237. puncture_needle := c.GetString("puncture_needle")
  238. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  239. epo := c.GetString("epo")
  240. epo_count, _ := c.GetFloat("epo_count", 0)
  241. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  242. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  243. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  244. //if template.TemplateId == 2 || template.TemplateId == 6 {
  245. // if appRole.UserType == 3 {
  246. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  247. // if getPermissionErr != nil {
  248. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  249. // return
  250. // } else if headNursePermission == nil {
  251. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  252. // return
  253. // }
  254. // }
  255. //}
  256. prescription := models.DialysisPrescription{
  257. UserOrgId: adminUserInfo.CurrentOrgId,
  258. PatientId: patient,
  259. RecordDate: recordDate.Unix(),
  260. ModeId: mode_id,
  261. DialysisDuration: dialysis_duration,
  262. Dialyzer: dialyzer,
  263. ReplacementTotal: replacement_total,
  264. PerfusionApparatus: perfusion_apparatus,
  265. BloodFlowVolume: blood_flow_volume,
  266. DewaterAmount: dewater_amount,
  267. DisplaceLiqui: displace_liqui,
  268. ReplacementWay: replacement_way,
  269. Anticoagulant: anticoagulant,
  270. AnticoagulantShouji: anticoagulant_shouji,
  271. AnticoagulantWeichi: anticoagulant_weichi,
  272. AnticoagulantZongliang: anticoagulant_zongliang,
  273. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  274. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  275. Kalium: kalium,
  276. Sodium: sodium,
  277. Calcium: calcium,
  278. Bicarbonate: bicarbonate,
  279. Glucose: glucose,
  280. // DryWeight: dry_weight,
  281. DialysateFlow: dialysate_flow,
  282. DialysateTemperature: dialysate_temperature,
  283. Conductivity: conductivity,
  284. Remark: remark,
  285. Status: 1,
  286. CreatedTime: time.Now().Unix(),
  287. UpdatedTime: time.Now().Unix(),
  288. DialysisDurationMinute: dialysisDurationMinute,
  289. DialysisDurationHour: dialysisDurationHour,
  290. TargetUltrafiltration: targetUltrafiltration,
  291. DialysateFormulation: dialysateFormulation,
  292. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  293. BodyFluid: body_fluid,
  294. SpecialMedicine: special_medicine,
  295. SpecialMedicineOther: special_medicine_other,
  296. DisplaceLiquiPart: displace_liqui_part,
  297. DisplaceLiquiValue: displace_liqui_value,
  298. BloodAccess: blood_access,
  299. Ultrafiltration: ultrafiltration,
  300. BodyFluidOther: body_fluid_other,
  301. TargetKtv: target_ktv,
  302. Niprocart: niprocart,
  303. Jms: jms,
  304. FistulaNeedleSet: fistula_needle_set,
  305. FistulaNeedleSet16: fistula_needle_set_16,
  306. Hemoperfusion: hemoperfusion,
  307. DialyserSterilised: dialyser_sterilised,
  308. Filtryzer: filtryzer,
  309. Dialyzers: dialyzers,
  310. Injector: injector,
  311. Bloodlines: bloodlines,
  312. TubingHemodialysis: tubing_hemodialysis,
  313. Package: safe_package,
  314. ALiquid: a_liquid,
  315. PreImpulse: preImpules,
  316. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  317. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  318. Blood: blood,
  319. DialysisDialyszers: dialysis_dialyszers,
  320. DialysisIrrigation: dialysis_irrigation,
  321. AntioxidantCommodityName: antioxidant_commodity_name,
  322. DisplaceSpeed: displace_speed,
  323. Illness: illness,
  324. Amylaceum: amylaceum,
  325. SingleTime: single_time,
  326. SingleWater: single_water,
  327. ReplacementFlow: replacement_flow,
  328. PlasmaSeparator: plasma_separator,
  329. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  330. OxygenFlow: oxygen_flow,
  331. OxygenUptake: oxygen_uptake,
  332. OxygenTime: oxygen_time,
  333. HemodialysisPipelines: hemodialysis_pipelines,
  334. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  335. PunctureNeedle: puncture_needle,
  336. PunctureNeedleCount: puncture_needle_count,
  337. Epo: epo,
  338. EpoCount: epo_count,
  339. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  340. }
  341. if appRole.UserType == 2 || appRole.UserType == 1 {
  342. prescription.PrescriptionDoctor = appRole.AdminUserId
  343. }
  344. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  345. if dialysisPrescription.ID == 0 { //新增
  346. if mode_id > 0 {
  347. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  348. }
  349. prescription.Creater = adminUserInfo.AdminUser.Id
  350. //针对河间咸得
  351. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  352. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  353. prescription.DisplaceLiquiPart = 0
  354. prescription.DisplaceLiquiValue = 0
  355. }
  356. }
  357. err := service.AddSigleRecord(&prescription)
  358. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  359. redis := service.RedisClient()
  360. //清空key 值
  361. redis.Set(key, "", time.Second)
  362. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  363. redis.Set(keyTwo, "", time.Second)
  364. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  365. redis.Set(keyThree, "", time.Second)
  366. defer redis.Close()
  367. if err == nil {
  368. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  369. if updateErr != nil {
  370. utils.ErrorLog("%v", updateErr)
  371. }
  372. c.ServeSuccessJSON(map[string]interface{}{
  373. "prescription": &prescription,
  374. })
  375. } else {
  376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  377. }
  378. } else { //修改
  379. if mode_id > 0 {
  380. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  381. }
  382. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  383. //if template.TemplateId == 1 {
  384. // if dialysisPrescription.Creater > 0 && dialysisPrescription.Creater != adminUserInfo.AdminUser.Id {
  385. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  386. // if getPermissionErr != nil {
  387. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  388. // return
  389. // } else if headNursePermission == nil {
  390. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  391. // return
  392. // }
  393. // }
  394. //}
  395. if appRole.UserType == 2 || appRole.UserType == 1 {
  396. prescription_doctor := adminUserInfo.AdminUser.Id
  397. prescription.PrescriptionDoctor = prescription_doctor
  398. }
  399. if dialysisPrescription.Creater == 0 { //体重称
  400. prescription.Creater = adminUserInfo.AdminUser.Id
  401. } else {
  402. prescription.Creater = dialysisPrescription.Creater
  403. }
  404. prescription.CreatedTime = dialysisPrescription.CreatedTime
  405. prescription.UpdatedTime = time.Now().Unix()
  406. prescription.Modifier = adminUserInfo.AdminUser.Id
  407. prescription.ID = dialysisPrescription.ID
  408. updateErr := service.UpDateDialysisPrescription(&prescription)
  409. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  410. redis := service.RedisClient()
  411. defer redis.Close()
  412. //清空key 值
  413. redis.Set(key, "", time.Second)
  414. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  415. redis.Set(keyOne, "", time.Second)
  416. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  417. redis.Set(keyThree, "", time.Second)
  418. if updateErr == nil {
  419. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  420. if updateErr != nil {
  421. utils.ErrorLog("%v", updateErr)
  422. }
  423. c.ServeSuccessJSON(map[string]interface{}{
  424. "prescription": &prescription,
  425. })
  426. } else {
  427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  428. }
  429. }
  430. }
  431. func (c *DialysisApiController) PostSoulution() {
  432. patient, _ := c.GetInt64("patient", 0)
  433. recordDateStr := c.GetString("record_date")
  434. if patient <= 0 {
  435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  436. return
  437. }
  438. adminUserInfo := c.GetAdminUserInfo()
  439. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  440. if patientInfo.ID == 0 {
  441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  442. return
  443. }
  444. if len(recordDateStr) == 0 {
  445. recordDateStr = time.Now().Format("2006-01-02")
  446. }
  447. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  448. if parseDateErr != nil {
  449. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  451. return
  452. }
  453. mode_id, _ := c.GetInt64("mode_id", 0)
  454. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  455. dialyzer, _ := c.GetInt64("dialyzer", 0)
  456. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  457. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  458. replacement_total, _ := c.GetFloat("replacement_total", 0)
  459. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  460. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  461. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  462. replacement_way, _ := c.GetInt64("replacement_way", 0)
  463. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  464. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  465. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  466. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  467. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  468. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  469. kalium, _ := c.GetFloat("kalium", 0)
  470. sodium, _ := c.GetFloat("sodium", 0)
  471. calcium, _ := c.GetFloat("calcium", 0)
  472. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  473. glucose, _ := c.GetFloat("glucose", 0)
  474. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  475. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  476. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  477. conductivity, _ := c.GetFloat("conductivity", 0)
  478. remark := c.GetString("remark")
  479. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  480. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  481. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  482. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  483. body_fluid, _ := c.GetInt64("body_fluid", 0)
  484. special_medicine, _ := c.GetInt64("special_medicine", 0)
  485. special_medicine_other := c.GetString("special_medicine_other")
  486. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  487. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  488. blood_access, _ := c.GetInt64("blood_access", 0)
  489. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  490. body_fluid_other := c.GetString("body_fluid_other")
  491. target_ktv, _ := c.GetFloat("target_ktv", 0)
  492. niprocart, _ := c.GetInt64("niprocart", 0)
  493. jms, _ := c.GetInt64("jms", 0)
  494. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  495. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  496. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  497. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  498. filtryzer, _ := c.GetInt64("filtryzer", 0)
  499. dialyzers, _ := c.GetInt64("dialyzers", 0)
  500. injector, _ := c.GetInt64("injector", 0)
  501. bloodlines, _ := c.GetInt64("bloodlines", 0)
  502. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  503. safe_package, _ := c.GetInt64("package", 0)
  504. a_liquid, _ := c.GetInt64("a_liquid", 0)
  505. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  506. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  507. blood := c.GetString("blood")
  508. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  509. dialysis_irrigation := c.GetString("dialysis_irrigation")
  510. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  511. displace_speed := c.GetString("displace_speed")
  512. illness, _ := c.GetInt64("illness")
  513. amylaceum := c.GetString("amylaceum")
  514. single_time := c.GetString("single_time")
  515. single_water := c.GetString("single_water")
  516. replacement_flow := c.GetString("replacement_flow")
  517. plasma_separator := c.GetString("plasma_separator")
  518. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  519. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  520. oxygen_flow := c.GetString("oxygen_flow")
  521. oxygen_time := c.GetString("oxygen_time")
  522. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  523. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  524. puncture_needle := c.GetString("puncture_needle")
  525. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  526. epo := c.GetString("epo")
  527. epo_count, _ := c.GetFloat("epo_count", 0)
  528. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  529. impulse := c.GetString("impulse")
  530. preImpules, parseDateErr := strconv.ParseFloat(impulse, 64)
  531. fmt.Println("", preImpules)
  532. var prescription_doctor int64
  533. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  534. if appRole.UserType == 2 || appRole.UserType == 1 {
  535. prescription_doctor = appRole.AdminUserId
  536. }
  537. if mode_id > 0 {
  538. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  539. }
  540. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  541. //
  542. //if template.TemplateId == 2 || template.TemplateId == 6 {
  543. // if appRole.UserType == 3 {
  544. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  545. // if getPermissionErr != nil {
  546. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  547. // return
  548. // } else if headNursePermission == nil {
  549. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  550. // return
  551. // }
  552. // }
  553. //}
  554. prescription := models.DialysisPrescription{
  555. UserOrgId: adminUserInfo.CurrentOrgId,
  556. PatientId: patient,
  557. RecordDate: recordDate.Unix(),
  558. ModeId: mode_id,
  559. DialysisDuration: dialysis_duration,
  560. Dialyzer: dialyzer,
  561. PerfusionApparatus: perfusion_apparatus,
  562. BloodFlowVolume: blood_flow_volume,
  563. DewaterAmount: dewater_amount,
  564. DisplaceLiqui: displace_liqui,
  565. ReplacementWay: replacement_way,
  566. Anticoagulant: anticoagulant,
  567. AnticoagulantShouji: anticoagulant_shouji,
  568. AnticoagulantWeichi: anticoagulant_weichi,
  569. AnticoagulantZongliang: anticoagulant_zongliang,
  570. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  571. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  572. Kalium: kalium,
  573. Sodium: sodium,
  574. Calcium: calcium,
  575. Bicarbonate: bicarbonate,
  576. Glucose: glucose,
  577. // DryWeight: dry_weight,
  578. DialysateFlow: dialysate_flow,
  579. DialysateTemperature: dialysate_temperature,
  580. Conductivity: conductivity,
  581. Remark: remark,
  582. PrescriptionDoctor: prescription_doctor,
  583. Status: 1,
  584. CreatedTime: time.Now().Unix(),
  585. UpdatedTime: time.Now().Unix(),
  586. DialysisDurationMinute: dialysisDurationMinute,
  587. DialysisDurationHour: dialysisDurationHour,
  588. TargetUltrafiltration: targetUltrafiltration,
  589. DialysateFormulation: dialysateFormulation,
  590. ReplacementTotal: replacement_total,
  591. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  592. BodyFluid: body_fluid,
  593. SpecialMedicine: special_medicine,
  594. SpecialMedicineOther: special_medicine_other,
  595. DisplaceLiquiPart: displace_liqui_part,
  596. DisplaceLiquiValue: displace_liqui_value,
  597. BloodAccess: blood_access,
  598. Ultrafiltration: ultrafiltration,
  599. BodyFluidOther: body_fluid_other,
  600. TargetKtv: target_ktv,
  601. Niprocart: niprocart,
  602. Jms: jms,
  603. FistulaNeedleSet: fistula_needle_set,
  604. FistulaNeedleSet16: fistula_needle_set_16,
  605. Hemoperfusion: hemoperfusion,
  606. DialyserSterilised: dialyser_sterilised,
  607. Filtryzer: filtryzer,
  608. Dialyzers: dialyzers,
  609. Injector: injector,
  610. Bloodlines: bloodlines,
  611. TubingHemodialysis: tubing_hemodialysis,
  612. Package: safe_package,
  613. ALiquid: a_liquid,
  614. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  615. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  616. Blood: blood,
  617. DialysisIrrigation: dialysis_irrigation,
  618. DialysisDialyszers: dialysis_dialyszers,
  619. AntioxidantCommodityName: antioxidant_commodity_name,
  620. DisplaceSpeed: displace_speed,
  621. Illness: illness,
  622. Amylaceum: amylaceum,
  623. SingleTime: single_time,
  624. SingleWater: single_water,
  625. ReplacementFlow: replacement_flow,
  626. PlasmaSeparator: plasma_separator,
  627. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  628. OxygenTime: oxygen_time,
  629. OxygenUptake: oxygen_uptake,
  630. OxygenFlow: oxygen_flow,
  631. HemodialysisPipelines: hemodialysis_pipelines,
  632. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  633. PunctureNeedle: puncture_needle,
  634. PunctureNeedleCount: puncture_needle_count,
  635. Epo: epo,
  636. EpoCount: epo_count,
  637. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  638. PreImpulse: preImpules,
  639. }
  640. //查询最近透析准备表里是否存在 透析器 灌流器
  641. //splitStr := strings.Split(dialysis_dialyszers, ",")
  642. //
  643. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  644. //
  645. //mation, _ := service.GetGoodInfoMation(adminUserInfo.CurrentOrgId)
  646. //if len(mation)>0{
  647. // for _, item := range splitStr {
  648. // for _,it := range mation{
  649. // if(item == it.SpecificationName){
  650. //
  651. // //查询最近一次的透析器
  652. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  653. //
  654. // if errcode == gorm.ErrRecordNotFound{
  655. // //插入数据
  656. // prepare := models.DialysisBeforePrepare{
  657. // UserOrgId: adminUserInfo.CurrentOrgId,
  658. // PatientId: patient,
  659. // RecordDate: recordDate.Unix(),
  660. // GoodTypeId: it.GoodTypeId,
  661. // GoodId: it.ID,
  662. // Count: 1,
  663. // Ctime: time.Now().Unix(),
  664. // Creater: adminUserInfo.AdminUser.Id,
  665. // Status:1,
  666. //
  667. // }
  668. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  669. // fmt.Println("",errcode)
  670. // }
  671. // }
  672. // }
  673. //
  674. // }
  675. //
  676. // for _, item := range splitIrrigation {
  677. // for _,it := range mation{
  678. // if(item == it.SpecificationName){
  679. // //查询最近一次的透析器
  680. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  681. // if errcode == gorm.ErrRecordNotFound{
  682. // //插入数据
  683. // prepare := models.DialysisBeforePrepare{
  684. // UserOrgId: adminUserInfo.CurrentOrgId,
  685. // PatientId: patient,
  686. // RecordDate: recordDate.Unix(),
  687. // GoodTypeId: it.GoodTypeId,
  688. // GoodId: it.ID,
  689. // Count: 1,
  690. // Ctime: time.Now().Unix(),
  691. // Creater: adminUserInfo.AdminUser.Id,
  692. // Status:1,
  693. //
  694. // }
  695. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  696. // fmt.Println(errcode)
  697. // }
  698. // }
  699. // }
  700. // }
  701. //}
  702. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  703. if dialysisPrescription.ID == 0 { //新增
  704. if appRole.UserType == 2 || appRole.UserType == 1 {
  705. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  706. }
  707. prescription.Creater = adminUserInfo.AdminUser.Id
  708. } else { //修改
  709. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  710. //if template.TemplateId == 1 {
  711. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  712. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  713. // if getPermissionErr != nil {
  714. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  715. // return
  716. // } else if headNursePermission == nil {
  717. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  718. // return
  719. // }
  720. // }
  721. //}
  722. if appRole.UserType == 2 || appRole.UserType == 1 {
  723. prescription_doctor := adminUserInfo.AdminUser.Id
  724. prescription.PrescriptionDoctor = prescription_doctor
  725. } else {
  726. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  727. }
  728. if dialysisPrescription.Creater == 0 {
  729. prescription.Creater = adminUserInfo.AdminUser.Id
  730. } else {
  731. prescription.Creater = dialysisPrescription.Creater
  732. }
  733. prescription.CreatedTime = dialysisPrescription.CreatedTime
  734. prescription.UpdatedTime = time.Now().Unix()
  735. prescription.Modifier = adminUserInfo.AdminUser.Id
  736. prescription.ID = dialysisPrescription.ID
  737. }
  738. solution := models.DialysisSolution{
  739. RegistrarsId: adminUserInfo.AdminUser.Id,
  740. UserOrgId: adminUserInfo.CurrentOrgId,
  741. Doctor: prescription_doctor,
  742. PatientId: patient,
  743. ModeId: mode_id,
  744. DialysisDuration: dialysis_duration,
  745. PerfusionApparatus: perfusion_apparatus,
  746. BloodFlowVolume: blood_flow_volume,
  747. Dewater: dewater_amount,
  748. DisplaceLiqui: displace_liqui,
  749. ReplacementWay: replacement_way,
  750. Anticoagulant: anticoagulant,
  751. AnticoagulantShouji: anticoagulant_shouji,
  752. AnticoagulantWeichi: anticoagulant_weichi,
  753. AnticoagulantZongliang: anticoagulant_zongliang,
  754. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  755. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  756. Kalium: kalium,
  757. Sodium: sodium,
  758. Calcium: calcium,
  759. Bicarbonate: bicarbonate,
  760. Glucose: glucose,
  761. // DryWeight: dry_weight,
  762. DialysateFlow: dialysate_flow,
  763. DialysateTemperature: dialysate_temperature,
  764. Conductivity: conductivity,
  765. Remark: remark,
  766. Status: 1,
  767. CreatedTime: time.Now().Unix(),
  768. UpdatedTime: time.Now().Unix(),
  769. DialysisDurationMinute: dialysisDurationMinute,
  770. DialysisDurationHour: dialysisDurationHour,
  771. TargetUltrafiltration: targetUltrafiltration,
  772. DialysateFormulation: dialysateFormulation,
  773. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  774. BodyFluid: body_fluid,
  775. SpecialMedicine: special_medicine,
  776. SpecialMedicineOther: special_medicine_other,
  777. DisplaceLiquiPart: displace_liqui_part,
  778. DisplaceLiquiValue: displace_liqui_value,
  779. BloodAccess: blood_access,
  780. Ultrafiltration: ultrafiltration,
  781. BodyFluidOther: body_fluid_other,
  782. ReplacementTotal: replacement_total,
  783. TargetKtv: target_ktv,
  784. DialysisIrrigation: dialysis_irrigation,
  785. DialysisDialyszers: dialysis_dialyszers,
  786. HemodialysisPipelines: hemodialysis_pipelines,
  787. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  788. PunctureNeedle: puncture_needle,
  789. PunctureNeedleCount: puncture_needle_count,
  790. Epo: epo,
  791. EpoCount: epo_count,
  792. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  793. OxygenUptake: oxygen_uptake,
  794. OxygenFlow: oxygen_flow,
  795. OxygenTime: oxygen_time,
  796. PreImpulse: preImpules,
  797. SolutionStatus: 1,
  798. }
  799. //针对河间咸得
  800. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  801. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  802. prescription.DisplaceLiquiPart = 0
  803. prescription.DisplaceLiquiValue = 0
  804. }
  805. }
  806. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  807. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  808. solution.DisplaceLiquiPart = 0
  809. solution.DisplaceLiquiValue = 0
  810. }
  811. }
  812. err := service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  813. //获取最新1条
  814. dialysisSolution, _ := service.GetLastPatientDialysisSolution(patient, adminUserInfo.CurrentOrgId)
  815. //更新状态
  816. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  817. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  818. redis := service.RedisClient()
  819. //清空key 值
  820. redis.Set(key, "", time.Second)
  821. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  822. //清空key 值
  823. redis.Set(keyOne, "", time.Second)
  824. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  825. redis.Set(keyTwo, "", time.Second)
  826. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  827. redis.Set(keyThree, "", time.Second)
  828. defer redis.Close()
  829. if err == nil {
  830. c.ServeSuccessJSON(map[string]interface{}{
  831. "solution": &solution,
  832. "prescription": &prescription,
  833. })
  834. } else {
  835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  836. }
  837. }
  838. func (c *DialysisApiController) PostDouleCheck() {
  839. id, _ := c.GetInt64("patient", 0)
  840. recordDateStr := c.GetString("record_date")
  841. checkTimeStr := c.GetString("check_time")
  842. firstCheckTimeStr := c.GetString("first_check_time")
  843. creater, _ := c.GetInt64("creater", 0)
  844. modifier, _ := c.GetInt64("modifier", 0)
  845. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  846. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  847. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  848. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  849. dialysis_item_desc := c.GetString("dialysis_item_desc")
  850. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  851. vascular_access_desc := c.GetString("vascular_access_desc")
  852. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  853. collator, _ := c.GetInt64("collator", 0)
  854. employee_number := c.GetString("employee_number")
  855. if id <= 0 {
  856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. return
  858. }
  859. adminUserInfo := c.GetAdminUserInfo()
  860. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  861. if patient.ID == 0 {
  862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  863. return
  864. }
  865. if len(recordDateStr) == 0 {
  866. recordDateStr = time.Now().Format("2006-01-02")
  867. }
  868. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  869. if parseDateErr != nil {
  870. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  872. return
  873. }
  874. var checkDate int64
  875. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  876. list, _ := service.GetRoleList(adminUserInfo.CurrentOrgId, modifier)
  877. if employee_number != list.JobNumber {
  878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorEmployeeNumber)
  879. return
  880. }
  881. }
  882. if len(checkTimeStr) == 0 {
  883. //checkTimeStr = time.Now().Format("2006-01-02 15:04")
  884. checkDate = 0
  885. } else {
  886. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
  887. checkDate = checkDateUnix.Unix()
  888. }
  889. var firstCheckTimeDate int64
  890. if len(firstCheckTimeStr) == 0 {
  891. //firstCheckTimeStr = time.Now().Format("2006-01-02 15:04")
  892. firstCheckTimeDate = 0
  893. } else {
  894. firstCheckTimeDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", firstCheckTimeStr)
  895. firstCheckTimeDate = firstCheckTimeDateUnix.Unix()
  896. }
  897. doubleCheck := models.DoubleCheck{
  898. UserOrgId: adminUserInfo.CurrentOrgId,
  899. PatientId: id,
  900. DialysisItemCheck: dialysis_item_check,
  901. DialysisParameterCheck: dialysis_parameter_check,
  902. VascularAccessVerification: vascular_access_verification,
  903. PipelineConnectionCheck: pipeline_connection_check,
  904. DialysisItemDesc: dialysis_item_desc,
  905. DialysisParameterDesc: dialysis_parameter_desc,
  906. VascularAccessDesc: vascular_access_desc,
  907. PipelineConnectionDesc: pipeline_connection_desc,
  908. Collator: collator,
  909. Status: 1,
  910. CreatedTime: time.Now().Unix(),
  911. UpdatedTime: time.Now().Unix(),
  912. CheckDate: recordDate.Unix(),
  913. EmployeeNumber: employee_number,
  914. }
  915. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  916. if check.ID == 0 { //新增
  917. doubleCheck.FirstCheckTime = firstCheckTimeDate
  918. doubleCheck.CheckTime = checkDate
  919. doubleCheck.Creater = creater
  920. doubleCheck.Modifier = modifier
  921. err := service.AddSigleDoubleCheck(&doubleCheck)
  922. redis := service.RedisClient()
  923. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  924. //清空key 值
  925. redis.Set(key, "", time.Second)
  926. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  927. redis.Set(keyTwo, "", time.Second)
  928. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  929. redis.Set(keyThree, "", time.Second)
  930. defer redis.Close()
  931. if err == nil {
  932. c.ServeSuccessJSON(map[string]interface{}{
  933. "doubleCheck": doubleCheck,
  934. })
  935. } else {
  936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  937. }
  938. } else { //修改
  939. doubleCheck.FirstCheckTime = firstCheckTimeDate
  940. doubleCheck.CheckTime = checkDate
  941. doubleCheck.Creater = creater
  942. doubleCheck.Modifier = modifier
  943. doubleCheck.CreatedTime = check.CreatedTime
  944. doubleCheck.UpdatedTime = time.Now().Unix()
  945. doubleCheck.ID = check.ID
  946. redis := service.RedisClient()
  947. err := service.UpdateDoubleCheck(&doubleCheck)
  948. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  949. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  950. redis.Set(keyTwo, "", time.Second)
  951. //清空key 值
  952. redis.Set(key, "", time.Second)
  953. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  954. redis.Set(keyThree, "", time.Second)
  955. defer redis.Close()
  956. if err == nil {
  957. c.ServeSuccessJSON(map[string]interface{}{
  958. "doubleCheck": doubleCheck,
  959. })
  960. } else {
  961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  962. }
  963. }
  964. }
  965. func (c *DialysisApiController) PostReceiveTreatmentAsses() {
  966. id, _ := c.GetInt64("patient", 0)
  967. recordDateStr := c.GetString("record_date")
  968. way, _ := c.GetInt64("way", 0)
  969. consciousness, _ := c.GetInt64("consciousness", 0)
  970. appetite, _ := c.GetInt64("appetite", 0)
  971. condition, _ := c.GetInt64("condition", 0)
  972. posture, _ := c.GetInt64("posture")
  973. score := c.GetString("score")
  974. sick_condition, _ := c.GetInt64("sick_condition", 0)
  975. danger_level, _ := c.GetInt64("danger_level", 0)
  976. intake, _ := c.GetInt64("intake", 0)
  977. nutrition, _ := c.GetInt64("nutrition", 0)
  978. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  979. psychological_assessment_other := c.GetString("psychological_assessment_other")
  980. sick_condition_other := c.GetString("sick_condition_other")
  981. //precaution, _ := c.GetInt64("precaution", 0)
  982. precaution := c.GetString("precaution")
  983. precaution_other := c.GetString("precaution_other")
  984. psychological_other := c.GetString("psychological_other")
  985. admission_number := c.GetString("admission_number")
  986. tumble, _ := c.GetInt64("tumble")
  987. if id <= 0 {
  988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  989. return
  990. }
  991. adminUserInfo := c.GetAdminUserInfo()
  992. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  993. if patient.ID == 0 {
  994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  995. return
  996. }
  997. if len(recordDateStr) == 0 {
  998. recordDateStr = time.Now().Format("2006-01-02")
  999. }
  1000. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1001. if parseDateErr != nil {
  1002. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1004. return
  1005. }
  1006. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1007. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1008. UserOrgId: adminUserInfo.CurrentOrgId,
  1009. PatientId: id,
  1010. RecordDate: recordDate.Unix(),
  1011. Way: way,
  1012. Consciousness: consciousness,
  1013. Appetite: appetite,
  1014. Condition: condition,
  1015. SickCondition: sick_condition,
  1016. DangerLevel: danger_level,
  1017. Intake: intake,
  1018. Nutrition: nutrition,
  1019. PsychologicalAssessment: psychological_assessment,
  1020. PsychologicalAssessmentOther: psychological_assessment_other,
  1021. SickConditionOther: sick_condition_other,
  1022. Posture: posture,
  1023. CreatedTime: time.Now().Unix(),
  1024. UpdateTime: time.Now().Unix(),
  1025. Status: 1,
  1026. Score: score,
  1027. Precaution: precaution,
  1028. PrecautionOther: precaution_other,
  1029. PsychologicalOther: psychological_other,
  1030. AdmissionNumber: admission_number,
  1031. Tumble: tumble,
  1032. }
  1033. if receiveTreatment.ID == 0 { //新增
  1034. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1035. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1036. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1037. redis := service.RedisClient()
  1038. //清空key 值
  1039. redis.Set(key, "", time.Second)
  1040. defer redis.Close()
  1041. if err == nil {
  1042. c.ServeSuccessJSON(map[string]interface{}{
  1043. "receiveTreatmentAsses": receiveTreatmentAsses,
  1044. })
  1045. } else {
  1046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1047. }
  1048. } else { //修改
  1049. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1050. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1051. // if getPermissionErr != nil {
  1052. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1053. // return
  1054. // } else if headNursePermission == nil {
  1055. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1056. // return
  1057. // }
  1058. //}
  1059. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1060. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1061. receiveTreatmentAsses.UpdateTime = time.Now().Unix()
  1062. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1063. receiveTreatmentAsses.ID = receiveTreatment.ID
  1064. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1065. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1066. redis := service.RedisClient()
  1067. defer redis.Close()
  1068. redis.Set(keyOne, "", time.Second*60*60*18)
  1069. if err == nil {
  1070. c.ServeSuccessJSON(map[string]interface{}{
  1071. "receiveTreatmentAsses": receiveTreatmentAsses,
  1072. })
  1073. } else {
  1074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1075. }
  1076. }
  1077. }
  1078. func (c *DialysisApiController) PostAssessmentAfterDislysis() {
  1079. patient, _ := c.GetInt64("patient", 0)
  1080. recordDateStr := c.GetString("record_date")
  1081. fmt.Println(recordDateStr)
  1082. if patient <= 0 {
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1084. return
  1085. }
  1086. adminUserInfo := c.GetAdminUserInfo()
  1087. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1088. if patientInfo.ID == 0 {
  1089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1090. return
  1091. }
  1092. if len(recordDateStr) == 0 {
  1093. recordDateStr = time.Now().Format("2006-01-02")
  1094. }
  1095. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1096. if parseDateErr != nil {
  1097. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1099. return
  1100. }
  1101. // data := make(map[string]interface{}, 0)
  1102. var data models.AssessmentAfterDislysis
  1103. var err error
  1104. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  1105. fmt.Println(err)
  1106. if err != nil {
  1107. c.ErrorLog("数据解析错误:%v", err)
  1108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1109. return
  1110. }
  1111. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1112. assessment.DialysisOrderId = data.DialysisOrderId
  1113. assessment.Evaluator = adminUserInfo.AdminUser.Id
  1114. assessment.Status = 1
  1115. assessment.WeightAfter = data.WeightAfter
  1116. assessment.WeightLoss = data.WeightLoss
  1117. assessment.Temperature = data.Temperature
  1118. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  1119. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  1120. assessment.PulseFrequency = data.PulseFrequency
  1121. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  1122. assessment.ActualDisplacement = data.ActualDisplacement
  1123. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  1124. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  1125. assessment.Cruor = data.Cruor
  1126. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  1127. assessment.DialysisIntakes = data.DialysisIntakes
  1128. assessment.InternalFistula = data.InternalFistula
  1129. assessment.BloodAccessPartId = data.BloodAccessPartId
  1130. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  1131. assessment.Catheter = data.Catheter
  1132. assessment.Complication = data.Complication
  1133. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  1134. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  1135. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  1136. assessment.PatientGose = data.PatientGose
  1137. assessment.InpatientDepartment = data.InpatientDepartment
  1138. assessment.ObservationContent = data.ObservationContent
  1139. assessment.ObservationContentOther = data.ObservationContentOther
  1140. assessment.Remark = data.Remark
  1141. assessment.BreathingRate = data.BreathingRate
  1142. assessment.DialysisProcess = data.DialysisProcess
  1143. assessment.InAdvanceMinute = data.InAdvanceMinute
  1144. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  1145. assessment.InAdvanceReason = data.InAdvanceReason
  1146. assessment.HemostasisOpera = data.HemostasisOpera
  1147. assessment.HemostasisMinute = data.HemostasisMinute
  1148. assessment.TremorNoise = data.TremorNoise
  1149. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  1150. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  1151. assessment.ArterialTube = data.ArterialTube
  1152. assessment.IntravenousTube = data.IntravenousTube
  1153. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  1154. assessment.Dialyzer = data.Dialyzer
  1155. assessment.IsEat = data.IsEat
  1156. assessment.CvcA = data.CvcA
  1157. assessment.CvcV = data.CvcV
  1158. assessment.Channel = data.Channel
  1159. assessment.ReturnBlood = data.ReturnBlood
  1160. assessment.RehydrationVolume = data.RehydrationVolume
  1161. assessment.DialysisDuring = data.DialysisDuring
  1162. assessment.StrokeVolume = data.StrokeVolume
  1163. assessment.BloodFlow = data.BloodFlow
  1164. assessment.SealingFluidDispose = data.SealingFluidDispose
  1165. assessment.SealingFluidSpecial = data.SealingFluidSpecial
  1166. assessment.DosageOfAnticoagulants = data.DosageOfAnticoagulants
  1167. assessment.SupineSystolicBloodPressure = data.SupineSystolicBloodPressure
  1168. assessment.SettingPressure = data.SettingPressure
  1169. assessment.SupineDiastolicBloodPressure = data.SupineDiastolicBloodPressure
  1170. assessment.DiastolicPressure = data.DiastolicPressure
  1171. assessment.AdditionalWeight = data.AdditionalWeight
  1172. assessment.OtherComplication = data.OtherComplication
  1173. assessment.Ktv = data.Ktv
  1174. assessment.Urr = data.Urr
  1175. assessment.Hypertenison = data.Hypertenison
  1176. assessment.Hypopiesia = data.Hypopiesia
  1177. assessment.LeaveOfficeMethod = data.LeaveOfficeMethod
  1178. assessment.Lapse = data.Lapse
  1179. assessment.Consciousness = data.Consciousness
  1180. assessment.Fallrisk = data.Fallrisk
  1181. assessment.MachineRun = data.MachineRun
  1182. assessment.AfterUrea = data.AfterUrea
  1183. assessment.PipCoagulation = data.PipCoagulation
  1184. assessment.AccumulatedBloodVolume = data.AccumulatedBloodVolume
  1185. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1186. if assessment.ID > 0 {
  1187. if appRole.UserType == 2 || appRole.UserType == 1 {
  1188. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1189. assessment.AssessmentTime = time.Now().Unix()
  1190. } else {
  1191. if assessment.Creater == 0 {
  1192. assessment.Modifier = adminUserInfo.AdminUser.Id
  1193. assessment.Creater = adminUserInfo.AdminUser.Id
  1194. } else {
  1195. assessment.Modifier = adminUserInfo.AdminUser.Id
  1196. }
  1197. }
  1198. assessment.UpdatedTime = time.Now().Unix()
  1199. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  1200. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1201. redis := service.RedisClient()
  1202. //清空key 值
  1203. redis.Set(key, "", time.Second)
  1204. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1205. redis.Set(keyThree, "", time.Second)
  1206. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1207. redis.Set(keyTwo, "", time.Second)
  1208. defer redis.Close()
  1209. } else {
  1210. if appRole.UserType == 2 || appRole.UserType == 1 {
  1211. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1212. assessment.AssessmentTime = time.Now().Unix()
  1213. } else {
  1214. assessment.Creater = adminUserInfo.AdminUser.Id
  1215. }
  1216. assessment.CreatedTime = time.Now().Unix()
  1217. assessment.UpdatedTime = time.Now().Unix()
  1218. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  1219. assessment.PatientId = patient
  1220. assessment.AssessmentDate = recordDate.Unix()
  1221. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  1222. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1223. redis := service.RedisClient()
  1224. //清空key 值
  1225. redis.Set(key, "", time.Second)
  1226. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1227. redis.Set(keyThree, "", time.Second)
  1228. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1229. redis.Set(keyTwo, "", time.Second)
  1230. defer redis.Close()
  1231. }
  1232. if err != nil {
  1233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1234. return
  1235. }
  1236. c.ServeSuccessJSON(map[string]interface{}{
  1237. "AssessmentAfterDislysis": &assessment,
  1238. })
  1239. }
  1240. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  1241. patient, _ := c.GetInt64("patient", 0)
  1242. recordDateStr := c.GetString("record_date")
  1243. if patient <= 0 {
  1244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1245. return
  1246. }
  1247. adminUserInfo := c.GetAdminUserInfo()
  1248. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1249. if patientInfo.ID == 0 {
  1250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1251. return
  1252. }
  1253. if len(recordDateStr) == 0 {
  1254. recordDateStr = time.Now().Format("2006-01-02")
  1255. }
  1256. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1257. if parseDateErr != nil {
  1258. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1260. return
  1261. }
  1262. weight_before, _ := c.GetFloat("weight_before", 0)
  1263. dry_weight, _ := c.GetFloat("dry_weight", 0)
  1264. additional_weight, _ := c.GetFloat("additional_weight", 0)
  1265. temperature, _ := c.GetFloat("temperature", 0)
  1266. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1267. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1268. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1269. last_post_dialysis := c.GetString("last_post_dialysis")
  1270. dialysis_interphase := c.GetString("dialysis_interphase")
  1271. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  1272. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1273. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  1274. bloodAccessPartId := c.GetString("blood_access_part_id")
  1275. internalFistula := c.GetString("internal_fistula")
  1276. internal_fistula_skin := c.GetString("internal_fistula_skin")
  1277. catheter := c.GetString("catheter")
  1278. catheter_bend, _ := c.GetInt("catheter_bend")
  1279. complication := c.GetString("complication")
  1280. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  1281. hemorrhage := c.GetString("hemorrhage")
  1282. hemorrhage_other := c.GetString("hemorrhage_other")
  1283. remark := c.GetString("remark")
  1284. puncture_method := c.GetString("puncture_method")
  1285. dialysis_count := c.GetString("dialysis_count")
  1286. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  1287. emergency_treatment_other := c.GetString("emergency_treatment_other")
  1288. ductus_arantii := c.GetString("ductus_arantii")
  1289. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  1290. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  1291. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  1292. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  1293. puncture_way := c.GetString("puncture_way")
  1294. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  1295. internal_fistula_other := c.GetString("internal_fistula_other")
  1296. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  1297. breathing_rate := c.GetString("breathing_rate")
  1298. is_infect, _ := c.GetInt64("is_infect", 0)
  1299. exposed, _ := c.GetFloat("exposed", 0)
  1300. skin := c.GetString("skin")
  1301. skin_other := c.GetString("skin_other")
  1302. infect_other := c.GetString("infect_other")
  1303. ductus_arantii_other := c.GetString("ductus_arantii_other")
  1304. machine_type := c.GetString("machine_type")
  1305. puncture_needle := c.GetString("puncture_needle")
  1306. //humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
  1307. humor_excessive_symptom := c.GetString("humor_excessive_symptom")
  1308. phinholing := c.GetString("pinholing")
  1309. catheter_suture := c.GetString("catheter_suture")
  1310. catheter_suture_other := c.GetString("catheter_suture_other")
  1311. edema := c.GetString("edema")
  1312. urine_volume, _ := c.GetFloat("urine_volume", 0)
  1313. special_treatment := c.GetString("special_treatment")
  1314. catheter_maintenance := c.GetString("catheter_maintenance")
  1315. thrombusType := c.GetString("thromubus_type")
  1316. thrombusInt, _ := strconv.ParseInt(thrombusType, 10, 64)
  1317. thrombus_a := c.GetString("thromubus_a")
  1318. thrombus_av := c.GetString("thrombus_av")
  1319. thrombus_v := c.GetString("thromubus_v")
  1320. dehydration := c.GetString("dehydration")
  1321. pre_dialysis_drugs := c.GetString("pre_dialysis_drugs")
  1322. period, _ := c.GetInt64("period")
  1323. estimated_food_intake := c.GetString("estimated_food_intake")
  1324. blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
  1325. urea_befor := c.GetString("urea_befor")
  1326. suction := c.GetString("suction")
  1327. weight_befor_remake := c.GetString("weight_befor_remake")
  1328. assessmentBeforeDislysis := models.PredialysisEvaluation{
  1329. DialysisCount: dialysis_count,
  1330. EmergencyTreatment: emergency_treatment,
  1331. EmergencyTreatmentOther: emergency_treatment_other,
  1332. DuctusArantii: ductus_arantii,
  1333. VenousCatheterization: venous_catheterization,
  1334. VenousCatheterizationPart: venous_catheterization_part,
  1335. VenousCatheterizationPartOther: venous_catheterization_part_other,
  1336. PunctureWay: puncture_way,
  1337. BloodAccessInternalFistula: blood_access_internal_fistula,
  1338. BloodAccessNoise: blood_access_noise,
  1339. InternalFistulaOther: internal_fistula_other,
  1340. Evaluator: adminUserInfo.AdminUser.Id,
  1341. UserOrgId: adminUserInfo.CurrentOrgId,
  1342. PatientId: patient,
  1343. AssessmentDate: recordDate.Unix(),
  1344. Temperature: temperature,
  1345. PulseFrequency: pulse_frequency,
  1346. SystolicBloodPressure: systolic_blood_pressure,
  1347. DiastolicBloodPressure: diastolic_blood_pressure,
  1348. WeightBefore: weight_before,
  1349. DryWeight: dry_weight,
  1350. AdditionalWeight: additional_weight,
  1351. DialysisInterphase: dialysis_interphase,
  1352. LastPostDialysis: last_post_dialysis,
  1353. SymptomBeforeDialysis: symptom_before_dialysis,
  1354. InternalFistula: internalFistula,
  1355. InternalFistulaSkin: internal_fistula_skin,
  1356. Catheter: catheter,
  1357. CatheterBend: catheter_bend,
  1358. Complication: complication,
  1359. CreatedTime: time.Now().Unix(),
  1360. Status: 1,
  1361. Remark: remark,
  1362. IsHemorrhage: is_hemorrhage,
  1363. Hemorrhage: hemorrhage,
  1364. HemorrhageOther: hemorrhage_other,
  1365. BloodAccessPartId: bloodAccessPartId,
  1366. BloodAccessPartOperaId: bloodAccessPartOperaId,
  1367. PunctureMethod: puncture_method,
  1368. BreathingRate: breathing_rate,
  1369. IsInfect: is_infect,
  1370. Exposed: exposed,
  1371. Skin: skin,
  1372. SkinOther: skin_other,
  1373. InfectOther: infect_other,
  1374. DuctusArantiiOther: ductus_arantii_other,
  1375. MachineType: machine_type,
  1376. PunctureNeedle: puncture_needle,
  1377. HumorExcessiveSymptom: humor_excessive_symptom,
  1378. Phinholing: phinholing,
  1379. CatheterSuture: catheter_suture,
  1380. CatheterSutureOther: catheter_suture_other,
  1381. Edema: edema,
  1382. UrineVolume: urine_volume,
  1383. SpecialTreatment: special_treatment,
  1384. CatheterMaintenance: catheter_maintenance,
  1385. ThromubusType: thrombusInt,
  1386. ThrombusAv: thrombus_av,
  1387. ThromubusA: thrombus_a,
  1388. ThromubusV: thrombus_v,
  1389. Dehydration: dehydration,
  1390. PreDialysisDrugs: pre_dialysis_drugs,
  1391. Period: period,
  1392. EstimatedFoodIntake: estimated_food_intake,
  1393. BloodPressureDuringDialysis: blood_pressure_during_dialysis,
  1394. UreaBefor: urea_befor,
  1395. Suction: suction,
  1396. WeightBeforRemake: weight_befor_remake,
  1397. }
  1398. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1399. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1400. if evaluation.ID == 0 { //新增
  1401. if appRole.UserType == 2 || appRole.UserType == 1 {
  1402. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1403. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1404. } else {
  1405. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  1406. }
  1407. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  1408. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1409. redis := service.RedisClient()
  1410. //清空key 值
  1411. redis.Set(key, "", time.Second)
  1412. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1413. redis.Set(keyOne, "", time.Second)
  1414. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1415. redis.Set(keyTwo, "", time.Second)
  1416. defer redis.Close()
  1417. if err == nil {
  1418. c.ServeSuccessJSON(map[string]interface{}{
  1419. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  1420. })
  1421. } else {
  1422. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1424. }
  1425. } else { //修改
  1426. //if appRole.UserType == 3 {
  1427. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  1428. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1429. // if getPermissionErr != nil {
  1430. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1431. // return
  1432. // } else if headNursePermission == nil {
  1433. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1434. // return
  1435. // }
  1436. // }
  1437. //}
  1438. if appRole.UserType == 2 || appRole.UserType == 1 {
  1439. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1440. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1441. } else {
  1442. if evaluation.Creater == 0 {
  1443. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  1444. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  1445. } else {
  1446. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  1447. }
  1448. }
  1449. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  1450. assessmentBeforeDislysis.ID = evaluation.ID
  1451. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  1452. //
  1453. //新增逻辑
  1454. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  1455. var dewater_amount float64
  1456. dewater_amount = 0
  1457. if evaluation.DryWeight > 0 {
  1458. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  1459. if templateInfo.TemplateId == 17 || templateInfo.TemplateId == 22 || templateInfo.TemplateId == 21 || templateInfo.TemplateId == 34 {
  1460. dewater_amount = dewater_amount * 1000
  1461. }
  1462. if dewater_amount <= 0 {
  1463. dewater_amount = 0
  1464. }
  1465. } else {
  1466. dewater_amount = 0
  1467. }
  1468. // 计算透析处方的相关超滤量
  1469. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1470. var lastDialysisPrescribe *models.DialysisPrescription
  1471. var dialysisSolution *models.DialysisSolution
  1472. var dialysisPrescribe *models.DialysisPrescription
  1473. var mode_id int64
  1474. if schedual != nil {
  1475. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  1476. if dialysisPrescribe == nil {
  1477. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1478. }
  1479. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1480. // 获取透析模版
  1481. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1482. mode_id = schedual.ModeId
  1483. } else {
  1484. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  1485. // 获取透析模版
  1486. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1487. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  1488. if dialysisPrescribe == nil && dialysisSolution != nil {
  1489. mode_id = dialysisSolution.ModeId
  1490. }
  1491. if dialysisPrescribe == nil && dialysisSolution == nil {
  1492. mode_id = 0
  1493. }
  1494. }
  1495. // 插入透析处方
  1496. if dialysisPrescribe == nil && dialysisSolution != nil {
  1497. var newprescribe models.DialysisPrescription
  1498. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1499. newprescribe.PatientId = dialysisSolution.PatientId
  1500. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1501. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1502. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1503. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1504. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1505. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1506. newprescribe.ModeId = dialysisSolution.ModeId
  1507. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1508. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1509. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1510. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1511. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1512. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1513. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1514. newprescribe.Glucose = dialysisSolution.Glucose
  1515. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1516. newprescribe.Kalium = dialysisSolution.Kalium
  1517. newprescribe.Sodium = dialysisSolution.Sodium
  1518. newprescribe.Calcium = dialysisSolution.Calcium
  1519. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1520. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1521. newprescribe.Conductivity = dialysisSolution.Conductivity
  1522. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1523. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1524. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1525. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1526. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1527. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1528. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1529. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1530. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1531. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1532. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1533. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1534. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1535. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1536. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1537. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1538. newprescribe.CreatedTime = time.Now().Unix()
  1539. newprescribe.UpdatedTime = time.Now().Unix()
  1540. newprescribe.RecordDate = recordDate.Unix()
  1541. newprescribe.DewaterAmount = dewater_amount
  1542. newprescribe.TargetUltrafiltration = dewater_amount
  1543. newprescribe.Status = 1
  1544. err := service.AddSigleRecord(&newprescribe)
  1545. if err != nil {
  1546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1547. }
  1548. }
  1549. if dialysisPrescribe == nil && dialysisSolution == nil {
  1550. if lastDialysisPrescribe != nil {
  1551. var newprescribe models.DialysisPrescription
  1552. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  1553. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  1554. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  1555. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  1556. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  1557. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  1558. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  1559. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  1560. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  1561. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  1562. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  1563. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  1564. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  1565. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  1566. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  1567. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  1568. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  1569. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  1570. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  1571. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  1572. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  1573. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  1574. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  1575. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  1576. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  1577. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  1578. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  1579. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  1580. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  1581. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  1582. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  1583. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  1584. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  1585. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  1586. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  1587. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  1588. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  1589. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  1590. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  1591. newprescribe.CreatedTime = time.Now().Unix()
  1592. newprescribe.UpdatedTime = time.Now().Unix()
  1593. newprescribe.RecordDate = recordDate.Unix()
  1594. newprescribe.DewaterAmount = dewater_amount
  1595. newprescribe.TargetUltrafiltration = dewater_amount
  1596. newprescribe.Status = 1
  1597. err := service.AddSigleRecord(&newprescribe)
  1598. if err != nil {
  1599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1600. }
  1601. } else {
  1602. var newprescribe models.DialysisPrescription
  1603. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  1604. newprescribe.PatientId = patient
  1605. newprescribe.ModeId = mode_id
  1606. newprescribe.CreatedTime = time.Now().Unix()
  1607. newprescribe.UpdatedTime = time.Now().Unix()
  1608. newprescribe.RecordDate = recordDate.Unix()
  1609. newprescribe.DewaterAmount = dewater_amount
  1610. newprescribe.TargetUltrafiltration = dewater_amount
  1611. newprescribe.Status = 1
  1612. err := service.AddSigleRecord(&newprescribe)
  1613. if err != nil {
  1614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1615. }
  1616. }
  1617. }
  1618. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  1619. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1620. redis := service.RedisClient()
  1621. //清空key 值
  1622. redis.Set(key, "", time.Second)
  1623. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1624. redis.Set(keyOne, "", time.Second)
  1625. defer redis.Close()
  1626. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1627. redis.Set(keyTwo, "", time.Second)
  1628. if err == nil {
  1629. c.ServeSuccessJSON(map[string]interface{}{
  1630. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  1631. })
  1632. } else {
  1633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1634. }
  1635. }
  1636. }
  1637. func (c *DialysisApiController) PostTreatmentSummary() {
  1638. patient, _ := c.GetInt64("patient", 0)
  1639. recordDateStr := c.GetString("record_date")
  1640. if patient <= 0 {
  1641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1642. return
  1643. }
  1644. adminUserInfo := c.GetAdminUserInfo()
  1645. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1646. if patientInfo.ID == 0 {
  1647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1648. return
  1649. }
  1650. if len(recordDateStr) == 0 {
  1651. recordDateStr = time.Now().Format("2006-01-02")
  1652. }
  1653. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1654. if parseDateErr != nil {
  1655. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1657. return
  1658. }
  1659. mission := c.GetString("mission")
  1660. dialysis_summary := c.GetString("dialysis_summary")
  1661. nursingRecord := c.GetString("nursing_record")
  1662. specialRecord := c.GetString("special_record")
  1663. sj_nurse := adminUserInfo.AdminUser.Id
  1664. zl_nurse := adminUserInfo.AdminUser.Id
  1665. hd_nurse := adminUserInfo.AdminUser.Id
  1666. xj_nurse := adminUserInfo.AdminUser.Id
  1667. zl_doctor := adminUserInfo.AdminUser.Id
  1668. treatmentSummary := models.TreatmentSummary{
  1669. UserOrgId: adminUserInfo.CurrentOrgId,
  1670. PatientId: patient,
  1671. AssessmentDate: recordDate.Unix(),
  1672. Mission: mission,
  1673. DialysisSummary: dialysis_summary,
  1674. SjNurse: sj_nurse,
  1675. ZlNurse: zl_nurse,
  1676. HdNurse: hd_nurse,
  1677. XjNurse: xj_nurse,
  1678. ZlDoctor: zl_doctor,
  1679. Status: 1,
  1680. CreatedTime: time.Now().Unix(),
  1681. NursingRecord: nursingRecord,
  1682. SpecialRecord: specialRecord,
  1683. }
  1684. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1685. if tempTreatmentSummary.ID == 0 { //新增
  1686. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  1687. err := service.AddSigleSummaryRecord(&treatmentSummary)
  1688. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  1689. redis := service.RedisClient()
  1690. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  1691. redis.Set(keyOne, "", time.Second)
  1692. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1693. redis.Set(keyThree, "", time.Second)
  1694. defer redis.Close()
  1695. //清空key 值
  1696. redis.Set(key, "", time.Second)
  1697. if err == nil {
  1698. c.ServeSuccessJSON(map[string]interface{}{
  1699. "summary": treatmentSummary,
  1700. })
  1701. } else {
  1702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1703. }
  1704. } else { //修改
  1705. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  1706. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1707. // if getPermissionErr != nil {
  1708. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1709. // return
  1710. // } else if headNursePermission == nil {
  1711. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1712. // return
  1713. // }
  1714. //}
  1715. treatmentSummary.Creater = tempTreatmentSummary.Creater
  1716. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  1717. treatmentSummary.UpdatedTime = time.Now().Unix()
  1718. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  1719. treatmentSummary.ID = tempTreatmentSummary.ID
  1720. err := service.UpdateSummeRecord(&treatmentSummary)
  1721. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  1722. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  1723. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1724. //清空key 值
  1725. redis := service.RedisClient()
  1726. redis.Set(key, "", time.Second)
  1727. redis.Set(keyOne, "", time.Second)
  1728. redis.Set(keyThree, "", time.Second)
  1729. defer redis.Close()
  1730. if err == nil {
  1731. c.ServeSuccessJSON(map[string]interface{}{
  1732. "summary": treatmentSummary,
  1733. })
  1734. } else {
  1735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1736. }
  1737. }
  1738. }
  1739. func (c *DialysisApiController) GetDeviceList() {
  1740. adminUserInfo := c.GetAdminUserInfo()
  1741. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  1742. c.ServeSuccessJSON(map[string]interface{}{
  1743. "device": device,
  1744. })
  1745. }
  1746. func (c *DialysisApiController) GetAllDeviceZone() {
  1747. adminUserInfo := c.GetAdminUserInfo()
  1748. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  1749. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1750. if err == nil {
  1751. c.ServeSuccessJSON(map[string]interface{}{
  1752. "zone": zone,
  1753. "dics": dics,
  1754. })
  1755. }
  1756. }
  1757. func (c *DialysisApiController) GetDialysisWatch() {
  1758. page, _ := c.GetInt64("page", 1)
  1759. limit, _ := c.GetInt64("limit", 10)
  1760. schedulType, _ := c.GetInt64("schedul_type", 0)
  1761. startTime, _ := c.GetInt64("schedul_time", 0)
  1762. partitionType, _ := c.GetInt64("partition_type", 0)
  1763. keywords := c.GetString("keywords")
  1764. start_time, _ := c.GetInt64("start_time")
  1765. end_time, _ := c.GetInt64("end_time")
  1766. adminUserInfo := c.GetAdminUserInfo()
  1767. if len(keywords) > 0 {
  1768. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  1769. if err == nil {
  1770. c.ServeSuccessJSON(map[string]interface{}{
  1771. "schedule": dialysisSchedule,
  1772. "total": total,
  1773. })
  1774. } else {
  1775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1776. }
  1777. } else {
  1778. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  1779. if err == nil {
  1780. c.ServeSuccessJSON(map[string]interface{}{
  1781. "schedule": dialysisSchedule,
  1782. "total": total,
  1783. })
  1784. } else {
  1785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1786. }
  1787. }
  1788. }
  1789. //func (c *DialysisApiController) GetDialysisWatch() {
  1790. // page, _ := c.GetInt64("page", 1)
  1791. // limit, _ := c.GetInt64("limit", 10)
  1792. // schedulType, _ := c.GetInt64("schedul_type", 0)
  1793. // startTime, _ := c.GetInt64("schedul_time", 0)
  1794. // partitionType, _ := c.GetInt64("partition_type", 0)
  1795. // keywords := c.GetString("keywords")
  1796. //
  1797. // adminUserInfo := c.GetAdminUserInfo()
  1798. // if len(keywords) > 0 {
  1799. // dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  1800. //
  1801. // //获取所有床位号
  1802. // numberList, _ := service.GetAllDeviceNumberByListSix(adminUserInfo.CurrentOrgId)
  1803. //
  1804. // //获取透析处方
  1805. // prescriptions, _ := service.GetAllPrescriptionByListTwo(adminUserInfo.CurrentOrgId, startTime)
  1806. // //获取透前评估
  1807. // assessmentBefores, _ := service.GetAllAssessmentBeforesByListThree(adminUserInfo.CurrentOrgId, startTime)
  1808. // //获取上机
  1809. // dialysisOrders, _ := service.GetAllDialysisOrdersByListThree(adminUserInfo.CurrentOrgId, startTime)
  1810. // //获取透后
  1811. // AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListThree(adminUserInfo.CurrentOrgId, startTime)
  1812. //
  1813. // //获取透后监测
  1814. // monitorlist, _ := service.GetAllMonitorListThree(adminUserInfo.CurrentOrgId, startTime)
  1815. //
  1816. // //获取所有的患者
  1817. // patients, _ := service.GetAllPatientListByListSix(adminUserInfo.CurrentOrgId,keywords)
  1818. //
  1819. // //获取所有透析模式
  1820. // treatments, _ := service.GetAllTreatModeByList(adminUserInfo.CurrentOrgId)
  1821. //
  1822. // for key, scheduals := range dialysisSchedule {
  1823. // // 获取患者信息
  1824. // for _, patient := range patients {
  1825. // if scheduals.PatientId == patient.ID {
  1826. // dialysisSchedule[key].MonitorPatients = patient
  1827. // break
  1828. // }
  1829. // }
  1830. // // 床位信息
  1831. // for _, device := range numberList {
  1832. // if scheduals.BedId == device.ID {
  1833. // dialysisSchedule[key].DeviceNumber = device
  1834. // break
  1835. // }
  1836. // }
  1837. //
  1838. // // 医嘱信息
  1839. // for _, prescription := range prescriptions {
  1840. // if scheduals.PatientId == prescription.PatientId {
  1841. // dialysisSchedule[key].Prescription = prescription
  1842. // break
  1843. // }
  1844. // }
  1845. //
  1846. // // 透前评估
  1847. // for _, assessmentBefore := range assessmentBefores {
  1848. // if scheduals.PatientId == assessmentBefore.PatientId {
  1849. // dialysisSchedule[key].AssessmentBeforeDislysis = assessmentBefore
  1850. // break
  1851. // }
  1852. // }
  1853. //
  1854. // // 透析上下机
  1855. // for _, dialysisOrder := range dialysisOrders {
  1856. // if scheduals.PatientId == dialysisOrder.PatientId {
  1857. // dialysisSchedule[key].DialysisOrder = dialysisOrder
  1858. // break
  1859. // }
  1860. // }
  1861. //
  1862. // records := make([]*models.MonitoringRecord, 0)
  1863. // // 透析监测
  1864. // for _, it := range monitorlist {
  1865. // records := append(records, it)
  1866. // if scheduals.PatientId == it.PatientId {
  1867. // dialysisSchedule[key].MonitoringRecord = records
  1868. // }
  1869. // }
  1870. //
  1871. // // 透后评估
  1872. // for _, afterDislysis := range AssessmentAfterDislysis {
  1873. // if scheduals.PatientId == afterDislysis.PatientId {
  1874. // dialysisSchedule[key].AssessmentAfterDislysis = afterDislysis
  1875. // break
  1876. // }
  1877. // }
  1878. //
  1879. // //透析模式
  1880. // for _, treatment := range treatments {
  1881. // if scheduals.ModeId == treatment.ID {
  1882. // dialysisSchedule[key].TreatmentMode = treatment
  1883. // break
  1884. // }
  1885. // }
  1886. // }
  1887. // //获取所有床位号
  1888. // if err == nil {
  1889. // c.ServeSuccessJSON(map[string]interface{}{
  1890. // "schedule": dialysisSchedule,
  1891. // "total": total,
  1892. // })
  1893. // } else {
  1894. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1895. // }
  1896. //
  1897. // } else {
  1898. // dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  1899. // if err == nil {
  1900. // c.ServeSuccessJSON(map[string]interface{}{
  1901. // "schedule": dialysisSchedule,
  1902. // "total": total,
  1903. // })
  1904. // } else {
  1905. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1906. // }
  1907. // }
  1908. //}
  1909. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  1910. patientId, _ := c.GetInt64("id", 0)
  1911. record_date, _ := c.GetInt64("record_date", 0)
  1912. adminUserInfo := c.GetAdminUserInfo()
  1913. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1914. var dialysisStatus int64
  1915. if dialysisOrder == nil { //没有透析记录
  1916. dialysisStatus = 0 //未透析
  1917. } else {
  1918. dialysisStatus = dialysisOrder.Stage
  1919. }
  1920. //用户基本信息
  1921. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1922. //接诊评估
  1923. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1924. //透前评估
  1925. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1926. //临时医嘱
  1927. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1928. //双人核对
  1929. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1930. //透析监测
  1931. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  1932. //透后评估
  1933. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1934. //透析小结
  1935. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1936. //透析处方
  1937. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1938. if dialysisPrescription.ID == 0 {
  1939. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  1940. c.ServeSuccessJSON(map[string]interface{}{
  1941. "patientInfo": schedualPatientInfo,
  1942. "dialysisPrescription": solution,
  1943. "receiverTreatmentAccess": receiverTreatmentAccess,
  1944. "predialysisEvaluation": PredialysisEvaluation,
  1945. "doctorAdvice": DoctorAdvice,
  1946. "doubleCheck": DoubleCheck,
  1947. "assessmentAfterDislysis": AssessmentAfterDislysis,
  1948. "treatmentSummary": TreatmentSummary,
  1949. "monitorRecord": Record,
  1950. "dialysisStatus": dialysisStatus,
  1951. "dialysisOrder": dialysisOrder,
  1952. "isSolution": 1,
  1953. })
  1954. } else {
  1955. c.ServeSuccessJSON(map[string]interface{}{
  1956. "patientInfo": schedualPatientInfo,
  1957. "dialysisPrescription": dialysisPrescription,
  1958. "receiverTreatmentAccess": receiverTreatmentAccess,
  1959. "predialysisEvaluation": PredialysisEvaluation,
  1960. "doctorAdvice": DoctorAdvice,
  1961. "doubleCheck": DoubleCheck,
  1962. "assessmentAfterDislysis": AssessmentAfterDislysis,
  1963. "treatmentSummary": TreatmentSummary,
  1964. "monitorRecord": Record,
  1965. "dialysisStatus": dialysisStatus,
  1966. "dialysisOrder": dialysisOrder,
  1967. "isSolution": 2,
  1968. })
  1969. }
  1970. }
  1971. func (c *DialysisApiController) CreateDoctorAdvice() {
  1972. patient, _ := c.GetInt64("id", 0)
  1973. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  1974. record_date, _ := c.GetInt64("record_date", 0)
  1975. if patient <= 0 {
  1976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1977. return
  1978. }
  1979. adminUserInfo := c.GetAdminUserInfo()
  1980. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1981. if patientInfo.ID == 0 {
  1982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1983. return
  1984. }
  1985. var advice models.DoctorAdvice
  1986. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  1987. if code > 0 {
  1988. c.ServeFailJSONWithSGJErrorCode(code)
  1989. return
  1990. }
  1991. if advice.ParentId > 0 {
  1992. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  1993. if old.ID == 0 || old.PatientId != patient {
  1994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1995. return
  1996. }
  1997. if old.StopState == 1 || old.ExecutionState == 1 {
  1998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1999. return
  2000. }
  2001. if old.ParentId > 0 {
  2002. advice.ParentId = old.ParentId
  2003. }
  2004. advice.StartTime = old.StartTime
  2005. advice.AdviceDoctor = old.AdviceDoctor
  2006. advice.DeliveryWay = old.DeliveryWay
  2007. advice.ExecutionFrequency = old.ExecutionFrequency
  2008. }
  2009. advice.RecordDate = record_date
  2010. advice.DialysisOrderId = dialysis_id
  2011. advice.Status = 1
  2012. advice.CreatedTime = time.Now().Unix()
  2013. advice.UpdatedTime = time.Now().Unix()
  2014. advice.StopState = 2
  2015. advice.ExecutionState = 2
  2016. advice.AdviceType = 2
  2017. advice.UserOrgId = adminUserInfo.CurrentOrgId
  2018. advice.PatientId = patient
  2019. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2020. err := service.CreateDoctorAdvice(&advice)
  2021. if err != nil {
  2022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2023. return
  2024. }
  2025. for _, subAdvice := range subAdivice {
  2026. subAdvice.ParentId = advice.ID
  2027. subAdvice.PatientId = patient
  2028. subAdvice.RecordDate = record_date
  2029. subAdvice.CreatedTime = time.Now().Unix()
  2030. subAdvice.UpdatedTime = time.Now().Unix()
  2031. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  2032. }
  2033. service.CreateSubDoctorAdvice(subAdivice)
  2034. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  2035. c.ServeSuccessJSON(map[string]interface{}{
  2036. "msg": "ok",
  2037. "advice": advice,
  2038. "subAdvice": subAdivices,
  2039. })
  2040. return
  2041. }
  2042. func (c *DialysisApiController) EditDoctorAdvice() {
  2043. patient, _ := c.GetInt64("patient", 0)
  2044. id, _ := c.GetInt64("id", 0)
  2045. parent_id, _ := c.GetInt64("parent_id", 0)
  2046. execution_time := c.GetString("execution_time")
  2047. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  2048. // checker, _ := c.GetInt64("checker", 0)
  2049. if id <= 0 || patient <= 0 {
  2050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2051. return
  2052. }
  2053. adminUserInfo := c.GetAdminUserInfo()
  2054. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2055. if advice.ID == 0 || advice.PatientId != patient {
  2056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2057. return
  2058. }
  2059. if len(execution_time) <= 0 {
  2060. utils.ErrorLog("execution_time")
  2061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2062. return
  2063. }
  2064. execution_staff := adminUserInfo.AdminUser.Id
  2065. checker := adminUserInfo.AdminUser.Id
  2066. timeLayout2 := "2006-01-02 15:04"
  2067. loc, _ := time.LoadLocation("Local")
  2068. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  2069. if errs != nil {
  2070. utils.ErrorLog(errs.Error())
  2071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2072. return
  2073. }
  2074. advices := models.DoctorAdvice{
  2075. ExecutionStaff: execution_staff,
  2076. ExecutionTime: theTime.Unix(),
  2077. Checker: checker,
  2078. UpdatedTime: time.Now().Unix(),
  2079. }
  2080. var err error
  2081. if parent_id > 0 {
  2082. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  2083. } else {
  2084. err = service.ExceDoctorAdviceById(&advices, id, patient)
  2085. }
  2086. if err != nil {
  2087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2088. return
  2089. }
  2090. c.ServeSuccessJSON(map[string]interface{}{
  2091. "msg": "ok",
  2092. "advice": advice,
  2093. })
  2094. return
  2095. }
  2096. func (c *DialysisApiController) GetDoctorAdvice() {
  2097. patient, _ := c.GetInt64("patient_id", 0)
  2098. parent_id, _ := c.GetInt64("parent_id", 0)
  2099. adviceId, _ := c.GetInt64("id", 0)
  2100. if patient <= 0 {
  2101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2102. return
  2103. }
  2104. dminUserInfo := c.GetAdminUserInfo()
  2105. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  2106. if patientInfo.ID == 0 {
  2107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2108. return
  2109. }
  2110. var subAdvice []*models.DoctorAdvice
  2111. var advice models.DoctorAdvice
  2112. if parent_id > 0 {
  2113. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  2114. if advice.ID == 0 || advice.PatientId != patient {
  2115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2116. return
  2117. }
  2118. subAdvice = service.FindSubAdivceById(patient, parent_id)
  2119. } else {
  2120. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  2121. if advice.ID == 0 || advice.PatientId != patient {
  2122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2123. return
  2124. }
  2125. subAdvice = service.FindSubAdivceById(patient, adviceId)
  2126. }
  2127. c.ServeSuccessJSON(map[string]interface{}{
  2128. "msg": "ok",
  2129. "advice": advice,
  2130. "subAdvice": subAdvice,
  2131. })
  2132. }
  2133. func (this *DialysisApiController) DelMonitor() {
  2134. recordID, _ := this.GetInt64("record_id")
  2135. patientID, _ := this.GetInt64("patient_id")
  2136. if recordID <= 0 || patientID <= 0 {
  2137. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2138. return
  2139. }
  2140. adminInfo := this.GetAdminUserInfo()
  2141. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  2142. if getPatientErr != nil {
  2143. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2144. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2145. return
  2146. } else if patient == nil {
  2147. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2148. return
  2149. }
  2150. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  2151. if getMonitorErr != nil {
  2152. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2153. return
  2154. }
  2155. //if monitor != nil {
  2156. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  2157. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2158. // if getPermissionErr != nil {
  2159. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2160. // return
  2161. // } else if headNursePermission == nil {
  2162. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2163. // return
  2164. // }
  2165. // }
  2166. //}
  2167. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  2168. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  2169. redis := service.RedisClient()
  2170. //清空key 值
  2171. redis.Set(key, "", time.Second)
  2172. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  2173. redis.Set(keyOne, "", time.Second)
  2174. defer redis.Close()
  2175. if err != nil {
  2176. this.ErrorLog("删除透析监测记录失败:%v", err)
  2177. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  2178. return
  2179. }
  2180. this.ServeSuccessJSON(map[string]interface{}{
  2181. "record_id": monitor.ID,
  2182. })
  2183. }
  2184. func (c *DialysisApiController) CreateMonitor() {
  2185. patient, _ := c.GetInt64("id", 0)
  2186. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  2187. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  2188. operate_time, _ := c.GetInt64("operate_time", 0)
  2189. // monitoring_time := c.GetString("monitoring_time")
  2190. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  2191. breathing_rated := c.GetString("breathing_rated")
  2192. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  2193. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  2194. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  2195. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  2196. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  2197. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  2198. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  2199. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  2200. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  2201. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  2202. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  2203. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  2204. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  2205. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  2206. temperature, _ := c.GetFloat("temperature", 0)
  2207. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  2208. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  2209. conductivity, _ := c.GetFloat("conductivity", 0)
  2210. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  2211. heparin, _ := c.GetFloat("heparin", 0)
  2212. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  2213. ktv, _ := c.GetFloat("ktv", 0)
  2214. symptom := c.GetString("symptom")
  2215. dispose := c.GetString("dispose")
  2216. result := c.GetString("results")
  2217. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  2218. monitor_anticoagulant, _ := c.GetInt64("monitor_anticoagulant")
  2219. monitor_anticoagulant_value := c.GetString("monitor_anticoagulant_value")
  2220. monitoring_date = monitoring_date / 1000
  2221. // operate_time = operate_time / 1000
  2222. if patient <= 0 {
  2223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2224. return
  2225. }
  2226. adminUserInfo := c.GetAdminUserInfo()
  2227. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2228. if patientInfo.ID == 0 {
  2229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2230. return
  2231. }
  2232. monitorRecord := models.MonitoringRecord{
  2233. PatientId: patient,
  2234. MonitoringDate: monitoring_date,
  2235. DialysisOrderId: dialysis_order_id,
  2236. OperateTime: operate_time,
  2237. // MonitoringTime: monitoring_time,
  2238. PulseFrequency: pulse_frequency,
  2239. BreathingRate: breathing_rated,
  2240. SystolicBloodPressure: systolic_blood_pressure,
  2241. DiastolicBloodPressure: diastolic_blood_pressure,
  2242. BloodPressureType: blood_pressure_type,
  2243. BloodFlowVolume: blood_flow_volume,
  2244. VenousPressure: venous_pressure,
  2245. VenousPressureType: venous_pressure_type,
  2246. TransmembranePressure: transmembrane_pressure,
  2247. TransmembranePressureType: transmembrane_pressure_type,
  2248. UltrafiltrationRate: ultrafiltration_rate,
  2249. UltrafiltrationVolume: ultrafiltration_volume,
  2250. SodiumConcentration: sodium_concentration,
  2251. ArterialPressure: arterial_pressure,
  2252. ArterialPressureType: arterial_pressure_type,
  2253. DialysateTemperature: dialysate_temperature,
  2254. Temperature: temperature,
  2255. ReplacementRate: replacement_rate,
  2256. DisplacementQuantity: displacement_quantity,
  2257. Ktv: ktv,
  2258. Symptom: symptom,
  2259. Dispose: dispose,
  2260. Result: result,
  2261. MonitoringNurse: monitoring_nurse,
  2262. Status: 1,
  2263. CreatedTime: time.Now().Unix(),
  2264. UpdatedTime: time.Now().Unix(),
  2265. UserOrgId: adminUserInfo.CurrentOrgId,
  2266. Conductivity: conductivity,
  2267. DisplacementFlowQuantity: displacement_flow_quantity,
  2268. Heparin: heparin,
  2269. DialysateFlow: dialysate_flow,
  2270. MonitorAnticoagulant: monitor_anticoagulant,
  2271. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  2272. }
  2273. err := service.CreateMonitor(&monitorRecord)
  2274. redis := service.RedisClient()
  2275. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_record_list_all"
  2276. redis.Set(key, "", time.Second)
  2277. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  2278. redis.Set(keyOne, "", time.Second)
  2279. redis.Close()
  2280. if err != nil {
  2281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2282. return
  2283. }
  2284. c.ServeSuccessJSON(map[string]interface{}{
  2285. "msg": "ok",
  2286. "monitor": monitorRecord,
  2287. })
  2288. return
  2289. }
  2290. // 已弃用
  2291. // func (c *DialysisApiController) CreateRecordData() {
  2292. // patient, _ := c.GetInt64("id", 0)
  2293. // status, _ := c.GetInt64("status", 0)
  2294. // now := time.Now()
  2295. // year, month, day := now.Date()
  2296. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2297. // todayTimeStamp := today_time.Unix()
  2298. // if patient <= 0 {
  2299. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2300. // return
  2301. // }
  2302. // adminUserInfo := c.GetAdminUserInfo()
  2303. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2304. // if patientInfo.ID == 0 {
  2305. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2306. // return
  2307. // }
  2308. // record := &models.DialysisOrder{
  2309. // DialysisDate: todayTimeStamp,
  2310. // UserOrgId: adminUserInfo.CurrentOrgId,
  2311. // PatientId: patient,
  2312. // Stage: status,
  2313. // Status: 1,
  2314. // CreatedTime: time.Now().Unix(),
  2315. // UpdatedTime: time.Now().Unix(),
  2316. // }
  2317. // if status == 1 {
  2318. // //创建透析记录
  2319. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  2320. // if err == nil {
  2321. // c.ServeSuccessJSON(map[string]interface{}{
  2322. // "dialysisOrder": record,
  2323. // })
  2324. // } else {
  2325. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2326. // }
  2327. // } else {
  2328. // record_id, _ := c.GetInt64("record_id", 0)
  2329. // //修改透析记录状态
  2330. // errs := service.ModifyDialysisRecord(record_id)
  2331. // //结束时候透析次数加1
  2332. // service.UpdateSolutionByPatientId(patient)
  2333. // if errs == nil {
  2334. // c.ServeSuccessJSON(map[string]interface{}{
  2335. // "dialysisOrder": record,
  2336. // })
  2337. // } else {
  2338. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2339. // }
  2340. // }
  2341. // }
  2342. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  2343. dataBody := make(map[string]interface{}, 0)
  2344. err := json.Unmarshal(data, &dataBody)
  2345. if err != nil {
  2346. utils.ErrorLog(err.Error())
  2347. code = enums.ErrorCodeParamWrong
  2348. return
  2349. }
  2350. timeLayout := "2006-01-02 "
  2351. timeLayout2 := "2006-01-02 15:04"
  2352. loc, _ := time.LoadLocation("Local")
  2353. if action == "create" {
  2354. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2355. utils.ErrorLog("advice_type")
  2356. code = enums.ErrorCodeParamWrong
  2357. return
  2358. }
  2359. adviceType := int64(dataBody["advice_type"].(float64))
  2360. if adviceType != 1 && adviceType != 2 {
  2361. utils.ErrorLog("advice_type != 1&&2")
  2362. code = enums.ErrorCodeParamWrong
  2363. return
  2364. }
  2365. advice.AdviceType = adviceType
  2366. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2367. utils.ErrorLog("advice_date")
  2368. code = enums.ErrorCodeParamWrong
  2369. return
  2370. }
  2371. adviceDate, _ := dataBody["advice_date"].(string)
  2372. if len(adviceDate) == 0 {
  2373. utils.ErrorLog("len(adviceDate) == 0")
  2374. code = enums.ErrorCodeParamWrong
  2375. return
  2376. }
  2377. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2378. if err != nil {
  2379. utils.ErrorLog(err.Error())
  2380. code = enums.ErrorCodeParamWrong
  2381. return
  2382. }
  2383. advice.AdviceDate = theTime.Unix()
  2384. }
  2385. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2386. utils.ErrorLog("start_time")
  2387. code = enums.ErrorCodeParamWrong
  2388. return
  2389. }
  2390. startDate, _ := dataBody["start_time"].(string)
  2391. if len(startDate) == 0 {
  2392. utils.ErrorLog("len(startDate) == 0")
  2393. code = enums.ErrorCodeParamWrong
  2394. return
  2395. }
  2396. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  2397. if err != nil {
  2398. utils.ErrorLog(err.Error())
  2399. code = enums.ErrorCodeParamWrong
  2400. return
  2401. }
  2402. advice.StartTime = theTime.Unix()
  2403. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2404. utils.ErrorLog("advice_name")
  2405. code = enums.ErrorCodeParamWrong
  2406. return
  2407. }
  2408. adviceName, _ := dataBody["advice_name"].(string)
  2409. if len(adviceName) == 0 {
  2410. utils.ErrorLog("len(advice_name) == 0")
  2411. code = enums.ErrorCodeParamWrong
  2412. return
  2413. }
  2414. advice.AdviceName = adviceName
  2415. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  2416. utils.ErrorLog("delivery_way")
  2417. code = enums.ErrorCodeParamWrong
  2418. return
  2419. }
  2420. deliveryWay, _ := dataBody["delivery_way"].(string)
  2421. if len(deliveryWay) == 0 {
  2422. utils.ErrorLog("len(deliveryWay) == 0")
  2423. code = enums.ErrorCodeParamWrong
  2424. return
  2425. }
  2426. advice.DeliveryWay = deliveryWay
  2427. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  2428. utils.ErrorLog("execution_frequency")
  2429. code = enums.ErrorCodeParamWrong
  2430. return
  2431. }
  2432. execution_frequency, _ := dataBody["execution_frequency"].(string)
  2433. if len(execution_frequency) == 0 {
  2434. utils.ErrorLog("len(execution_frequency) == 0")
  2435. code = enums.ErrorCodeParamWrong
  2436. return
  2437. }
  2438. advice.ExecutionFrequency = execution_frequency
  2439. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  2440. adviceDsc, _ := dataBody["advice_desc"].(string)
  2441. advice.AdviceDesc = adviceDsc
  2442. }
  2443. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  2444. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  2445. advice.DrugSpecUnit = drugSpecUnit
  2446. }
  2447. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  2448. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  2449. advice.SingleDose = singleDose
  2450. }
  2451. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  2452. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  2453. advice.SingleDoseUnit = singleDoseUnit
  2454. }
  2455. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  2456. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  2457. advice.PrescribingNumber = prescribingNumber
  2458. }
  2459. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  2460. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  2461. advice.PrescribingNumberUnit = prescribingNumberUnit
  2462. }
  2463. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  2464. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  2465. if len(thisContagions) > 0 {
  2466. for _, item := range thisContagions {
  2467. items := item.(map[string]interface{})
  2468. advice_name, _ := items["advice_name"].(string)
  2469. advice_desc, _ := items["advice_desc"].(string)
  2470. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  2471. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  2472. single_dose_unit, _ := items["single_dose_unit"].(string)
  2473. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  2474. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  2475. advice := &models.DoctorAdvice{
  2476. AdviceName: advice_name,
  2477. AdviceDesc: advice_desc,
  2478. SingleDose: single_dose,
  2479. SingleDoseUnit: single_dose_unit,
  2480. DrugSpecUnit: drug_spec_unit,
  2481. PrescribingNumber: prescribing_number,
  2482. PrescribingNumberUnit: prescribing_number_unit,
  2483. }
  2484. subAdvice = append(subAdvice, advice)
  2485. }
  2486. }
  2487. }
  2488. return
  2489. }
  2490. func (c *DialysisApiController) GetDialysisOrder() {
  2491. xtno := c.GetString("xtno")
  2492. xtdate := c.GetString("xtdate")
  2493. timeLayout := "2006-01-02"
  2494. loc, _ := time.LoadLocation("Local")
  2495. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  2496. if err != nil {
  2497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2498. return
  2499. }
  2500. xttime := theTime.Unix()
  2501. operatorIDs := make([]int64, 0)
  2502. adminUserInfo := c.GetAdminUserInfo()
  2503. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  2504. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.CurrentOrgId, xtno, xttime)
  2505. //透析单
  2506. dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2507. if dialysisOrder != nil {
  2508. if dialysisOrder.FinishNurse > 0 {
  2509. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  2510. }
  2511. if dialysisOrder.StartNurse > 0 {
  2512. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  2513. }
  2514. }
  2515. //透前评估
  2516. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2517. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  2518. //透后评估
  2519. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2520. if AssessmentAfterDislysis.Modifier > 0 {
  2521. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  2522. }
  2523. //上次透前评估
  2524. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2525. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2526. //透析处方
  2527. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2528. if dialysisPrescription.PrescriptionDoctor > 0 {
  2529. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  2530. }
  2531. //获取病人的透析模式
  2532. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2533. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2534. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2535. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2536. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2537. //获取透析处方
  2538. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2539. //获取临时医嘱
  2540. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2541. //config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  2542. //获取医嘱内容
  2543. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2544. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2545. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2546. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2547. //获取上次的透后体重
  2548. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2549. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2550. //获取透析次数
  2551. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  2552. if len(DoctorAdvice) > 0 {
  2553. for _, item := range DoctorAdvice {
  2554. if item.AdviceDoctor > 0 {
  2555. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2556. }
  2557. if item.ExecutionStaff > 0 {
  2558. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2559. }
  2560. if item.Checker > 0 {
  2561. operatorIDs = append(operatorIDs, item.Checker)
  2562. }
  2563. }
  2564. }
  2565. //透析监测
  2566. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2567. //透析检测
  2568. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2569. //透析小结
  2570. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2571. //接诊评估
  2572. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2573. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2574. if adminUserInfo.CurrentOrgId != 10101 {
  2575. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2576. patientInfo.TotalDialysis = dialysis_count
  2577. }
  2578. if adminUserInfo.CurrentOrgId == 10101 {
  2579. dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2580. patientInfo.TotalDialysis = dialysis_count
  2581. }
  2582. //相关操作对应的操作人
  2583. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  2584. operators, err := service.GetAdminUserEsOne(adminUserInfo.CurrentOrgId)
  2585. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2586. //获取当前日期月份的第一天
  2587. firstmonth := service.GetFirstDateOfMonth(theTime)
  2588. firstMonthDate := firstmonth.Unix()
  2589. //获取当前月份的病人透析次数
  2590. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  2591. //获取his数据
  2592. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2593. //hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2594. config, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  2595. project_config, _ := service.GetHisProjectConfig(adminUserInfo.CurrentOrgId)
  2596. projects, _ := service.FindAllHisProjectById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2597. //if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  2598. // for _, item := range projects {
  2599. // var advice *models.HisDoctorAdviceInfo
  2600. // advice.ID = item.ID
  2601. // advice.Checker = item.Checker
  2602. // advice.CheckTime = item.CheckTime
  2603. // advice.CheckState = item.CheckState
  2604. // advice.ExecutionState = item.ExecutionState
  2605. // advice.ExecutionStaff = item.ExecutionStaff
  2606. // advice.PrescribingNumber = float64(item.Count)
  2607. // advice.PrescribingNumberUnit = item.Unit
  2608. // advice.AdviceDoctor = item.Doctor
  2609. // if item.Type == 3 {
  2610. // advice.AdviceName = item.GoodInfo.GoodName
  2611. // } else if item.Type == 2 {
  2612. // advice.AdviceName = item.HisProject.ProjectName
  2613. // }
  2614. // advice.StartTime = item.StartTime
  2615. // hisAdvice = append(hisAdvice, advice)
  2616. // }
  2617. //}
  2618. if config.IsOpen == 1 {
  2619. c.ServeSuccessJSON(map[string]interface{}{
  2620. "xtdate": xtdate,
  2621. "users": adminUser,
  2622. "patientInfo": patientInfo,
  2623. "PredialysisEvaluation": PredialysisEvaluation,
  2624. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2625. "dialysisPrescription": dialysisPrescription,
  2626. "advices": hisAdvice,
  2627. "monitors": Record,
  2628. "summary": TreatmentSummary,
  2629. "receiverTreatmentAccess": receiverTreatmentAccess,
  2630. "dialysisOrder": dialysisOrder,
  2631. "operators": operators,
  2632. "org_template_info": templateInfo,
  2633. "check": check,
  2634. "schedule": schedule,
  2635. "dialysisway": dialysisway,
  2636. "order": order,
  2637. "doctorAdvice": doctorAdvice,
  2638. "doctor": doctor,
  2639. "nurse": nurse,
  2640. "doctorAdevieInfo": doctorAdevieInfo,
  2641. "total": total,
  2642. "startNuse": startNuse,
  2643. "DoctorName": DoctorName,
  2644. "assessmentAfterDislysis": assessmentAfterDislysis,
  2645. "predialysName": predialysName,
  2646. "FinishNuse": FinishNuse,
  2647. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  2648. "dialysiscount": dialysiscount,
  2649. "last_order": lastOrder,
  2650. "project_config": project_config,
  2651. "projects": projects,
  2652. })
  2653. }
  2654. if config.IsOpen == 0 || config.IsOpen == 2 {
  2655. c.ServeSuccessJSON(map[string]interface{}{
  2656. "xtdate": xtdate,
  2657. "users": adminUser,
  2658. "patientInfo": patientInfo,
  2659. "PredialysisEvaluation": PredialysisEvaluation,
  2660. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2661. "dialysisPrescription": dialysisPrescription,
  2662. "advices": DoctorAdvice,
  2663. "monitors": Record,
  2664. "summary": TreatmentSummary,
  2665. "receiverTreatmentAccess": receiverTreatmentAccess,
  2666. "dialysisOrder": dialysisOrder,
  2667. "operators": operators,
  2668. "org_template_info": templateInfo,
  2669. "check": check,
  2670. "schedule": schedule,
  2671. "dialysisway": dialysisway,
  2672. "order": order,
  2673. "doctorAdvice": doctorAdvice,
  2674. "doctor": doctor,
  2675. "nurse": nurse,
  2676. "doctorAdevieInfo": doctorAdevieInfo,
  2677. "total": total,
  2678. "startNuse": startNuse,
  2679. "DoctorName": DoctorName,
  2680. "assessmentAfterDislysis": assessmentAfterDislysis,
  2681. "predialysName": predialysName,
  2682. "FinishNuse": FinishNuse,
  2683. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  2684. "dialysiscount": dialysiscount,
  2685. "last_order": lastOrder,
  2686. "project_config": project_config,
  2687. "projects": projects,
  2688. })
  2689. }
  2690. }
  2691. //
  2692. func (c *DialysisApiController) GetLongAdvice() {
  2693. patient_id, _ := c.GetInt64("patient_id")
  2694. adminUserInfo := c.GetAdminUserInfo()
  2695. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2696. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  2697. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  2698. c.ServeSuccessJSON(map[string]interface{}{
  2699. "status": "1",
  2700. })
  2701. return
  2702. } else { //开启推送提醒
  2703. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  2704. var advice_three []*models.DoctorAdvice
  2705. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  2706. recordDateStr := time.Now().Format("2006-01-02")
  2707. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2708. nowtime := recordDate.Unix()
  2709. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  2710. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  2711. for _, advice := range advices {
  2712. if advice.FrequencyType == 3 {
  2713. t := time.Now()
  2714. week := int(t.Weekday())
  2715. switch week {
  2716. case 1:
  2717. if strings.Index(advice.WeekDay, "周一") == -1 {
  2718. advice_three = append(advice_three, advice)
  2719. }
  2720. break
  2721. case 2:
  2722. if strings.Index(advice.WeekDay, "周二") == -1 {
  2723. advice_three = append(advice_three, advice)
  2724. }
  2725. break
  2726. case 3:
  2727. if strings.Index(advice.WeekDay, "周三") == -1 {
  2728. advice_three = append(advice_three, advice)
  2729. }
  2730. break
  2731. case 4:
  2732. if strings.Index(advice.WeekDay, "周四") == -1 {
  2733. advice_three = append(advice_three, advice)
  2734. }
  2735. break
  2736. case 5:
  2737. if strings.Index(advice.WeekDay, "周五") == -1 {
  2738. advice_three = append(advice_three, advice)
  2739. }
  2740. break
  2741. case 6:
  2742. if strings.Index(advice.WeekDay, "周六") == -1 {
  2743. advice_three = append(advice_three, advice)
  2744. }
  2745. break
  2746. case 0:
  2747. if strings.Index(advice.WeekDay, "周日") == -1 {
  2748. advice_three = append(advice_three, advice)
  2749. }
  2750. break
  2751. }
  2752. }
  2753. }
  2754. for _, advice := range advices_two {
  2755. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  2756. now := p.Unix()
  2757. dayStr := strconv.FormatInt(advice.DayCount, 10)
  2758. dayStr2 := "-" + dayStr
  2759. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  2760. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  2761. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  2762. for _, ad := range advices {
  2763. advice_three = append(advice_three, ad)
  2764. }
  2765. }
  2766. if err == nil {
  2767. c.ServeSuccessJSON(map[string]interface{}{
  2768. "status": "2",
  2769. "advices": advices,
  2770. "advices_two": RemoveRepeatedElement(advice_three),
  2771. "is_open_remind": config.IsOpenRemind,
  2772. })
  2773. }
  2774. }
  2775. }
  2776. func (c *DialysisApiController) GetLongAdviceOne() {
  2777. patient_id, _ := c.GetInt64("patient_id")
  2778. schedule_date := c.GetString("schedule_date")
  2779. adminUserInfo := c.GetAdminUserInfo()
  2780. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2781. timeLayout := "2006-01-02"
  2782. loc, _ := time.LoadLocation("Local")
  2783. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  2784. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  2785. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  2786. c.ServeSuccessJSON(map[string]interface{}{
  2787. "status": "1",
  2788. })
  2789. return
  2790. } else { //开启推送提醒
  2791. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  2792. var advice_three []*models.DoctorAdvice
  2793. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  2794. //recordDateStr := time.Now().Format("2006-01-02")
  2795. //recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2796. //
  2797. //nowtime := recordDate.Unix()
  2798. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  2799. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  2800. fmt.Println("advice23323232233232233223232332232323322323wodee", theTime.Unix())
  2801. for _, advice := range advices {
  2802. if advice.FrequencyType == 3 {
  2803. t := time.Now()
  2804. week := int(t.Weekday())
  2805. switch week {
  2806. case 1:
  2807. if strings.Index(advice.WeekDay, "周一") == -1 {
  2808. advice_three = append(advice_three, advice)
  2809. }
  2810. break
  2811. case 2:
  2812. if strings.Index(advice.WeekDay, "周二") == -1 {
  2813. advice_three = append(advice_three, advice)
  2814. }
  2815. break
  2816. case 3:
  2817. if strings.Index(advice.WeekDay, "周三") == -1 {
  2818. advice_three = append(advice_three, advice)
  2819. }
  2820. break
  2821. case 4:
  2822. if strings.Index(advice.WeekDay, "周四") == -1 {
  2823. advice_three = append(advice_three, advice)
  2824. }
  2825. break
  2826. case 5:
  2827. if strings.Index(advice.WeekDay, "周五") == -1 {
  2828. advice_three = append(advice_three, advice)
  2829. }
  2830. break
  2831. case 6:
  2832. if strings.Index(advice.WeekDay, "周六") == -1 {
  2833. advice_three = append(advice_three, advice)
  2834. }
  2835. break
  2836. case 0:
  2837. if strings.Index(advice.WeekDay, "周日") == -1 {
  2838. advice_three = append(advice_three, advice)
  2839. }
  2840. break
  2841. }
  2842. }
  2843. }
  2844. for _, advice := range advices_two {
  2845. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  2846. now := p.Unix()
  2847. dayStr := strconv.FormatInt(advice.DayCount, 10)
  2848. dayStr2 := "-" + dayStr
  2849. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  2850. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  2851. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  2852. for _, ad := range advices {
  2853. advice_three = append(advice_three, ad)
  2854. }
  2855. }
  2856. if err == nil {
  2857. c.ServeSuccessJSON(map[string]interface{}{
  2858. "status": "2",
  2859. "advices": advices,
  2860. "advices_two": RemoveRepeatedElement(advice_three),
  2861. "is_open_remind": config.IsOpenRemind,
  2862. })
  2863. }
  2864. }
  2865. }
  2866. func (c *DialysisApiController) GetLongAdviceTwo() {
  2867. patient_id, _ := c.GetInt64("patient_id")
  2868. schedule_date, _ := c.GetInt64("schedule_date")
  2869. adminUserInfo := c.GetAdminUserInfo()
  2870. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2871. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  2872. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  2873. c.ServeSuccessJSON(map[string]interface{}{
  2874. "status": "1",
  2875. })
  2876. return
  2877. } else { //开启推送提醒
  2878. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  2879. var advice_three []*models.DoctorAdvice
  2880. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  2881. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  2882. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  2883. fmt.Println("advice23323232233232233223232332232323322323wodee", schedule_date)
  2884. for _, advice := range advices {
  2885. if advice.FrequencyType == 3 {
  2886. t := time.Now()
  2887. week := int(t.Weekday())
  2888. switch week {
  2889. case 1:
  2890. if strings.Index(advice.WeekDay, "周一") == -1 {
  2891. advice_three = append(advice_three, advice)
  2892. }
  2893. break
  2894. case 2:
  2895. if strings.Index(advice.WeekDay, "周二") == -1 {
  2896. advice_three = append(advice_three, advice)
  2897. }
  2898. break
  2899. case 3:
  2900. if strings.Index(advice.WeekDay, "周三") == -1 {
  2901. advice_three = append(advice_three, advice)
  2902. }
  2903. break
  2904. case 4:
  2905. if strings.Index(advice.WeekDay, "周四") == -1 {
  2906. advice_three = append(advice_three, advice)
  2907. }
  2908. break
  2909. case 5:
  2910. if strings.Index(advice.WeekDay, "周五") == -1 {
  2911. advice_three = append(advice_three, advice)
  2912. }
  2913. break
  2914. case 6:
  2915. if strings.Index(advice.WeekDay, "周六") == -1 {
  2916. advice_three = append(advice_three, advice)
  2917. }
  2918. break
  2919. case 0:
  2920. if strings.Index(advice.WeekDay, "周日") == -1 {
  2921. advice_three = append(advice_three, advice)
  2922. }
  2923. break
  2924. }
  2925. }
  2926. }
  2927. for _, advice := range advices_two {
  2928. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  2929. now := p.Unix()
  2930. dayStr := strconv.FormatInt(advice.DayCount, 10)
  2931. dayStr2 := "-" + dayStr
  2932. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  2933. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  2934. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  2935. for _, ad := range advices {
  2936. advice_three = append(advice_three, ad)
  2937. }
  2938. }
  2939. if err == nil {
  2940. c.ServeSuccessJSON(map[string]interface{}{
  2941. "status": "2",
  2942. "advices": advices,
  2943. "advices_two": RemoveRepeatedElement(advice_three),
  2944. "is_open_remind": config.IsOpenRemind,
  2945. })
  2946. }
  2947. }
  2948. }
  2949. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  2950. newArr = make([]*models.DoctorAdvice, 0)
  2951. for i := 0; i < len(arr); i++ {
  2952. repeat := false
  2953. for j := i + 1; j < len(arr); j++ {
  2954. if arr[i].ID == arr[j].ID {
  2955. repeat = true
  2956. break
  2957. }
  2958. }
  2959. if !repeat {
  2960. newArr = append(newArr, arr[i])
  2961. }
  2962. }
  2963. return
  2964. }
  2965. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  2966. patient, _ := c.GetInt64("id", 0)
  2967. groupNo, _ := c.GetInt64("groupno", 0)
  2968. if patient <= 0 {
  2969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2970. return
  2971. }
  2972. adminUserInfo := c.GetAdminUserInfo()
  2973. dataBody := make(map[string]interface{}, 0)
  2974. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2975. if err != nil {
  2976. utils.ErrorLog(err.Error())
  2977. return
  2978. }
  2979. utils.ErrorLog("%v", dataBody)
  2980. timeLayout := "2006-01-02 15:04"
  2981. loc, _ := time.LoadLocation("Local")
  2982. timeLayout2 := "2006-01-02"
  2983. loc2, _ := time.LoadLocation("Local")
  2984. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2985. utils.ErrorLog("advice_type")
  2986. return
  2987. }
  2988. adviceType := int64(2)
  2989. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2990. utils.ErrorLog("advice_date")
  2991. return
  2992. }
  2993. adviceDate, _ := dataBody["advice_date"].(string)
  2994. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  2995. AdviceDate := theTime.Unix()
  2996. RecordDate := theTime.Unix()
  2997. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2998. utils.ErrorLog("start_time")
  2999. return
  3000. }
  3001. startTime, _ := dataBody["start_time"].(string)
  3002. if len(startTime) == 0 {
  3003. utils.ErrorLog("len(start_time) == 0")
  3004. return
  3005. }
  3006. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  3007. if err != nil {
  3008. utils.ErrorLog(err.Error())
  3009. return
  3010. }
  3011. StartTime := theTimeUnix.Unix()
  3012. fmt.Println("startTIME", StartTime)
  3013. Remark := ""
  3014. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3015. remark, _ := dataBody["remark"].(string)
  3016. Remark = remark
  3017. }
  3018. var advices []*models.GroupAdvice
  3019. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  3020. utils.ErrorLog("advices")
  3021. return
  3022. }
  3023. adviceNames := dataBody["advices"].([]interface{})
  3024. for _, adviceNameMap := range adviceNames {
  3025. adviceNameM := adviceNameMap.(map[string]interface{})
  3026. var advice models.GroupAdvice
  3027. advice.Remark = Remark
  3028. advice.AdviceType = adviceType
  3029. advice.StartTime = StartTime
  3030. advice.AdviceDate = AdviceDate
  3031. advice.RecordDate = RecordDate
  3032. advice.Status = 1
  3033. advice.CreatedTime = time.Now().Unix()
  3034. advice.UpdatedTime = time.Now().Unix()
  3035. advice.StopState = 2
  3036. advice.ExecutionState = 2
  3037. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3038. advice.PatientId = patient
  3039. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3040. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  3041. utils.ErrorLog("advice_name")
  3042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3043. return
  3044. }
  3045. adviceName, _ := adviceNameM["advice_name"].(string)
  3046. if len(adviceName) == 0 {
  3047. utils.ErrorLog("len(advice_name) == 0")
  3048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3049. return
  3050. }
  3051. advice.AdviceName = adviceName
  3052. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  3053. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  3054. advice.DrugSpec = drugSpec
  3055. }
  3056. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  3057. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  3058. advice.AdviceDesc = adviceDesc
  3059. }
  3060. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  3061. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  3062. advice.DrugSpecUnit = drugSpecUnit
  3063. }
  3064. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  3065. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  3066. // advice.SingleDose = singleDose
  3067. //}
  3068. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  3069. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3070. advice.SingleDose = adviceNameM["single_dose"].(float64)
  3071. }
  3072. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  3073. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  3074. advice.SingleDoseUnit = singleDoseUnit
  3075. }
  3076. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  3077. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  3078. // advice.PrescribingNumber = prescribingNumber
  3079. //}
  3080. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  3081. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  3082. }
  3083. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  3084. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  3085. advice.PrescribingNumberUnit = prescribingNumberUnit
  3086. }
  3087. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  3088. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  3089. advice.DeliveryWay = deliveryWay
  3090. }
  3091. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3092. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3093. advice.ExecutionFrequency = executionFrequency
  3094. }
  3095. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  3096. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  3097. advice.FrequencyType = frequency_type
  3098. }
  3099. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  3100. day_count := int64(adviceNameM["day_count"].(float64))
  3101. advice.DayCount = day_count
  3102. }
  3103. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  3104. way := int64(adviceNameM["way"].(float64))
  3105. advice.Way = way
  3106. }
  3107. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  3108. drug_id := int64(adviceNameM["drug_id"].(float64))
  3109. advice.DrugId = drug_id
  3110. }
  3111. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  3112. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  3113. advice.DrugNameId = drug_name_id
  3114. }
  3115. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  3116. week_day, _ := adviceNameM["week_day"].(string)
  3117. advice.WeekDay = week_day
  3118. }
  3119. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  3120. template_id, _ := adviceNameM["template_id"].(string)
  3121. advice.TemplateId = template_id
  3122. }
  3123. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3124. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3125. advice.ExecutionFrequency = executionFrequency
  3126. }
  3127. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  3128. children := adviceNameM["child"].([]interface{})
  3129. if len(children) > 0 {
  3130. for _, childrenMap := range children {
  3131. childMap := childrenMap.(map[string]interface{})
  3132. var child models.GroupAdvice
  3133. child.Remark = Remark
  3134. child.AdviceType = adviceType
  3135. child.StartTime = StartTime
  3136. child.AdviceDate = AdviceDate
  3137. child.RecordDate = RecordDate
  3138. child.Status = 1
  3139. child.CreatedTime = time.Now().Unix()
  3140. child.UpdatedTime = time.Now().Unix()
  3141. child.StopState = 2
  3142. child.ExecutionState = 2
  3143. child.UserOrgId = adminUserInfo.CurrentOrgId
  3144. child.PatientId = patient
  3145. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  3146. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  3147. utils.ErrorLog("child advice_name")
  3148. return
  3149. }
  3150. childAdviceName, _ := childMap["advice_name"].(string)
  3151. if len(childAdviceName) == 0 {
  3152. utils.ErrorLog("len(child advice_name) == 0")
  3153. return
  3154. }
  3155. child.AdviceName = childAdviceName
  3156. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  3157. childAdviceDesc, _ := childMap["advice_desc"].(string)
  3158. child.AdviceDesc = childAdviceDesc
  3159. }
  3160. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  3161. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  3162. child.DrugSpec = childDrugSpec
  3163. }
  3164. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  3165. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  3166. child.DrugSpecUnit = childDrugSpecUnit
  3167. }
  3168. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  3169. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3170. child.SingleDose = childSingleDose
  3171. }
  3172. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  3173. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3174. child.SingleDose = childMap["single_dose"].(float64)
  3175. }
  3176. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  3177. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3178. child.Remark = childMap["remark"].(string)
  3179. }
  3180. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  3181. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3182. child.DrugId = int64(childMap["drug_id"].(float64))
  3183. }
  3184. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  3185. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  3186. child.SingleDoseUnit = childSingleDoseUnit
  3187. }
  3188. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  3189. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  3190. child.PrescribingNumber = childPrescribingNumber
  3191. }
  3192. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  3193. //childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  3194. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  3195. }
  3196. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  3197. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  3198. child.PrescribingNumberUnit = childPrescribingNumberUnit
  3199. }
  3200. child.DeliveryWay = advice.DeliveryWay
  3201. child.ExecutionFrequency = advice.ExecutionFrequency
  3202. advice.Children = append(advice.Children, &child)
  3203. }
  3204. }
  3205. }
  3206. advices = append(advices, &advice)
  3207. }
  3208. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  3209. redis := service.RedisClient()
  3210. formatAdviceDate := theTime.Format("2006-01-02")
  3211. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3212. redis.Set(key, "", time.Second)
  3213. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  3214. redis.Set(keyOne, "", time.Second)
  3215. keyFour := "scheduals_" + formatAdviceDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3216. redis.Set(keyFour, "", time.Second)
  3217. defer redis.Close()
  3218. if err != nil {
  3219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3220. return
  3221. }
  3222. c.ServeSuccessJSON(map[string]interface{}{
  3223. "msg": "ok",
  3224. "advices": list,
  3225. })
  3226. return
  3227. }
  3228. func (c *DialysisApiController) GetSolution() {
  3229. patient_id, _ := c.GetInt64("patient_id")
  3230. mode_id, _ := c.GetInt64("mode_id")
  3231. adminUserInfo := c.GetAdminUserInfo()
  3232. solution, err := service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  3233. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  3234. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, mode_id)
  3235. if err != nil {
  3236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3237. return
  3238. }
  3239. c.ServeSuccessJSON(map[string]interface{}{
  3240. "solution": solution,
  3241. "prescription": prescription,
  3242. "system_prescription": system_prescription,
  3243. })
  3244. }
  3245. func (c *DialysisApiController) GetSchedule() {
  3246. schedual_type, _ := c.GetInt64("schedual_type")
  3247. adminUserInfo := c.GetAdminUserInfo()
  3248. //timeLayout := "2006-01-02 15:04:05"
  3249. //
  3250. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  3251. //loc, _ := time.LoadLocation("Local")
  3252. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  3253. //scheduleTime := theStartTime.Unix()
  3254. scheduleTime, _ := c.GetInt64("record_date")
  3255. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  3256. c.ServeSuccessJSON(map[string]interface{}{
  3257. "number": deviceNumber,
  3258. })
  3259. }
  3260. func (this *DialysisApiController) GetTodayMonitor() {
  3261. thisTime := time.Now()
  3262. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3263. timeLayout := "2006-01-02 15:04:05"
  3264. loc, _ := time.LoadLocation("Local")
  3265. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3266. theAssessmentDateTime := theStartTime.Unix()
  3267. patientID, _ := this.GetInt64("patient_id")
  3268. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3269. adminInfo := this.GetAdminUserInfo()
  3270. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  3271. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  3272. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  3273. var ultrafiltration_rate float64
  3274. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  3275. //针对福建医师汇 获取透前评估预增脱水量
  3276. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  3277. fmt.Println("透前评估数据", evaluation)
  3278. if prescription.ID > 0 {
  3279. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3280. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3281. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  3282. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3283. record.UltrafiltrationRate = ultrafiltration_rate
  3284. }
  3285. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10121 {
  3286. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3287. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3288. record.UltrafiltrationRate = ultrafiltration_rate
  3289. }
  3290. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10234 {
  3291. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3292. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3293. record.UltrafiltrationRate = ultrafiltration_rate
  3294. }
  3295. if template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.CurrentOrgId == 9538
  3296. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3297. record.UltrafiltrationRate = ultrafiltration_rate
  3298. }
  3299. if template.TemplateId == 41 { //adminInfo.CurrentOrgId == 9538
  3300. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3301. record.UltrafiltrationRate = ultrafiltration_rate
  3302. }
  3303. if template.TemplateId == 43 { //adminInfo.CurrentOrgId == 9538
  3304. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3305. record.UltrafiltrationRate = ultrafiltration_rate
  3306. }
  3307. if template.TemplateId == 46 || template.TemplateId == 54 { //adminInfo.CurrentOrgId == 9538
  3308. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3309. record.UltrafiltrationRate = ultrafiltration_rate
  3310. }
  3311. if template.TemplateId == 47 { //adminInfo.CurrentOrgId == 9538
  3312. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3313. record.UltrafiltrationRate = ultrafiltration_rate
  3314. }
  3315. // 只针对方济医院
  3316. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  3317. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3318. ultrafiltration_rate = value
  3319. record.UltrafiltrationRate = ultrafiltration_rate
  3320. }
  3321. }
  3322. }
  3323. // record.UltrafiltrationRate = ultrafiltration_rate
  3324. record.UltrafiltrationVolume = 0
  3325. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  3326. if ultrafiltration_rate > 0 {
  3327. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3328. record.UltrafiltrationVolume = value
  3329. }
  3330. }
  3331. 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 {
  3332. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  3333. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3334. record.UltrafiltrationVolume = ultrafiltration_volume
  3335. }
  3336. }
  3337. if template.TemplateId == 47 || template.TemplateId == 54 {
  3338. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3339. }
  3340. this.ServeSuccessJSON(map[string]interface{}{
  3341. "monitor": record,
  3342. })
  3343. }
  3344. func (c *DialysisApiController) UploadDryWeight() {
  3345. patient_id, _ := c.GetInt64("id")
  3346. dry_weight, _ := c.GetFloat("dry_weight")
  3347. doctor_id, _ := c.GetInt64("doctor_id")
  3348. remark := c.GetString("remark")
  3349. adminUserInfo := c.GetAdminUserInfo()
  3350. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  3351. fmt.Println(err)
  3352. if err == gorm.ErrRecordNotFound {
  3353. dryWeight := &models.SgjPatientDryweight{
  3354. PatientId: patient_id,
  3355. DryWeight: dry_weight,
  3356. Remakes: remark,
  3357. Ctime: time.Now().Unix(),
  3358. Mtime: time.Now().Unix(),
  3359. Creator: doctor_id,
  3360. Status: 1,
  3361. UserOrgId: adminUserInfo.CurrentOrgId,
  3362. AdjustedValue: "/",
  3363. UserId: adminUserInfo.AdminUser.Id,
  3364. }
  3365. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3366. loc, _ := time.LoadLocation("Local")
  3367. nowTime := time.Now()
  3368. nowDay := nowTime.Format("2006-01-02")
  3369. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3370. redis := service.RedisClient()
  3371. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  3372. redis.Set(keyOne, "", time.Second)
  3373. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3374. redis.Set(key, "", time.Second)
  3375. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3376. redis.Set(keyTwo, "", time.Second)
  3377. redis.Close()
  3378. if createErr == nil {
  3379. c.ServeSuccessJSON(map[string]interface{}{
  3380. "msg": "提交成功",
  3381. "weight": dryWeight,
  3382. })
  3383. }
  3384. } else {
  3385. dryWeight := &models.SgjPatientDryweight{
  3386. PatientId: patient_id,
  3387. DryWeight: dry_weight,
  3388. Remakes: remark,
  3389. Ctime: time.Now().Unix(),
  3390. Mtime: time.Now().Unix(),
  3391. Creator: doctor_id,
  3392. Status: 1,
  3393. UserOrgId: adminUserInfo.CurrentOrgId,
  3394. AdjustedValue: "/",
  3395. UserId: adminUserInfo.AdminUser.Id,
  3396. }
  3397. var value float64
  3398. value = dry_weight - weightAdjust.DryWeight
  3399. fmt.Println(value)
  3400. if value < 0 {
  3401. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  3402. } else if value == 0 {
  3403. dryWeight.AdjustedValue = "/"
  3404. } else if value > 0 {
  3405. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  3406. }
  3407. fmt.Println(value)
  3408. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3409. loc, _ := time.LoadLocation("Local")
  3410. nowTime := time.Now()
  3411. nowDay := nowTime.Format("2006-01-02")
  3412. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3413. redis := service.RedisClient()
  3414. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  3415. redis.Set(keyOne, "", time.Second)
  3416. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3417. redis.Set(key, "", time.Second)
  3418. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3419. redis.Set(keyTwo, "", time.Second)
  3420. redis.Close()
  3421. if createErr == nil {
  3422. c.ServeSuccessJSON(map[string]interface{}{
  3423. "msg": "提交成功",
  3424. "weight": dryWeight,
  3425. })
  3426. }
  3427. }
  3428. }
  3429. func (this *DialysisApiController) GetFuncPurview() {
  3430. adminUserInfo := this.GetAdminUserInfo()
  3431. user_id := adminUserInfo.AdminUser.Id
  3432. app_id := adminUserInfo.CurrentAppId
  3433. org_id := adminUserInfo.CurrentOrgId
  3434. create_url := this.GetString("create_url")
  3435. modify_url := this.GetString("modify_url")
  3436. modify_other_url := this.GetString("modify_other_url")
  3437. del_url := this.GetString("del_url")
  3438. del_other_url := this.GetString("del_other_url")
  3439. exce_url := this.GetString("exce_url")
  3440. check_url := this.GetString("check_url")
  3441. modify_exce_url := this.GetString("modify_exce_url")
  3442. module, _ := this.GetInt64("module", 0)
  3443. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  3444. var is_has_create bool
  3445. var is_has_modify bool
  3446. var is_has_modify_other bool
  3447. var is_has_del bool
  3448. var is_has_del_other bool
  3449. var is_has_exce bool
  3450. var is_has_check bool
  3451. var is_has_modify_exce bool
  3452. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  3453. if adminUserInfo.AdminUser.Id != org.Creator {
  3454. if app_role != nil {
  3455. if len(app_role.RoleIds) > 0 {
  3456. roles := strings.Split(app_role.RoleIds, ",")
  3457. var userRolePurviews string
  3458. for _, item := range roles {
  3459. role_id, _ := strconv.ParseInt(item, 10, 64)
  3460. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  3461. if len(userRolePurviews) == 0 {
  3462. userRolePurviews = purviews
  3463. } else {
  3464. userRolePurviews = userRolePurviews + "," + purviews
  3465. }
  3466. }
  3467. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  3468. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  3469. for _, item := range funcPurviews {
  3470. //for _, url := range strings.Split(item.Urlfor,","){
  3471. if strings.Split(item.Urlfor, ",")[1] == create_url {
  3472. is_has_create = true
  3473. }
  3474. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  3475. is_has_modify = true
  3476. }
  3477. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  3478. is_has_modify_other = true
  3479. }
  3480. if strings.Split(item.Urlfor, ",")[1] == del_url {
  3481. is_has_del = true
  3482. }
  3483. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  3484. is_has_del_other = true
  3485. }
  3486. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  3487. is_has_exce = true
  3488. }
  3489. if strings.Split(item.Urlfor, ",")[1] == check_url {
  3490. is_has_check = true
  3491. }
  3492. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  3493. is_has_modify_exce = true
  3494. }
  3495. }
  3496. } else {
  3497. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  3498. return
  3499. }
  3500. this.ServeSuccessJSON(map[string]interface{}{
  3501. "is_has_create": is_has_create,
  3502. "is_has_modify": is_has_modify,
  3503. "is_has_modify_other": is_has_modify_other,
  3504. "is_has_del": is_has_del,
  3505. "is_has_del_other": is_has_del_other,
  3506. "is_has_exce": is_has_exce,
  3507. "is_has_check": is_has_check,
  3508. "is_has_modify_exce": is_has_modify_exce,
  3509. "module": module,
  3510. })
  3511. } else {
  3512. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  3513. return
  3514. }
  3515. } else {
  3516. this.ServeSuccessJSON(map[string]interface{}{
  3517. "is_has_create": true,
  3518. "is_has_modify": true,
  3519. "is_has_modify_other": true,
  3520. "is_has_del": true,
  3521. "is_has_del_other": true,
  3522. "is_has_exce": true,
  3523. "is_has_check": true,
  3524. "is_has_modify_exce": true,
  3525. "module": true,
  3526. })
  3527. }
  3528. }
  3529. func (this *DialysisApiController) GetOrderDoctorAdvice() {
  3530. patient_id, _ := this.GetInt64("patient_id", 0)
  3531. advice_date, _ := this.GetInt64("advice_date")
  3532. adminUserInfo := this.GetAdminUserInfo()
  3533. doctorAdvice, _ := service.GetBloodDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  3534. hisDoctorAdvice, _ := service.GetHisDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  3535. this.ServeSuccessJSON(map[string]interface{}{
  3536. "doctorAdvice": doctorAdvice,
  3537. "hisDoctorAdvice": hisDoctorAdvice,
  3538. })
  3539. }
  3540. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  3541. change_type, _ := this.GetInt64("type", 0)
  3542. record_date := this.GetString("record_time")
  3543. patient_id, _ := this.GetInt64("patient_id", 0)
  3544. timeLayout := "2006-01-02"
  3545. loc, _ := time.LoadLocation("Local")
  3546. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3547. record_time := theAdviceRecordTime.Unix()
  3548. adminUserInfo := this.GetAdminUserInfo()
  3549. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  3550. if err == nil {
  3551. if len(advices) == 0 {
  3552. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  3553. return
  3554. } else {
  3555. this.ServeSuccessJSON(map[string]interface{}{
  3556. "advices": advices,
  3557. "schedule": sch,
  3558. })
  3559. return
  3560. }
  3561. } else {
  3562. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3563. return
  3564. }
  3565. }
  3566. func (c *DialysisApiController) GetDialysisGoods() {
  3567. schedualDate := c.GetString("schedule_date")
  3568. schedule_type, _ := c.GetInt64("schedule_type")
  3569. partition_id, _ := c.GetInt64("partition_id")
  3570. page, _ := c.GetInt("page")
  3571. limit, _ := c.GetInt("limit")
  3572. keywords := c.GetString("keywords")
  3573. patient_id, _ := c.GetInt64("patient_id")
  3574. good_type, _ := c.GetInt64("good_type")
  3575. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  3576. if parseDateErr != nil && len(schedualDate) != 0 {
  3577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3578. return
  3579. }
  3580. schedualEndDate := int64(0)
  3581. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  3582. if parseDateErr != nil && len(schedualDate) != 0 {
  3583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3584. return
  3585. }
  3586. schedualEndDate = endDate.Unix()
  3587. adminUser := c.GetAdminUserInfo()
  3588. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  3589. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  3590. if err == gorm.ErrRecordNotFound {
  3591. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  3592. var ids []int64
  3593. for _, item := range list {
  3594. ids = append(ids, item.PatientId)
  3595. }
  3596. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  3597. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3598. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  3599. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  3600. item.LastAutomaticReduceDetail = goodUser
  3601. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3602. }
  3603. c.ServeSuccessJSON(map[string]interface{}{
  3604. "dialysis_goods": dialysisGoods,
  3605. "good_type": goodTypes,
  3606. "total": total,
  3607. })
  3608. return
  3609. } else if err == nil {
  3610. //获取当天排班的每个患者的库存使用情况
  3611. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  3612. var ids []int64
  3613. for _, item := range list {
  3614. ids = append(ids, item.PatientId)
  3615. }
  3616. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  3617. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3618. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  3619. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  3620. fmt.Println(goodUser)
  3621. fmt.Println(lastGoodUserDetial)
  3622. item.LastAutomaticReduceDetail = goodUser
  3623. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3624. }
  3625. if err == nil {
  3626. c.ServeSuccessJSON(map[string]interface{}{
  3627. "dialysis_goods": dialysisGoods,
  3628. "good_type": goodTypes,
  3629. "total": total,
  3630. })
  3631. return
  3632. } else {
  3633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3634. return
  3635. }
  3636. } else if err != nil {
  3637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3638. return
  3639. }
  3640. }
  3641. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  3642. start_time := c.GetString("start_time")
  3643. end_time := c.GetString("end_time")
  3644. timeLayout := "2006-01-02"
  3645. loc, _ := time.LoadLocation("Local")
  3646. var theStartTime int64
  3647. if len(start_time) > 0 {
  3648. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3649. if err != nil {
  3650. utils.ErrorLog(err.Error())
  3651. }
  3652. theStartTime = theTime.Unix()
  3653. }
  3654. var theEndtTime int64
  3655. if len(end_time) > 0 {
  3656. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3657. if err != nil {
  3658. utils.ErrorLog(err.Error())
  3659. }
  3660. theEndtTime = theTime.Unix()
  3661. }
  3662. adminUser := c.GetAdminUserInfo()
  3663. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  3664. if err == nil {
  3665. c.ServeSuccessJSON(map[string]interface{}{
  3666. "stock_out": outInfo,
  3667. })
  3668. return
  3669. } else {
  3670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3671. return
  3672. }
  3673. }
  3674. func (c *DialysisApiController) GetRoleList() {
  3675. orgId := c.GetAdminUserInfo().CurrentOrgId
  3676. admin_user_id, _ := c.GetInt64("admin_user_id")
  3677. list, err := service.GetRoleList(orgId, admin_user_id)
  3678. if err == nil {
  3679. c.ServeSuccessJSON(map[string]interface{}{
  3680. "adminRole": list,
  3681. })
  3682. return
  3683. } else {
  3684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3685. return
  3686. }
  3687. }
  3688. func (c *DialysisApiController) GetInitPrintData() {
  3689. patient_id, _ := c.GetInt64("patient_id")
  3690. record_date, _ := c.GetInt64("record_date")
  3691. orgId := c.GetAdminUserInfo().CurrentOrgId
  3692. list, err := service.GetInitPrintData(patient_id, record_date, orgId)
  3693. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, record_date, orgId)
  3694. if err == nil {
  3695. c.ServeSuccessJSON(map[string]interface{}{
  3696. "list": list,
  3697. "assessmentAfterDislysis": assessmentAfterDislysis,
  3698. })
  3699. return
  3700. } else {
  3701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3702. return
  3703. }
  3704. }
  3705. func (c *DialysisApiController) GetInitPrintDataOne() {
  3706. patient_id, _ := c.GetInt64("patient_id")
  3707. start_time := c.GetString("record_date")
  3708. timeLayout := "2006-01-02"
  3709. loc, _ := time.LoadLocation("Local")
  3710. var theStartTime int64
  3711. if len(start_time) > 0 {
  3712. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3713. if err != nil {
  3714. utils.ErrorLog(err.Error())
  3715. }
  3716. theStartTime = theTime.Unix()
  3717. }
  3718. orgId := c.GetAdminUserInfo().CurrentOrgId
  3719. list, err := service.GetInitPrintData(patient_id, theStartTime, orgId)
  3720. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, theStartTime, orgId)
  3721. if err == nil {
  3722. c.ServeSuccessJSON(map[string]interface{}{
  3723. "list": list,
  3724. "assessmentAfterDislysis": assessmentAfterDislysis,
  3725. })
  3726. return
  3727. } else {
  3728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3729. return
  3730. }
  3731. }
  3732. //新接口
  3733. func (this *DialysisApiController) GetPatientDialysisSolutionGroupList() {
  3734. keyword := this.GetString("keywords")
  3735. limit, _ := this.GetInt64("limit")
  3736. page, _ := this.GetInt64("page")
  3737. partition_id, _ := this.GetInt64("partition_id")
  3738. schedule_type, _ := this.GetInt64("schedule_type")
  3739. start_time := this.GetString("schedule_date")
  3740. timeLayout := "2006-01-02"
  3741. loc, _ := time.LoadLocation("Local")
  3742. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3743. orgId := this.GetAdminUserInfo().CurrentOrgId
  3744. list, total, err := service.GetPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId)
  3745. if err == nil {
  3746. this.ServeSuccessJSON(map[string]interface{}{
  3747. "list": list,
  3748. "total": total,
  3749. })
  3750. return
  3751. } else {
  3752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3753. return
  3754. }
  3755. }
  3756. func (this *DialysisApiController) GetDialysisAdviceTemplateList() {
  3757. keyword := this.GetString("keywords")
  3758. limit, _ := this.GetInt64("limit")
  3759. page, _ := this.GetInt64("page")
  3760. partition_id, _ := this.GetInt64("partition_id")
  3761. schedule_type, _ := this.GetInt64("schedule_type")
  3762. start_time := this.GetString("schedule_date")
  3763. timeLayout := "2006-01-02"
  3764. loc, _ := time.LoadLocation("Local")
  3765. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3766. orgId := this.GetAdminUserInfo().CurrentOrgId
  3767. list, total, err := service.GetDialysisAdviceTemplateList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId)
  3768. //获取长期医嘱
  3769. adviceList, _ := service.GetAllLongAdviceList(orgId)
  3770. //获取医嘱模版
  3771. templateList, _ := service.GetAllHisAdviceTemplateList(orgId)
  3772. if err == nil {
  3773. this.ServeSuccessJSON(map[string]interface{}{
  3774. "list": list,
  3775. "total": total,
  3776. "adviceList": adviceList,
  3777. "templateList": templateList,
  3778. })
  3779. return
  3780. } else {
  3781. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3782. return
  3783. }
  3784. }
  3785. func (this *DialysisApiController) SaveDialysisSetting() {
  3786. orgId := this.GetAdminUserInfo().CurrentOrgId
  3787. device_number_set, _ := this.GetInt64("device_number_set")
  3788. device_type_set, _ := this.GetInt64("device_type_set")
  3789. name_set, _ := this.GetInt64("name_set")
  3790. admission_number_set, _ := this.GetInt64("admission_number_set")
  3791. dialysis_no_set, _ := this.GetInt64("dialysis_no_set")
  3792. weight_befor_set, _ := this.GetInt64("weight_befor_set")
  3793. dry_weight_set, _ := this.GetInt64("dry_weight_set")
  3794. blood_pressure_set, _ := this.GetInt64("blood_pressure_set")
  3795. ultrafiltration_volume_set, _ := this.GetInt64("ultrafiltration_volume_set")
  3796. internal_fistula_set, _ := this.GetInt64("internal_fistula_set")
  3797. blood_flow_volume_set, _ := this.GetInt64("blood_flow_volume_set")
  3798. anticoagulant_set, _ := this.GetInt64("anticoagulant_set")
  3799. sealing_fluid_dispose_set, _ := this.GetInt64("sealing_fluid_dispose_set")
  3800. mode_id_set, _ := this.GetInt64("mode_id_set")
  3801. dialysis_time_set, _ := this.GetInt64("dialysis_time_set")
  3802. dialysis_dialyszers_set, _ := this.GetInt64("dialysis_dialyszers_set")
  3803. dialysis_irrigation_set, _ := this.GetInt64("dialysis_irrigation_set")
  3804. gaijiliang_set, _ := this.GetInt64("gaijiliang_set")
  3805. kalium_set, _ := this.GetInt64("kalium_set")
  3806. displace_liqui_value_set, _ := this.GetInt64("displace_liqui_value_set")
  3807. bicarbonate_set, _ := this.GetInt64("bicarbonate_set")
  3808. glucose_set, _ := this.GetInt64("glucose_set")
  3809. dialysisSetting := models.XtDialysisSetting{
  3810. UserOrgId: orgId,
  3811. Status: 1,
  3812. DeviceNumber: device_number_set,
  3813. DeviceType: device_type_set,
  3814. Name: name_set,
  3815. AdmissionNumber: admission_number_set,
  3816. DialysisNo: dialysis_no_set,
  3817. WeightBefor: weight_befor_set,
  3818. DryWeight: dry_weight_set,
  3819. BloodPressure: blood_pressure_set,
  3820. UltrafiltrationVolume: ultrafiltration_volume_set,
  3821. InternalFistula: internal_fistula_set,
  3822. BloodFlowVolume: blood_flow_volume_set,
  3823. Anticoagulant: anticoagulant_set,
  3824. SealingFluidDispose: sealing_fluid_dispose_set,
  3825. ModeId: mode_id_set,
  3826. DialysisTime: dialysis_time_set,
  3827. DialysisDialyszers: dialysis_dialyszers_set,
  3828. DialysisIrrigation: dialysis_irrigation_set,
  3829. Gaijiliang: gaijiliang_set,
  3830. Kalium: kalium_set,
  3831. DisplaceLiquiValue: displace_liqui_value_set,
  3832. Bicarbonate: bicarbonate_set,
  3833. Glucose: glucose_set,
  3834. Ctime: time.Now().Unix(),
  3835. Mtime: time.Now().Unix(),
  3836. }
  3837. err := service.SaveDialysisSetting(dialysisSetting)
  3838. if err == nil {
  3839. this.ServeSuccessJSON(map[string]interface{}{
  3840. "dialysisSetting": dialysisSetting,
  3841. })
  3842. return
  3843. } else {
  3844. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3845. return
  3846. }
  3847. }
  3848. func (this *DialysisApiController) GetDialysisSetting() {
  3849. orgId := this.GetAdminUserInfo().CurrentOrgId
  3850. dialysisSett, _ := service.GetDialysisSetting(orgId)
  3851. this.ServeSuccessJSON(map[string]interface{}{
  3852. "dialysisSett": dialysisSett,
  3853. })
  3854. return
  3855. }
  3856. func (this *DialysisApiController) GetDialysisParameterList() {
  3857. keyword := this.GetString("keywords")
  3858. limit, _ := this.GetInt64("limit")
  3859. page, _ := this.GetInt64("page")
  3860. partition_id, _ := this.GetInt64("partition_id")
  3861. schedule_type, _ := this.GetInt64("schedule_type")
  3862. start_time := this.GetString("schedule_date")
  3863. timeLayout := "2006-01-02"
  3864. loc, _ := time.LoadLocation("Local")
  3865. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3866. orgId := this.GetAdminUserInfo().CurrentOrgId
  3867. list, total, err := service.GetDialysisParameterList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId)
  3868. if err == nil {
  3869. this.ServeSuccessJSON(map[string]interface{}{
  3870. "list": list,
  3871. "total": total,
  3872. })
  3873. return
  3874. } else {
  3875. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3876. return
  3877. }
  3878. }
  3879. func (this *DialysisApiController) GetDialysisGoodTotalCount() {
  3880. orgId := this.GetAdminUserInfo().CurrentOrgId
  3881. schedule_type, _ := this.GetInt64("schedule_type")
  3882. partion_type, _ := this.GetInt64("partion_type")
  3883. start_time := this.GetString("schedule_date")
  3884. timeLayout := "2006-01-02"
  3885. loc, _ := time.LoadLocation("Local")
  3886. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3887. list, err := service.GetDialysisGoodTotalCount(orgId, schedule_type, partion_type, startTime.Unix())
  3888. if err == nil {
  3889. this.ServeSuccessJSON(map[string]interface{}{
  3890. "list": list,
  3891. })
  3892. return
  3893. } else {
  3894. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3895. return
  3896. }
  3897. }