dialysis_api_controller.go 147KB

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