dialysis_api_controller.go 147KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827
  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. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1140. if assessment.ID > 0 {
  1141. if appRole.UserType == 2 || appRole.UserType == 1 {
  1142. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1143. assessment.AssessmentTime = time.Now().Unix()
  1144. } else {
  1145. if assessment.Creater == 0 {
  1146. assessment.Modifier = adminUserInfo.AdminUser.Id
  1147. assessment.Creater = adminUserInfo.AdminUser.Id
  1148. } else {
  1149. assessment.Modifier = adminUserInfo.AdminUser.Id
  1150. }
  1151. }
  1152. assessment.UpdatedTime = time.Now().Unix()
  1153. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  1154. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1155. redis := service.RedisClient()
  1156. //清空key 值
  1157. redis.Set(key, "", time.Second)
  1158. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1159. redis.Set(keyThree, "", time.Second)
  1160. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1161. redis.Set(keyTwo, "", time.Second)
  1162. defer redis.Close()
  1163. } else {
  1164. if appRole.UserType == 2 || appRole.UserType == 1 {
  1165. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1166. assessment.AssessmentTime = time.Now().Unix()
  1167. } else {
  1168. assessment.Creater = adminUserInfo.AdminUser.Id
  1169. }
  1170. assessment.CreatedTime = time.Now().Unix()
  1171. assessment.UpdatedTime = time.Now().Unix()
  1172. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  1173. assessment.PatientId = patient
  1174. assessment.AssessmentDate = recordDate.Unix()
  1175. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  1176. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1177. redis := service.RedisClient()
  1178. //清空key 值
  1179. redis.Set(key, "", time.Second)
  1180. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1181. redis.Set(keyThree, "", time.Second)
  1182. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1183. redis.Set(keyTwo, "", time.Second)
  1184. defer redis.Close()
  1185. }
  1186. if err != nil {
  1187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1188. return
  1189. }
  1190. c.ServeSuccessJSON(map[string]interface{}{
  1191. "AssessmentAfterDislysis": &assessment,
  1192. })
  1193. }
  1194. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  1195. patient, _ := c.GetInt64("patient", 0)
  1196. recordDateStr := c.GetString("record_date")
  1197. if patient <= 0 {
  1198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1199. return
  1200. }
  1201. adminUserInfo := c.GetAdminUserInfo()
  1202. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1203. if patientInfo.ID == 0 {
  1204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1205. return
  1206. }
  1207. if len(recordDateStr) == 0 {
  1208. recordDateStr = time.Now().Format("2006-01-02")
  1209. }
  1210. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1211. if parseDateErr != nil {
  1212. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1214. return
  1215. }
  1216. weight_before, _ := c.GetFloat("weight_before", 0)
  1217. dry_weight, _ := c.GetFloat("dry_weight", 0)
  1218. additional_weight, _ := c.GetFloat("additional_weight", 0)
  1219. temperature, _ := c.GetFloat("temperature", 0)
  1220. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1221. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1222. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1223. last_post_dialysis := c.GetString("last_post_dialysis")
  1224. dialysis_interphase := c.GetString("dialysis_interphase")
  1225. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  1226. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1227. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  1228. bloodAccessPartId := c.GetString("blood_access_part_id")
  1229. internalFistula := c.GetString("internal_fistula")
  1230. internal_fistula_skin := c.GetString("internal_fistula_skin")
  1231. catheter := c.GetString("catheter")
  1232. catheter_bend, _ := c.GetInt("catheter_bend")
  1233. complication := c.GetString("complication")
  1234. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  1235. hemorrhage := c.GetString("hemorrhage")
  1236. hemorrhage_other := c.GetString("hemorrhage_other")
  1237. remark := c.GetString("remark")
  1238. puncture_method := c.GetString("puncture_method")
  1239. dialysis_count := c.GetString("dialysis_count")
  1240. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  1241. emergency_treatment_other := c.GetString("emergency_treatment_other")
  1242. ductus_arantii := c.GetString("ductus_arantii")
  1243. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  1244. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  1245. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  1246. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  1247. puncture_way := c.GetString("puncture_way")
  1248. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  1249. internal_fistula_other := c.GetString("internal_fistula_other")
  1250. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  1251. breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  1252. is_infect, _ := c.GetInt64("is_infect", 0)
  1253. exposed, _ := c.GetFloat("exposed", 0)
  1254. skin := c.GetString("skin")
  1255. skin_other := c.GetString("skin_other")
  1256. infect_other := c.GetString("infect_other")
  1257. ductus_arantii_other := c.GetString("ductus_arantii_other")
  1258. machine_type := c.GetString("machine_type")
  1259. puncture_needle := c.GetString("puncture_needle")
  1260. //humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
  1261. humor_excessive_symptom := c.GetString("humor_excessive_symptom")
  1262. phinholing := c.GetString("pinholing")
  1263. catheter_suture := c.GetString("catheter_suture")
  1264. catheter_suture_other := c.GetString("catheter_suture_other")
  1265. edema := c.GetString("edema")
  1266. urine_volume, _ := c.GetFloat("urine_volume", 0)
  1267. special_treatment := c.GetString("special_treatment")
  1268. catheter_maintenance := c.GetString("catheter_maintenance")
  1269. thrombusType := c.GetString("thromubus_type")
  1270. thrombusInt, _ := strconv.ParseInt(thrombusType, 10, 64)
  1271. thrombus_a := c.GetString("thromubus_a")
  1272. thrombus_av := c.GetString("thrombus_av")
  1273. thrombus_v := c.GetString("thromubus_v")
  1274. dehydration := c.GetString("dehydration")
  1275. pre_dialysis_drugs := c.GetString("pre_dialysis_drugs")
  1276. period, _ := c.GetInt64("period")
  1277. estimated_food_intake := c.GetString("estimated_food_intake")
  1278. blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
  1279. assessmentBeforeDislysis := models.PredialysisEvaluation{
  1280. DialysisCount: dialysis_count,
  1281. EmergencyTreatment: emergency_treatment,
  1282. EmergencyTreatmentOther: emergency_treatment_other,
  1283. DuctusArantii: ductus_arantii,
  1284. VenousCatheterization: venous_catheterization,
  1285. VenousCatheterizationPart: venous_catheterization_part,
  1286. VenousCatheterizationPartOther: venous_catheterization_part_other,
  1287. PunctureWay: puncture_way,
  1288. BloodAccessInternalFistula: blood_access_internal_fistula,
  1289. BloodAccessNoise: blood_access_noise,
  1290. InternalFistulaOther: internal_fistula_other,
  1291. Evaluator: adminUserInfo.AdminUser.Id,
  1292. UserOrgId: adminUserInfo.CurrentOrgId,
  1293. PatientId: patient,
  1294. AssessmentDate: recordDate.Unix(),
  1295. Temperature: temperature,
  1296. PulseFrequency: pulse_frequency,
  1297. SystolicBloodPressure: systolic_blood_pressure,
  1298. DiastolicBloodPressure: diastolic_blood_pressure,
  1299. WeightBefore: weight_before,
  1300. DryWeight: dry_weight,
  1301. AdditionalWeight: additional_weight,
  1302. DialysisInterphase: dialysis_interphase,
  1303. LastPostDialysis: last_post_dialysis,
  1304. SymptomBeforeDialysis: symptom_before_dialysis,
  1305. InternalFistula: internalFistula,
  1306. InternalFistulaSkin: internal_fistula_skin,
  1307. Catheter: catheter,
  1308. CatheterBend: catheter_bend,
  1309. Complication: complication,
  1310. CreatedTime: time.Now().Unix(),
  1311. Status: 1,
  1312. Remark: remark,
  1313. IsHemorrhage: is_hemorrhage,
  1314. Hemorrhage: hemorrhage,
  1315. HemorrhageOther: hemorrhage_other,
  1316. BloodAccessPartId: bloodAccessPartId,
  1317. BloodAccessPartOperaId: bloodAccessPartOperaId,
  1318. PunctureMethod: puncture_method,
  1319. BreathingRate: breathing_rate,
  1320. IsInfect: is_infect,
  1321. Exposed: exposed,
  1322. Skin: skin,
  1323. SkinOther: skin_other,
  1324. InfectOther: infect_other,
  1325. DuctusArantiiOther: ductus_arantii_other,
  1326. MachineType: machine_type,
  1327. PunctureNeedle: puncture_needle,
  1328. HumorExcessiveSymptom: humor_excessive_symptom,
  1329. Phinholing: phinholing,
  1330. CatheterSuture: catheter_suture,
  1331. CatheterSutureOther: catheter_suture_other,
  1332. Edema: edema,
  1333. UrineVolume: urine_volume,
  1334. SpecialTreatment: special_treatment,
  1335. CatheterMaintenance: catheter_maintenance,
  1336. ThromubusType: thrombusInt,
  1337. ThrombusAv: thrombus_av,
  1338. ThromubusA: thrombus_a,
  1339. ThromubusV: thrombus_v,
  1340. Dehydration: dehydration,
  1341. PreDialysisDrugs: pre_dialysis_drugs,
  1342. Period: period,
  1343. EstimatedFoodIntake: estimated_food_intake,
  1344. BloodPressureDuringDialysis: blood_pressure_during_dialysis,
  1345. }
  1346. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1347. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1348. if evaluation.ID == 0 { //新增
  1349. if appRole.UserType == 2 || appRole.UserType == 1 {
  1350. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1351. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1352. } else {
  1353. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  1354. }
  1355. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  1356. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1357. redis := service.RedisClient()
  1358. //清空key 值
  1359. redis.Set(key, "", time.Second)
  1360. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1361. redis.Set(keyOne, "", time.Second)
  1362. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1363. redis.Set(keyTwo, "", time.Second)
  1364. defer redis.Close()
  1365. if err == nil {
  1366. c.ServeSuccessJSON(map[string]interface{}{
  1367. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  1368. })
  1369. } else {
  1370. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1372. }
  1373. } else { //修改
  1374. //if appRole.UserType == 3 {
  1375. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  1376. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1377. // if getPermissionErr != nil {
  1378. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1379. // return
  1380. // } else if headNursePermission == nil {
  1381. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1382. // return
  1383. // }
  1384. // }
  1385. //}
  1386. if appRole.UserType == 2 || appRole.UserType == 1 {
  1387. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1388. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1389. } else {
  1390. if evaluation.Creater == 0 {
  1391. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  1392. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  1393. } else {
  1394. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  1395. }
  1396. }
  1397. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  1398. assessmentBeforeDislysis.ID = evaluation.ID
  1399. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  1400. //
  1401. //新增逻辑
  1402. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  1403. var dewater_amount float64
  1404. dewater_amount = 0
  1405. if evaluation.DryWeight > 0 {
  1406. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  1407. if templateInfo.TemplateId == 17 || templateInfo.TemplateId == 22 || templateInfo.TemplateId == 21 || templateInfo.TemplateId == 34 {
  1408. dewater_amount = dewater_amount * 1000
  1409. }
  1410. if dewater_amount <= 0 {
  1411. dewater_amount = 0
  1412. }
  1413. } else {
  1414. dewater_amount = 0
  1415. }
  1416. // 计算透析处方的相关超滤量
  1417. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1418. var lastDialysisPrescribe *models.DialysisPrescription
  1419. var dialysisSolution *models.DialysisSolution
  1420. var dialysisPrescribe *models.DialysisPrescription
  1421. var mode_id int64
  1422. if schedual != nil {
  1423. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  1424. if dialysisPrescribe == nil {
  1425. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1426. }
  1427. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1428. // 获取透析模版
  1429. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1430. mode_id = schedual.ModeId
  1431. } else {
  1432. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  1433. // 获取透析模版
  1434. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1435. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  1436. if dialysisPrescribe == nil && dialysisSolution != nil {
  1437. mode_id = dialysisSolution.ModeId
  1438. }
  1439. if dialysisPrescribe == nil && dialysisSolution == nil {
  1440. mode_id = 0
  1441. }
  1442. }
  1443. fmt.Println("dialysisPrescribe------------------------------------", dialysisPrescribe)
  1444. fmt.Println("dialysisSolution------------------------------------", dialysisSolution)
  1445. // 插入透析处方
  1446. if dialysisPrescribe == nil && dialysisSolution != nil {
  1447. var newprescribe models.DialysisPrescription
  1448. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1449. newprescribe.PatientId = dialysisSolution.PatientId
  1450. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1451. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1452. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1453. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1454. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1455. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1456. newprescribe.ModeId = dialysisSolution.ModeId
  1457. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1458. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1459. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1460. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1461. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1462. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1463. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1464. newprescribe.Glucose = dialysisSolution.Glucose
  1465. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1466. newprescribe.Kalium = dialysisSolution.Kalium
  1467. newprescribe.Sodium = dialysisSolution.Sodium
  1468. newprescribe.Calcium = dialysisSolution.Calcium
  1469. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1470. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1471. newprescribe.Conductivity = dialysisSolution.Conductivity
  1472. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1473. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1474. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1475. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1476. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1477. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1478. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1479. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1480. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1481. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1482. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1483. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1484. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1485. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1486. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1487. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1488. newprescribe.CreatedTime = time.Now().Unix()
  1489. newprescribe.UpdatedTime = time.Now().Unix()
  1490. newprescribe.RecordDate = recordDate.Unix()
  1491. newprescribe.DewaterAmount = dewater_amount
  1492. newprescribe.TargetUltrafiltration = dewater_amount
  1493. newprescribe.Status = 1
  1494. err := service.AddSigleRecord(&newprescribe)
  1495. if err != nil {
  1496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1497. }
  1498. }
  1499. if dialysisPrescribe == nil && dialysisSolution == nil {
  1500. if lastDialysisPrescribe != nil {
  1501. var newprescribe models.DialysisPrescription
  1502. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  1503. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  1504. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  1505. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  1506. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  1507. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  1508. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  1509. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  1510. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  1511. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  1512. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  1513. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  1514. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  1515. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  1516. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  1517. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  1518. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  1519. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  1520. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  1521. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  1522. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  1523. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  1524. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  1525. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  1526. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  1527. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  1528. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  1529. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  1530. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  1531. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  1532. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  1533. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  1534. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  1535. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  1536. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  1537. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  1538. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  1539. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  1540. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  1541. newprescribe.CreatedTime = time.Now().Unix()
  1542. newprescribe.UpdatedTime = time.Now().Unix()
  1543. newprescribe.RecordDate = recordDate.Unix()
  1544. newprescribe.DewaterAmount = dewater_amount
  1545. newprescribe.TargetUltrafiltration = dewater_amount
  1546. newprescribe.Status = 1
  1547. err := service.AddSigleRecord(&newprescribe)
  1548. if err != nil {
  1549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1550. }
  1551. } else {
  1552. var newprescribe models.DialysisPrescription
  1553. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  1554. newprescribe.PatientId = patient
  1555. newprescribe.ModeId = mode_id
  1556. newprescribe.CreatedTime = time.Now().Unix()
  1557. newprescribe.UpdatedTime = time.Now().Unix()
  1558. newprescribe.RecordDate = recordDate.Unix()
  1559. newprescribe.DewaterAmount = dewater_amount
  1560. newprescribe.TargetUltrafiltration = dewater_amount
  1561. newprescribe.Status = 1
  1562. err := service.AddSigleRecord(&newprescribe)
  1563. if err != nil {
  1564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1565. }
  1566. }
  1567. }
  1568. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  1569. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1570. redis := service.RedisClient()
  1571. //清空key 值
  1572. redis.Set(key, "", time.Second)
  1573. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1574. redis.Set(keyOne, "", time.Second)
  1575. defer redis.Close()
  1576. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1577. redis.Set(keyTwo, "", time.Second)
  1578. if err == nil {
  1579. c.ServeSuccessJSON(map[string]interface{}{
  1580. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  1581. })
  1582. } else {
  1583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1584. }
  1585. }
  1586. }
  1587. func (c *DialysisApiController) PostTreatmentSummary() {
  1588. patient, _ := c.GetInt64("patient", 0)
  1589. recordDateStr := c.GetString("record_date")
  1590. if patient <= 0 {
  1591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1592. return
  1593. }
  1594. adminUserInfo := c.GetAdminUserInfo()
  1595. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1596. if patientInfo.ID == 0 {
  1597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1598. return
  1599. }
  1600. if len(recordDateStr) == 0 {
  1601. recordDateStr = time.Now().Format("2006-01-02")
  1602. }
  1603. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1604. if parseDateErr != nil {
  1605. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1607. return
  1608. }
  1609. mission := c.GetString("mission")
  1610. dialysis_summary := c.GetString("dialysis_summary")
  1611. nursingRecord := c.GetString("nursing_record")
  1612. specialRecord := c.GetString("special_record")
  1613. sj_nurse := adminUserInfo.AdminUser.Id
  1614. zl_nurse := adminUserInfo.AdminUser.Id
  1615. hd_nurse := adminUserInfo.AdminUser.Id
  1616. xj_nurse := adminUserInfo.AdminUser.Id
  1617. zl_doctor := adminUserInfo.AdminUser.Id
  1618. treatmentSummary := models.TreatmentSummary{
  1619. UserOrgId: adminUserInfo.CurrentOrgId,
  1620. PatientId: patient,
  1621. AssessmentDate: recordDate.Unix(),
  1622. Mission: mission,
  1623. DialysisSummary: dialysis_summary,
  1624. SjNurse: sj_nurse,
  1625. ZlNurse: zl_nurse,
  1626. HdNurse: hd_nurse,
  1627. XjNurse: xj_nurse,
  1628. ZlDoctor: zl_doctor,
  1629. Status: 1,
  1630. CreatedTime: time.Now().Unix(),
  1631. NursingRecord: nursingRecord,
  1632. SpecialRecord: specialRecord,
  1633. }
  1634. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1635. if tempTreatmentSummary.ID == 0 { //新增
  1636. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  1637. err := service.AddSigleSummaryRecord(&treatmentSummary)
  1638. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  1639. redis := service.RedisClient()
  1640. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  1641. redis.Set(keyOne, "", time.Second)
  1642. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1643. redis.Set(keyThree, "", time.Second)
  1644. defer redis.Close()
  1645. //清空key 值
  1646. redis.Set(key, "", time.Second)
  1647. if err == nil {
  1648. c.ServeSuccessJSON(map[string]interface{}{
  1649. "summary": treatmentSummary,
  1650. })
  1651. } else {
  1652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1653. }
  1654. } else { //修改
  1655. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  1656. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1657. // if getPermissionErr != nil {
  1658. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1659. // return
  1660. // } else if headNursePermission == nil {
  1661. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1662. // return
  1663. // }
  1664. //}
  1665. treatmentSummary.Creater = tempTreatmentSummary.Creater
  1666. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  1667. treatmentSummary.UpdatedTime = time.Now().Unix()
  1668. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  1669. treatmentSummary.ID = tempTreatmentSummary.ID
  1670. err := service.UpdateSummeRecord(&treatmentSummary)
  1671. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  1672. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  1673. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1674. //清空key 值
  1675. redis := service.RedisClient()
  1676. redis.Set(key, "", time.Second)
  1677. redis.Set(keyOne, "", time.Second)
  1678. redis.Set(keyThree, "", time.Second)
  1679. defer redis.Close()
  1680. if err == nil {
  1681. c.ServeSuccessJSON(map[string]interface{}{
  1682. "summary": treatmentSummary,
  1683. })
  1684. } else {
  1685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1686. }
  1687. }
  1688. }
  1689. func (c *DialysisApiController) GetDeviceList() {
  1690. adminUserInfo := c.GetAdminUserInfo()
  1691. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  1692. c.ServeSuccessJSON(map[string]interface{}{
  1693. "device": device,
  1694. })
  1695. }
  1696. func (c *DialysisApiController) GetAllDeviceZone() {
  1697. adminUserInfo := c.GetAdminUserInfo()
  1698. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  1699. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1700. if err == nil {
  1701. c.ServeSuccessJSON(map[string]interface{}{
  1702. "zone": zone,
  1703. "dics": dics,
  1704. })
  1705. }
  1706. }
  1707. func (c *DialysisApiController) GetDialysisWatch() {
  1708. page, _ := c.GetInt64("page", 1)
  1709. limit, _ := c.GetInt64("limit", 10)
  1710. schedulType, _ := c.GetInt64("schedul_type", 0)
  1711. startTime, _ := c.GetInt64("schedul_time", 0)
  1712. partitionType, _ := c.GetInt64("partition_type", 0)
  1713. keywords := c.GetString("keywords")
  1714. adminUserInfo := c.GetAdminUserInfo()
  1715. if len(keywords) > 0 {
  1716. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  1717. if err == nil {
  1718. c.ServeSuccessJSON(map[string]interface{}{
  1719. "schedule": dialysisSchedule,
  1720. "total": total,
  1721. })
  1722. } else {
  1723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1724. }
  1725. } else {
  1726. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  1727. if err == nil {
  1728. c.ServeSuccessJSON(map[string]interface{}{
  1729. "schedule": dialysisSchedule,
  1730. "total": total,
  1731. })
  1732. } else {
  1733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1734. }
  1735. }
  1736. }
  1737. //func (c *DialysisApiController) GetDialysisWatch() {
  1738. // page, _ := c.GetInt64("page", 1)
  1739. // limit, _ := c.GetInt64("limit", 10)
  1740. // schedulType, _ := c.GetInt64("schedul_type", 0)
  1741. // startTime, _ := c.GetInt64("schedul_time", 0)
  1742. // partitionType, _ := c.GetInt64("partition_type", 0)
  1743. // keywords := c.GetString("keywords")
  1744. //
  1745. // adminUserInfo := c.GetAdminUserInfo()
  1746. // if len(keywords) > 0 {
  1747. // dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  1748. //
  1749. // //获取所有床位号
  1750. // numberList, _ := service.GetAllDeviceNumberByListSix(adminUserInfo.CurrentOrgId)
  1751. //
  1752. // //获取透析处方
  1753. // prescriptions, _ := service.GetAllPrescriptionByListTwo(adminUserInfo.CurrentOrgId, startTime)
  1754. // //获取透前评估
  1755. // assessmentBefores, _ := service.GetAllAssessmentBeforesByListThree(adminUserInfo.CurrentOrgId, startTime)
  1756. // //获取上机
  1757. // dialysisOrders, _ := service.GetAllDialysisOrdersByListThree(adminUserInfo.CurrentOrgId, startTime)
  1758. // //获取透后
  1759. // AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListThree(adminUserInfo.CurrentOrgId, startTime)
  1760. //
  1761. // //获取透后监测
  1762. // monitorlist, _ := service.GetAllMonitorListThree(adminUserInfo.CurrentOrgId, startTime)
  1763. //
  1764. // //获取所有的患者
  1765. // patients, _ := service.GetAllPatientListByListSix(adminUserInfo.CurrentOrgId,keywords)
  1766. //
  1767. // //获取所有透析模式
  1768. // treatments, _ := service.GetAllTreatModeByList(adminUserInfo.CurrentOrgId)
  1769. //
  1770. // for key, scheduals := range dialysisSchedule {
  1771. // // 获取患者信息
  1772. // for _, patient := range patients {
  1773. // if scheduals.PatientId == patient.ID {
  1774. // dialysisSchedule[key].MonitorPatients = patient
  1775. // break
  1776. // }
  1777. // }
  1778. // // 床位信息
  1779. // for _, device := range numberList {
  1780. // if scheduals.BedId == device.ID {
  1781. // dialysisSchedule[key].DeviceNumber = device
  1782. // break
  1783. // }
  1784. // }
  1785. //
  1786. // // 医嘱信息
  1787. // for _, prescription := range prescriptions {
  1788. // if scheduals.PatientId == prescription.PatientId {
  1789. // dialysisSchedule[key].Prescription = prescription
  1790. // break
  1791. // }
  1792. // }
  1793. //
  1794. // // 透前评估
  1795. // for _, assessmentBefore := range assessmentBefores {
  1796. // if scheduals.PatientId == assessmentBefore.PatientId {
  1797. // dialysisSchedule[key].AssessmentBeforeDislysis = assessmentBefore
  1798. // break
  1799. // }
  1800. // }
  1801. //
  1802. // // 透析上下机
  1803. // for _, dialysisOrder := range dialysisOrders {
  1804. // if scheduals.PatientId == dialysisOrder.PatientId {
  1805. // dialysisSchedule[key].DialysisOrder = dialysisOrder
  1806. // break
  1807. // }
  1808. // }
  1809. //
  1810. // records := make([]*models.MonitoringRecord, 0)
  1811. // // 透析监测
  1812. // for _, it := range monitorlist {
  1813. // records := append(records, it)
  1814. // if scheduals.PatientId == it.PatientId {
  1815. // dialysisSchedule[key].MonitoringRecord = records
  1816. // }
  1817. // }
  1818. //
  1819. // // 透后评估
  1820. // for _, afterDislysis := range AssessmentAfterDislysis {
  1821. // if scheduals.PatientId == afterDislysis.PatientId {
  1822. // dialysisSchedule[key].AssessmentAfterDislysis = afterDislysis
  1823. // break
  1824. // }
  1825. // }
  1826. //
  1827. // //透析模式
  1828. // for _, treatment := range treatments {
  1829. // if scheduals.ModeId == treatment.ID {
  1830. // dialysisSchedule[key].TreatmentMode = treatment
  1831. // break
  1832. // }
  1833. // }
  1834. // }
  1835. // //获取所有床位号
  1836. // if err == nil {
  1837. // c.ServeSuccessJSON(map[string]interface{}{
  1838. // "schedule": dialysisSchedule,
  1839. // "total": total,
  1840. // })
  1841. // } else {
  1842. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1843. // }
  1844. //
  1845. // } else {
  1846. // dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  1847. // if err == nil {
  1848. // c.ServeSuccessJSON(map[string]interface{}{
  1849. // "schedule": dialysisSchedule,
  1850. // "total": total,
  1851. // })
  1852. // } else {
  1853. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1854. // }
  1855. // }
  1856. //}
  1857. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  1858. patientId, _ := c.GetInt64("id", 0)
  1859. record_date, _ := c.GetInt64("record_date", 0)
  1860. adminUserInfo := c.GetAdminUserInfo()
  1861. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1862. var dialysisStatus int64
  1863. if dialysisOrder == nil { //没有透析记录
  1864. dialysisStatus = 0 //未透析
  1865. } else {
  1866. dialysisStatus = dialysisOrder.Stage
  1867. }
  1868. //用户基本信息
  1869. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1870. //接诊评估
  1871. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1872. //透前评估
  1873. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1874. //临时医嘱
  1875. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1876. //双人核对
  1877. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1878. //透析监测
  1879. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  1880. //透后评估
  1881. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1882. //透析小结
  1883. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1884. //透析处方
  1885. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  1886. if dialysisPrescription.ID == 0 {
  1887. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  1888. c.ServeSuccessJSON(map[string]interface{}{
  1889. "patientInfo": schedualPatientInfo,
  1890. "dialysisPrescription": solution,
  1891. "receiverTreatmentAccess": receiverTreatmentAccess,
  1892. "predialysisEvaluation": PredialysisEvaluation,
  1893. "doctorAdvice": DoctorAdvice,
  1894. "doubleCheck": DoubleCheck,
  1895. "assessmentAfterDislysis": AssessmentAfterDislysis,
  1896. "treatmentSummary": TreatmentSummary,
  1897. "monitorRecord": Record,
  1898. "dialysisStatus": dialysisStatus,
  1899. "dialysisOrder": dialysisOrder,
  1900. "isSolution": 1,
  1901. })
  1902. } else {
  1903. c.ServeSuccessJSON(map[string]interface{}{
  1904. "patientInfo": schedualPatientInfo,
  1905. "dialysisPrescription": dialysisPrescription,
  1906. "receiverTreatmentAccess": receiverTreatmentAccess,
  1907. "predialysisEvaluation": PredialysisEvaluation,
  1908. "doctorAdvice": DoctorAdvice,
  1909. "doubleCheck": DoubleCheck,
  1910. "assessmentAfterDislysis": AssessmentAfterDislysis,
  1911. "treatmentSummary": TreatmentSummary,
  1912. "monitorRecord": Record,
  1913. "dialysisStatus": dialysisStatus,
  1914. "dialysisOrder": dialysisOrder,
  1915. "isSolution": 2,
  1916. })
  1917. }
  1918. }
  1919. func (c *DialysisApiController) CreateDoctorAdvice() {
  1920. patient, _ := c.GetInt64("id", 0)
  1921. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  1922. record_date, _ := c.GetInt64("record_date", 0)
  1923. if patient <= 0 {
  1924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1925. return
  1926. }
  1927. adminUserInfo := c.GetAdminUserInfo()
  1928. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1929. if patientInfo.ID == 0 {
  1930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1931. return
  1932. }
  1933. var advice models.DoctorAdvice
  1934. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  1935. if code > 0 {
  1936. c.ServeFailJSONWithSGJErrorCode(code)
  1937. return
  1938. }
  1939. if advice.ParentId > 0 {
  1940. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  1941. if old.ID == 0 || old.PatientId != patient {
  1942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1943. return
  1944. }
  1945. if old.StopState == 1 || old.ExecutionState == 1 {
  1946. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1947. return
  1948. }
  1949. if old.ParentId > 0 {
  1950. advice.ParentId = old.ParentId
  1951. }
  1952. advice.StartTime = old.StartTime
  1953. advice.AdviceDoctor = old.AdviceDoctor
  1954. advice.DeliveryWay = old.DeliveryWay
  1955. advice.ExecutionFrequency = old.ExecutionFrequency
  1956. }
  1957. advice.RecordDate = record_date
  1958. advice.DialysisOrderId = dialysis_id
  1959. advice.Status = 1
  1960. advice.CreatedTime = time.Now().Unix()
  1961. advice.UpdatedTime = time.Now().Unix()
  1962. advice.StopState = 2
  1963. advice.ExecutionState = 2
  1964. advice.AdviceType = 2
  1965. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1966. advice.PatientId = patient
  1967. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1968. err := service.CreateDoctorAdvice(&advice)
  1969. if err != nil {
  1970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1971. return
  1972. }
  1973. for _, subAdvice := range subAdivice {
  1974. subAdvice.ParentId = advice.ID
  1975. subAdvice.PatientId = patient
  1976. subAdvice.RecordDate = record_date
  1977. subAdvice.CreatedTime = time.Now().Unix()
  1978. subAdvice.UpdatedTime = time.Now().Unix()
  1979. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  1980. }
  1981. service.CreateSubDoctorAdvice(subAdivice)
  1982. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  1983. c.ServeSuccessJSON(map[string]interface{}{
  1984. "msg": "ok",
  1985. "advice": advice,
  1986. "subAdvice": subAdivices,
  1987. })
  1988. return
  1989. }
  1990. func (c *DialysisApiController) EditDoctorAdvice() {
  1991. patient, _ := c.GetInt64("patient", 0)
  1992. id, _ := c.GetInt64("id", 0)
  1993. parent_id, _ := c.GetInt64("parent_id", 0)
  1994. execution_time := c.GetString("execution_time")
  1995. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  1996. // checker, _ := c.GetInt64("checker", 0)
  1997. if id <= 0 || patient <= 0 {
  1998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1999. return
  2000. }
  2001. adminUserInfo := c.GetAdminUserInfo()
  2002. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2003. if advice.ID == 0 || advice.PatientId != patient {
  2004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2005. return
  2006. }
  2007. if len(execution_time) <= 0 {
  2008. utils.ErrorLog("execution_time")
  2009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2010. return
  2011. }
  2012. execution_staff := adminUserInfo.AdminUser.Id
  2013. checker := adminUserInfo.AdminUser.Id
  2014. timeLayout2 := "2006-01-02 15:04"
  2015. loc, _ := time.LoadLocation("Local")
  2016. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  2017. if errs != nil {
  2018. utils.ErrorLog(errs.Error())
  2019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2020. return
  2021. }
  2022. advices := models.DoctorAdvice{
  2023. ExecutionStaff: execution_staff,
  2024. ExecutionTime: theTime.Unix(),
  2025. Checker: checker,
  2026. UpdatedTime: time.Now().Unix(),
  2027. }
  2028. var err error
  2029. if parent_id > 0 {
  2030. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  2031. } else {
  2032. err = service.ExceDoctorAdviceById(&advices, id, patient)
  2033. }
  2034. if err != nil {
  2035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2036. return
  2037. }
  2038. c.ServeSuccessJSON(map[string]interface{}{
  2039. "msg": "ok",
  2040. "advice": advice,
  2041. })
  2042. return
  2043. }
  2044. func (c *DialysisApiController) GetDoctorAdvice() {
  2045. patient, _ := c.GetInt64("patient_id", 0)
  2046. parent_id, _ := c.GetInt64("parent_id", 0)
  2047. adviceId, _ := c.GetInt64("id", 0)
  2048. if patient <= 0 {
  2049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2050. return
  2051. }
  2052. dminUserInfo := c.GetAdminUserInfo()
  2053. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  2054. if patientInfo.ID == 0 {
  2055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2056. return
  2057. }
  2058. var subAdvice []*models.DoctorAdvice
  2059. var advice models.DoctorAdvice
  2060. if parent_id > 0 {
  2061. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  2062. if advice.ID == 0 || advice.PatientId != patient {
  2063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2064. return
  2065. }
  2066. subAdvice = service.FindSubAdivceById(patient, parent_id)
  2067. } else {
  2068. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  2069. if advice.ID == 0 || advice.PatientId != patient {
  2070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2071. return
  2072. }
  2073. subAdvice = service.FindSubAdivceById(patient, adviceId)
  2074. }
  2075. c.ServeSuccessJSON(map[string]interface{}{
  2076. "msg": "ok",
  2077. "advice": advice,
  2078. "subAdvice": subAdvice,
  2079. })
  2080. }
  2081. func (this *DialysisApiController) DelMonitor() {
  2082. recordID, _ := this.GetInt64("record_id")
  2083. patientID, _ := this.GetInt64("patient_id")
  2084. if recordID <= 0 || patientID <= 0 {
  2085. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2086. return
  2087. }
  2088. adminInfo := this.GetAdminUserInfo()
  2089. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  2090. if getPatientErr != nil {
  2091. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2092. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2093. return
  2094. } else if patient == nil {
  2095. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2096. return
  2097. }
  2098. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  2099. if getMonitorErr != nil {
  2100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2101. return
  2102. }
  2103. //if monitor != nil {
  2104. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  2105. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2106. // if getPermissionErr != nil {
  2107. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2108. // return
  2109. // } else if headNursePermission == nil {
  2110. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2111. // return
  2112. // }
  2113. // }
  2114. //}
  2115. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  2116. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  2117. redis := service.RedisClient()
  2118. //清空key 值
  2119. redis.Set(key, "", time.Second)
  2120. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  2121. redis.Set(keyOne, "", time.Second)
  2122. defer redis.Close()
  2123. if err != nil {
  2124. this.ErrorLog("删除透析监测记录失败:%v", err)
  2125. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  2126. return
  2127. }
  2128. this.ServeSuccessJSON(map[string]interface{}{
  2129. "record_id": monitor.ID,
  2130. })
  2131. }
  2132. func (c *DialysisApiController) CreateMonitor() {
  2133. patient, _ := c.GetInt64("id", 0)
  2134. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  2135. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  2136. operate_time, _ := c.GetInt64("operate_time", 0)
  2137. // monitoring_time := c.GetString("monitoring_time")
  2138. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  2139. breathing_rated, _ := c.GetFloat("breathing_rated", 0)
  2140. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  2141. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  2142. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  2143. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  2144. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  2145. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  2146. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  2147. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  2148. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  2149. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  2150. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  2151. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  2152. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  2153. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  2154. temperature, _ := c.GetFloat("temperature", 0)
  2155. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  2156. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  2157. conductivity, _ := c.GetFloat("conductivity", 0)
  2158. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  2159. heparin, _ := c.GetFloat("heparin", 0)
  2160. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  2161. ktv, _ := c.GetFloat("ktv", 0)
  2162. symptom := c.GetString("symptom")
  2163. dispose := c.GetString("dispose")
  2164. result := c.GetString("results")
  2165. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  2166. monitor_anticoagulant, _ := c.GetInt64("monitor_anticoagulant")
  2167. monitor_anticoagulant_value := c.GetString("monitor_anticoagulant_value")
  2168. monitoring_date = monitoring_date / 1000
  2169. // operate_time = operate_time / 1000
  2170. if patient <= 0 {
  2171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2172. return
  2173. }
  2174. adminUserInfo := c.GetAdminUserInfo()
  2175. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2176. if patientInfo.ID == 0 {
  2177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2178. return
  2179. }
  2180. monitorRecord := models.MonitoringRecord{
  2181. PatientId: patient,
  2182. MonitoringDate: monitoring_date,
  2183. DialysisOrderId: dialysis_order_id,
  2184. OperateTime: operate_time,
  2185. // MonitoringTime: monitoring_time,
  2186. PulseFrequency: pulse_frequency,
  2187. BreathingRate: breathing_rated,
  2188. SystolicBloodPressure: systolic_blood_pressure,
  2189. DiastolicBloodPressure: diastolic_blood_pressure,
  2190. BloodPressureType: blood_pressure_type,
  2191. BloodFlowVolume: blood_flow_volume,
  2192. VenousPressure: venous_pressure,
  2193. VenousPressureType: venous_pressure_type,
  2194. TransmembranePressure: transmembrane_pressure,
  2195. TransmembranePressureType: transmembrane_pressure_type,
  2196. UltrafiltrationRate: ultrafiltration_rate,
  2197. UltrafiltrationVolume: ultrafiltration_volume,
  2198. SodiumConcentration: sodium_concentration,
  2199. ArterialPressure: arterial_pressure,
  2200. ArterialPressureType: arterial_pressure_type,
  2201. DialysateTemperature: dialysate_temperature,
  2202. Temperature: temperature,
  2203. ReplacementRate: replacement_rate,
  2204. DisplacementQuantity: displacement_quantity,
  2205. Ktv: ktv,
  2206. Symptom: symptom,
  2207. Dispose: dispose,
  2208. Result: result,
  2209. MonitoringNurse: monitoring_nurse,
  2210. Status: 1,
  2211. CreatedTime: time.Now().Unix(),
  2212. UpdatedTime: time.Now().Unix(),
  2213. UserOrgId: adminUserInfo.CurrentOrgId,
  2214. Conductivity: conductivity,
  2215. DisplacementFlowQuantity: displacement_flow_quantity,
  2216. Heparin: heparin,
  2217. DialysateFlow: dialysate_flow,
  2218. MonitorAnticoagulant: monitor_anticoagulant,
  2219. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  2220. }
  2221. err := service.CreateMonitor(&monitorRecord)
  2222. redis := service.RedisClient()
  2223. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_record_list_all"
  2224. redis.Set(key, "", time.Second)
  2225. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  2226. redis.Set(keyOne, "", time.Second)
  2227. redis.Close()
  2228. if err != nil {
  2229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2230. return
  2231. }
  2232. c.ServeSuccessJSON(map[string]interface{}{
  2233. "msg": "ok",
  2234. "monitor": monitorRecord,
  2235. })
  2236. return
  2237. }
  2238. // 已弃用
  2239. // func (c *DialysisApiController) CreateRecordData() {
  2240. // patient, _ := c.GetInt64("id", 0)
  2241. // status, _ := c.GetInt64("status", 0)
  2242. // now := time.Now()
  2243. // year, month, day := now.Date()
  2244. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2245. // todayTimeStamp := today_time.Unix()
  2246. // if patient <= 0 {
  2247. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2248. // return
  2249. // }
  2250. // adminUserInfo := c.GetAdminUserInfo()
  2251. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2252. // if patientInfo.ID == 0 {
  2253. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2254. // return
  2255. // }
  2256. // record := &models.DialysisOrder{
  2257. // DialysisDate: todayTimeStamp,
  2258. // UserOrgId: adminUserInfo.CurrentOrgId,
  2259. // PatientId: patient,
  2260. // Stage: status,
  2261. // Status: 1,
  2262. // CreatedTime: time.Now().Unix(),
  2263. // UpdatedTime: time.Now().Unix(),
  2264. // }
  2265. // if status == 1 {
  2266. // //创建透析记录
  2267. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  2268. // if err == nil {
  2269. // c.ServeSuccessJSON(map[string]interface{}{
  2270. // "dialysisOrder": record,
  2271. // })
  2272. // } else {
  2273. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2274. // }
  2275. // } else {
  2276. // record_id, _ := c.GetInt64("record_id", 0)
  2277. // //修改透析记录状态
  2278. // errs := service.ModifyDialysisRecord(record_id)
  2279. // //结束时候透析次数加1
  2280. // service.UpdateSolutionByPatientId(patient)
  2281. // if errs == nil {
  2282. // c.ServeSuccessJSON(map[string]interface{}{
  2283. // "dialysisOrder": record,
  2284. // })
  2285. // } else {
  2286. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2287. // }
  2288. // }
  2289. // }
  2290. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  2291. dataBody := make(map[string]interface{}, 0)
  2292. err := json.Unmarshal(data, &dataBody)
  2293. if err != nil {
  2294. utils.ErrorLog(err.Error())
  2295. code = enums.ErrorCodeParamWrong
  2296. return
  2297. }
  2298. timeLayout := "2006-01-02 "
  2299. timeLayout2 := "2006-01-02 15:04"
  2300. loc, _ := time.LoadLocation("Local")
  2301. if action == "create" {
  2302. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2303. utils.ErrorLog("advice_type")
  2304. code = enums.ErrorCodeParamWrong
  2305. return
  2306. }
  2307. adviceType := int64(dataBody["advice_type"].(float64))
  2308. if adviceType != 1 && adviceType != 2 {
  2309. utils.ErrorLog("advice_type != 1&&2")
  2310. code = enums.ErrorCodeParamWrong
  2311. return
  2312. }
  2313. advice.AdviceType = adviceType
  2314. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2315. utils.ErrorLog("advice_date")
  2316. code = enums.ErrorCodeParamWrong
  2317. return
  2318. }
  2319. adviceDate, _ := dataBody["advice_date"].(string)
  2320. if len(adviceDate) == 0 {
  2321. utils.ErrorLog("len(adviceDate) == 0")
  2322. code = enums.ErrorCodeParamWrong
  2323. return
  2324. }
  2325. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2326. if err != nil {
  2327. utils.ErrorLog(err.Error())
  2328. code = enums.ErrorCodeParamWrong
  2329. return
  2330. }
  2331. advice.AdviceDate = theTime.Unix()
  2332. }
  2333. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2334. utils.ErrorLog("start_time")
  2335. code = enums.ErrorCodeParamWrong
  2336. return
  2337. }
  2338. startDate, _ := dataBody["start_time"].(string)
  2339. if len(startDate) == 0 {
  2340. utils.ErrorLog("len(startDate) == 0")
  2341. code = enums.ErrorCodeParamWrong
  2342. return
  2343. }
  2344. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  2345. if err != nil {
  2346. utils.ErrorLog(err.Error())
  2347. code = enums.ErrorCodeParamWrong
  2348. return
  2349. }
  2350. advice.StartTime = theTime.Unix()
  2351. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2352. utils.ErrorLog("advice_name")
  2353. code = enums.ErrorCodeParamWrong
  2354. return
  2355. }
  2356. adviceName, _ := dataBody["advice_name"].(string)
  2357. if len(adviceName) == 0 {
  2358. utils.ErrorLog("len(advice_name) == 0")
  2359. code = enums.ErrorCodeParamWrong
  2360. return
  2361. }
  2362. advice.AdviceName = adviceName
  2363. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  2364. utils.ErrorLog("delivery_way")
  2365. code = enums.ErrorCodeParamWrong
  2366. return
  2367. }
  2368. deliveryWay, _ := dataBody["delivery_way"].(string)
  2369. if len(deliveryWay) == 0 {
  2370. utils.ErrorLog("len(deliveryWay) == 0")
  2371. code = enums.ErrorCodeParamWrong
  2372. return
  2373. }
  2374. advice.DeliveryWay = deliveryWay
  2375. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  2376. utils.ErrorLog("execution_frequency")
  2377. code = enums.ErrorCodeParamWrong
  2378. return
  2379. }
  2380. execution_frequency, _ := dataBody["execution_frequency"].(string)
  2381. if len(execution_frequency) == 0 {
  2382. utils.ErrorLog("len(execution_frequency) == 0")
  2383. code = enums.ErrorCodeParamWrong
  2384. return
  2385. }
  2386. advice.ExecutionFrequency = execution_frequency
  2387. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  2388. adviceDsc, _ := dataBody["advice_desc"].(string)
  2389. advice.AdviceDesc = adviceDsc
  2390. }
  2391. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  2392. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  2393. advice.DrugSpecUnit = drugSpecUnit
  2394. }
  2395. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  2396. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  2397. advice.SingleDose = singleDose
  2398. }
  2399. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  2400. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  2401. advice.SingleDoseUnit = singleDoseUnit
  2402. }
  2403. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  2404. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  2405. advice.PrescribingNumber = prescribingNumber
  2406. }
  2407. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  2408. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  2409. advice.PrescribingNumberUnit = prescribingNumberUnit
  2410. }
  2411. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  2412. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  2413. if len(thisContagions) > 0 {
  2414. for _, item := range thisContagions {
  2415. items := item.(map[string]interface{})
  2416. advice_name, _ := items["advice_name"].(string)
  2417. advice_desc, _ := items["advice_desc"].(string)
  2418. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  2419. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  2420. single_dose_unit, _ := items["single_dose_unit"].(string)
  2421. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  2422. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  2423. advice := &models.DoctorAdvice{
  2424. AdviceName: advice_name,
  2425. AdviceDesc: advice_desc,
  2426. SingleDose: single_dose,
  2427. SingleDoseUnit: single_dose_unit,
  2428. DrugSpecUnit: drug_spec_unit,
  2429. PrescribingNumber: prescribing_number,
  2430. PrescribingNumberUnit: prescribing_number_unit,
  2431. }
  2432. subAdvice = append(subAdvice, advice)
  2433. }
  2434. }
  2435. }
  2436. return
  2437. }
  2438. func (c *DialysisApiController) GetDialysisOrder() {
  2439. xtno := c.GetString("xtno")
  2440. xtdate := c.GetString("xtdate")
  2441. timeLayout := "2006-01-02"
  2442. loc, _ := time.LoadLocation("Local")
  2443. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  2444. if err != nil {
  2445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2446. return
  2447. }
  2448. xttime := theTime.Unix()
  2449. operatorIDs := make([]int64, 0)
  2450. adminUserInfo := c.GetAdminUserInfo()
  2451. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  2452. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.CurrentOrgId, xtno, xttime)
  2453. //透析单
  2454. dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2455. if dialysisOrder != nil {
  2456. if dialysisOrder.FinishNurse > 0 {
  2457. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  2458. }
  2459. if dialysisOrder.StartNurse > 0 {
  2460. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  2461. }
  2462. }
  2463. //透前评估
  2464. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2465. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  2466. //透后评估
  2467. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2468. if AssessmentAfterDislysis.Modifier > 0 {
  2469. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  2470. }
  2471. //上次透前评估
  2472. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2473. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2474. //透析处方
  2475. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2476. if dialysisPrescription.PrescriptionDoctor > 0 {
  2477. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  2478. }
  2479. //获取病人的透析模式
  2480. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2481. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2482. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2483. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2484. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2485. //获取透析处方
  2486. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2487. //获取临时医嘱
  2488. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2489. //config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  2490. //获取医嘱内容
  2491. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2492. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  2493. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2494. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2495. //获取上次的透后体重
  2496. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2497. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2498. //获取透析次数
  2499. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  2500. if len(DoctorAdvice) > 0 {
  2501. for _, item := range DoctorAdvice {
  2502. if item.AdviceDoctor > 0 {
  2503. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2504. }
  2505. if item.ExecutionStaff > 0 {
  2506. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2507. }
  2508. if item.Checker > 0 {
  2509. operatorIDs = append(operatorIDs, item.Checker)
  2510. }
  2511. }
  2512. }
  2513. //透析监测
  2514. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2515. //透析检测
  2516. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2517. //透析小结
  2518. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2519. //接诊评估
  2520. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2521. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2522. if adminUserInfo.CurrentOrgId != 10101 {
  2523. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2524. patientInfo.TotalDialysis = dialysis_count
  2525. }
  2526. if adminUserInfo.CurrentOrgId == 10101 {
  2527. dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2528. patientInfo.TotalDialysis = dialysis_count
  2529. }
  2530. //相关操作对应的操作人
  2531. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  2532. operators, err := service.GetAdminUserEsOne(adminUserInfo.CurrentOrgId)
  2533. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2534. //获取当前日期月份的第一天
  2535. firstmonth := service.GetFirstDateOfMonth(theTime)
  2536. firstMonthDate := firstmonth.Unix()
  2537. //获取当前月份的病人透析次数
  2538. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  2539. //获取his数据
  2540. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2541. //hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2542. config, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  2543. project_config, _ := service.GetHisProjectConfig(adminUserInfo.CurrentOrgId)
  2544. projects, _ := service.FindAllHisProjectById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  2545. //if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  2546. // for _, item := range projects {
  2547. // var advice *models.HisDoctorAdviceInfo
  2548. // advice.ID = item.ID
  2549. // advice.Checker = item.Checker
  2550. // advice.CheckTime = item.CheckTime
  2551. // advice.CheckState = item.CheckState
  2552. // advice.ExecutionState = item.ExecutionState
  2553. // advice.ExecutionStaff = item.ExecutionStaff
  2554. // advice.PrescribingNumber = float64(item.Count)
  2555. // advice.PrescribingNumberUnit = item.Unit
  2556. // advice.AdviceDoctor = item.Doctor
  2557. // if item.Type == 3 {
  2558. // advice.AdviceName = item.GoodInfo.GoodName
  2559. // } else if item.Type == 2 {
  2560. // advice.AdviceName = item.HisProject.ProjectName
  2561. // }
  2562. // advice.StartTime = item.StartTime
  2563. // hisAdvice = append(hisAdvice, advice)
  2564. // }
  2565. //}
  2566. if config.IsOpen == 1 {
  2567. c.ServeSuccessJSON(map[string]interface{}{
  2568. "xtdate": xtdate,
  2569. "users": adminUser,
  2570. "patientInfo": patientInfo,
  2571. "PredialysisEvaluation": PredialysisEvaluation,
  2572. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2573. "dialysisPrescription": dialysisPrescription,
  2574. "advices": hisAdvice,
  2575. "monitors": Record,
  2576. "summary": TreatmentSummary,
  2577. "receiverTreatmentAccess": receiverTreatmentAccess,
  2578. "dialysisOrder": dialysisOrder,
  2579. "operators": operators,
  2580. "org_template_info": templateInfo,
  2581. "check": check,
  2582. "schedule": schedule,
  2583. "dialysisway": dialysisway,
  2584. "order": order,
  2585. "doctorAdvice": doctorAdvice,
  2586. "doctor": doctor,
  2587. "nurse": nurse,
  2588. "doctorAdevieInfo": doctorAdevieInfo,
  2589. "total": total,
  2590. "startNuse": startNuse,
  2591. "DoctorName": DoctorName,
  2592. "assessmentAfterDislysis": assessmentAfterDislysis,
  2593. "predialysName": predialysName,
  2594. "FinishNuse": FinishNuse,
  2595. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  2596. "dialysiscount": dialysiscount,
  2597. "last_order": lastOrder,
  2598. "project_config": project_config,
  2599. "projects": projects,
  2600. })
  2601. }
  2602. if config.IsOpen == 0 || config.IsOpen == 2 {
  2603. c.ServeSuccessJSON(map[string]interface{}{
  2604. "xtdate": xtdate,
  2605. "users": adminUser,
  2606. "patientInfo": patientInfo,
  2607. "PredialysisEvaluation": PredialysisEvaluation,
  2608. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2609. "dialysisPrescription": dialysisPrescription,
  2610. "advices": DoctorAdvice,
  2611. "monitors": Record,
  2612. "summary": TreatmentSummary,
  2613. "receiverTreatmentAccess": receiverTreatmentAccess,
  2614. "dialysisOrder": dialysisOrder,
  2615. "operators": operators,
  2616. "org_template_info": templateInfo,
  2617. "check": check,
  2618. "schedule": schedule,
  2619. "dialysisway": dialysisway,
  2620. "order": order,
  2621. "doctorAdvice": doctorAdvice,
  2622. "doctor": doctor,
  2623. "nurse": nurse,
  2624. "doctorAdevieInfo": doctorAdevieInfo,
  2625. "total": total,
  2626. "startNuse": startNuse,
  2627. "DoctorName": DoctorName,
  2628. "assessmentAfterDislysis": assessmentAfterDislysis,
  2629. "predialysName": predialysName,
  2630. "FinishNuse": FinishNuse,
  2631. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  2632. "dialysiscount": dialysiscount,
  2633. "last_order": lastOrder,
  2634. "project_config": project_config,
  2635. "projects": projects,
  2636. })
  2637. }
  2638. }
  2639. //
  2640. func (c *DialysisApiController) GetLongAdvice() {
  2641. patient_id, _ := c.GetInt64("patient_id")
  2642. adminUserInfo := c.GetAdminUserInfo()
  2643. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2644. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  2645. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  2646. c.ServeSuccessJSON(map[string]interface{}{
  2647. "status": "1",
  2648. })
  2649. return
  2650. } else { //开启推送提醒
  2651. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  2652. var advice_three []*models.DoctorAdvice
  2653. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  2654. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id)
  2655. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id)
  2656. for _, advice := range advices {
  2657. if advice.FrequencyType == 3 {
  2658. t := time.Now()
  2659. week := int(t.Weekday())
  2660. switch week {
  2661. case 1:
  2662. if strings.Index(advice.WeekDay, "周一") == -1 {
  2663. advice_three = append(advice_three, advice)
  2664. }
  2665. break
  2666. case 2:
  2667. if strings.Index(advice.WeekDay, "周二") == -1 {
  2668. advice_three = append(advice_three, advice)
  2669. }
  2670. break
  2671. case 3:
  2672. if strings.Index(advice.WeekDay, "周三") == -1 {
  2673. advice_three = append(advice_three, advice)
  2674. }
  2675. break
  2676. case 4:
  2677. if strings.Index(advice.WeekDay, "周四") == -1 {
  2678. advice_three = append(advice_three, advice)
  2679. }
  2680. break
  2681. case 5:
  2682. if strings.Index(advice.WeekDay, "周五") == -1 {
  2683. advice_three = append(advice_three, advice)
  2684. }
  2685. break
  2686. case 6:
  2687. if strings.Index(advice.WeekDay, "周六") == -1 {
  2688. advice_three = append(advice_three, advice)
  2689. }
  2690. break
  2691. case 0:
  2692. if strings.Index(advice.WeekDay, "周日") == -1 {
  2693. advice_three = append(advice_three, advice)
  2694. }
  2695. break
  2696. }
  2697. }
  2698. }
  2699. for _, advice := range advices_two {
  2700. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  2701. now := p.Unix()
  2702. dayStr := strconv.FormatInt(advice.DayCount, 10)
  2703. dayStr2 := "-" + dayStr
  2704. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  2705. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  2706. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  2707. for _, ad := range advices {
  2708. advice_three = append(advice_three, ad)
  2709. }
  2710. }
  2711. if err == nil {
  2712. c.ServeSuccessJSON(map[string]interface{}{
  2713. "status": "2",
  2714. "advices": advices,
  2715. "advices_two": RemoveRepeatedElement(advice_three),
  2716. "is_open_remind": config.IsOpenRemind,
  2717. })
  2718. }
  2719. }
  2720. }
  2721. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  2722. newArr = make([]*models.DoctorAdvice, 0)
  2723. for i := 0; i < len(arr); i++ {
  2724. repeat := false
  2725. for j := i + 1; j < len(arr); j++ {
  2726. if arr[i].ID == arr[j].ID {
  2727. repeat = true
  2728. break
  2729. }
  2730. }
  2731. if !repeat {
  2732. newArr = append(newArr, arr[i])
  2733. }
  2734. }
  2735. return
  2736. }
  2737. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  2738. patient, _ := c.GetInt64("id", 0)
  2739. groupNo, _ := c.GetInt64("groupno", 0)
  2740. if patient <= 0 {
  2741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2742. return
  2743. }
  2744. adminUserInfo := c.GetAdminUserInfo()
  2745. dataBody := make(map[string]interface{}, 0)
  2746. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2747. if err != nil {
  2748. utils.ErrorLog(err.Error())
  2749. return
  2750. }
  2751. utils.ErrorLog("%v", dataBody)
  2752. timeLayout := "2006-01-02 15:04"
  2753. loc, _ := time.LoadLocation("Local")
  2754. timeLayout2 := "2006-01-02"
  2755. loc2, _ := time.LoadLocation("Local")
  2756. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2757. utils.ErrorLog("advice_type")
  2758. return
  2759. }
  2760. adviceType := int64(2)
  2761. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2762. utils.ErrorLog("advice_date")
  2763. return
  2764. }
  2765. adviceDate, _ := dataBody["advice_date"].(string)
  2766. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  2767. AdviceDate := theTime.Unix()
  2768. RecordDate := theTime.Unix()
  2769. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2770. utils.ErrorLog("start_time")
  2771. return
  2772. }
  2773. startTime, _ := dataBody["start_time"].(string)
  2774. if len(startTime) == 0 {
  2775. utils.ErrorLog("len(start_time) == 0")
  2776. return
  2777. }
  2778. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  2779. if err != nil {
  2780. utils.ErrorLog(err.Error())
  2781. return
  2782. }
  2783. StartTime := theTimeUnix.Unix()
  2784. fmt.Println("startTIME", StartTime)
  2785. Remark := ""
  2786. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2787. remark, _ := dataBody["remark"].(string)
  2788. Remark = remark
  2789. }
  2790. var advices []*models.GroupAdvice
  2791. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  2792. utils.ErrorLog("advices")
  2793. return
  2794. }
  2795. adviceNames := dataBody["advices"].([]interface{})
  2796. for _, adviceNameMap := range adviceNames {
  2797. adviceNameM := adviceNameMap.(map[string]interface{})
  2798. var advice models.GroupAdvice
  2799. advice.Remark = Remark
  2800. advice.AdviceType = adviceType
  2801. advice.StartTime = StartTime
  2802. advice.AdviceDate = AdviceDate
  2803. advice.RecordDate = RecordDate
  2804. advice.Status = 1
  2805. advice.CreatedTime = time.Now().Unix()
  2806. advice.UpdatedTime = time.Now().Unix()
  2807. advice.StopState = 2
  2808. advice.ExecutionState = 2
  2809. advice.UserOrgId = adminUserInfo.CurrentOrgId
  2810. advice.PatientId = patient
  2811. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2812. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  2813. utils.ErrorLog("advice_name")
  2814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2815. return
  2816. }
  2817. adviceName, _ := adviceNameM["advice_name"].(string)
  2818. if len(adviceName) == 0 {
  2819. utils.ErrorLog("len(advice_name) == 0")
  2820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2821. return
  2822. }
  2823. advice.AdviceName = adviceName
  2824. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  2825. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  2826. advice.DrugSpec = drugSpec
  2827. }
  2828. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  2829. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  2830. advice.AdviceDesc = adviceDesc
  2831. }
  2832. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  2833. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  2834. advice.DrugSpecUnit = drugSpecUnit
  2835. }
  2836. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  2837. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  2838. // advice.SingleDose = singleDose
  2839. //}
  2840. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  2841. //single_dose := int64(adviceNameM["single_dose"].(float64))
  2842. advice.SingleDose = adviceNameM["single_dose"].(float64)
  2843. }
  2844. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  2845. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  2846. advice.SingleDoseUnit = singleDoseUnit
  2847. }
  2848. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  2849. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  2850. // advice.PrescribingNumber = prescribingNumber
  2851. //}
  2852. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  2853. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  2854. }
  2855. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  2856. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  2857. advice.PrescribingNumberUnit = prescribingNumberUnit
  2858. }
  2859. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  2860. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  2861. advice.DeliveryWay = deliveryWay
  2862. }
  2863. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  2864. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2865. advice.ExecutionFrequency = executionFrequency
  2866. }
  2867. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  2868. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  2869. advice.FrequencyType = frequency_type
  2870. }
  2871. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  2872. day_count := int64(adviceNameM["day_count"].(float64))
  2873. advice.DayCount = day_count
  2874. }
  2875. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  2876. way := int64(adviceNameM["way"].(float64))
  2877. advice.Way = way
  2878. }
  2879. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  2880. drug_id := int64(adviceNameM["drug_id"].(float64))
  2881. advice.DrugId = drug_id
  2882. }
  2883. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  2884. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  2885. advice.DrugNameId = drug_name_id
  2886. }
  2887. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  2888. week_day, _ := adviceNameM["week_day"].(string)
  2889. advice.WeekDay = week_day
  2890. }
  2891. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  2892. template_id, _ := adviceNameM["template_id"].(string)
  2893. advice.TemplateId = template_id
  2894. }
  2895. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  2896. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2897. advice.ExecutionFrequency = executionFrequency
  2898. }
  2899. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  2900. children := adviceNameM["child"].([]interface{})
  2901. if len(children) > 0 {
  2902. for _, childrenMap := range children {
  2903. childMap := childrenMap.(map[string]interface{})
  2904. var child models.GroupAdvice
  2905. child.Remark = Remark
  2906. child.AdviceType = adviceType
  2907. child.StartTime = StartTime
  2908. child.AdviceDate = AdviceDate
  2909. child.RecordDate = RecordDate
  2910. child.Status = 1
  2911. child.CreatedTime = time.Now().Unix()
  2912. child.UpdatedTime = time.Now().Unix()
  2913. child.StopState = 2
  2914. child.ExecutionState = 2
  2915. child.UserOrgId = adminUserInfo.CurrentOrgId
  2916. child.PatientId = patient
  2917. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  2918. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  2919. utils.ErrorLog("child advice_name")
  2920. return
  2921. }
  2922. childAdviceName, _ := childMap["advice_name"].(string)
  2923. if len(childAdviceName) == 0 {
  2924. utils.ErrorLog("len(child advice_name) == 0")
  2925. return
  2926. }
  2927. child.AdviceName = childAdviceName
  2928. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  2929. childAdviceDesc, _ := childMap["advice_desc"].(string)
  2930. child.AdviceDesc = childAdviceDesc
  2931. }
  2932. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  2933. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  2934. child.DrugSpec = childDrugSpec
  2935. }
  2936. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  2937. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  2938. child.DrugSpecUnit = childDrugSpecUnit
  2939. }
  2940. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  2941. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  2942. child.SingleDose = childSingleDose
  2943. }
  2944. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  2945. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  2946. child.SingleDoseUnit = childSingleDoseUnit
  2947. }
  2948. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  2949. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  2950. child.PrescribingNumber = childPrescribingNumber
  2951. }
  2952. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  2953. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  2954. child.PrescribingNumberUnit = childPrescribingNumberUnit
  2955. }
  2956. child.DeliveryWay = advice.DeliveryWay
  2957. child.ExecutionFrequency = advice.ExecutionFrequency
  2958. advice.Children = append(advice.Children, &child)
  2959. }
  2960. }
  2961. }
  2962. advices = append(advices, &advice)
  2963. }
  2964. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  2965. redis := service.RedisClient()
  2966. formatAdviceDate := theTime.Format("2006-01-02")
  2967. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  2968. redis.Set(key, "", time.Second)
  2969. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  2970. redis.Set(keyOne, "", time.Second)
  2971. keyFour := "scheduals_" + formatAdviceDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2972. redis.Set(keyFour, "", time.Second)
  2973. defer redis.Close()
  2974. if err != nil {
  2975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2976. return
  2977. }
  2978. c.ServeSuccessJSON(map[string]interface{}{
  2979. "msg": "ok",
  2980. "advices": list,
  2981. })
  2982. return
  2983. }
  2984. func (c *DialysisApiController) GetSolution() {
  2985. patient_id, _ := c.GetInt64("patient_id")
  2986. mode_id, _ := c.GetInt64("mode_id")
  2987. adminUserInfo := c.GetAdminUserInfo()
  2988. solution, err := service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  2989. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  2990. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, mode_id)
  2991. if err != nil {
  2992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2993. return
  2994. }
  2995. c.ServeSuccessJSON(map[string]interface{}{
  2996. "solution": solution,
  2997. "prescription": prescription,
  2998. "system_prescription": system_prescription,
  2999. })
  3000. }
  3001. func (c *DialysisApiController) GetSchedule() {
  3002. schedual_type, _ := c.GetInt64("schedual_type")
  3003. adminUserInfo := c.GetAdminUserInfo()
  3004. //timeLayout := "2006-01-02 15:04:05"
  3005. //
  3006. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  3007. //loc, _ := time.LoadLocation("Local")
  3008. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  3009. //scheduleTime := theStartTime.Unix()
  3010. scheduleTime, _ := c.GetInt64("record_date")
  3011. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  3012. c.ServeSuccessJSON(map[string]interface{}{
  3013. "number": deviceNumber,
  3014. })
  3015. }
  3016. func (this *DialysisApiController) GetTodayMonitor() {
  3017. thisTime := time.Now()
  3018. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3019. timeLayout := "2006-01-02 15:04:05"
  3020. loc, _ := time.LoadLocation("Local")
  3021. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3022. theAssessmentDateTime := theStartTime.Unix()
  3023. patientID, _ := this.GetInt64("patient_id")
  3024. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3025. adminInfo := this.GetAdminUserInfo()
  3026. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  3027. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  3028. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  3029. var ultrafiltration_rate float64
  3030. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  3031. //针对福建医师汇 获取透前评估预增脱水量
  3032. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  3033. fmt.Println("透前评估数据", evaluation)
  3034. if prescription.ID > 0 {
  3035. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3036. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3037. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  3038. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3039. record.UltrafiltrationRate = ultrafiltration_rate
  3040. }
  3041. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10121 {
  3042. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3043. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3044. record.UltrafiltrationRate = ultrafiltration_rate
  3045. }
  3046. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10234 {
  3047. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3048. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3049. record.UltrafiltrationRate = ultrafiltration_rate
  3050. }
  3051. if template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.CurrentOrgId == 9538
  3052. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3053. record.UltrafiltrationRate = ultrafiltration_rate
  3054. }
  3055. if template.TemplateId == 41 { //adminInfo.CurrentOrgId == 9538
  3056. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3057. record.UltrafiltrationRate = ultrafiltration_rate
  3058. }
  3059. if template.TemplateId == 43 { //adminInfo.CurrentOrgId == 9538
  3060. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3061. record.UltrafiltrationRate = ultrafiltration_rate
  3062. }
  3063. // 只针对方济医院
  3064. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  3065. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3066. ultrafiltration_rate = value
  3067. record.UltrafiltrationRate = ultrafiltration_rate
  3068. }
  3069. }
  3070. }
  3071. // record.UltrafiltrationRate = ultrafiltration_rate
  3072. record.UltrafiltrationVolume = 0
  3073. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  3074. if ultrafiltration_rate > 0 {
  3075. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3076. record.UltrafiltrationVolume = value
  3077. }
  3078. }
  3079. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 41 || template.TemplateId == 43 {
  3080. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  3081. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3082. record.UltrafiltrationVolume = ultrafiltration_volume
  3083. }
  3084. }
  3085. this.ServeSuccessJSON(map[string]interface{}{
  3086. "monitor": record,
  3087. })
  3088. }
  3089. func (c *DialysisApiController) UploadDryWeight() {
  3090. patient_id, _ := c.GetInt64("id")
  3091. dry_weight, _ := c.GetFloat("dry_weight")
  3092. doctor_id, _ := c.GetInt64("doctor_id")
  3093. remark := c.GetString("remark")
  3094. adminUserInfo := c.GetAdminUserInfo()
  3095. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  3096. fmt.Println(err)
  3097. if err == gorm.ErrRecordNotFound {
  3098. dryWeight := &models.SgjPatientDryweight{
  3099. PatientId: patient_id,
  3100. DryWeight: dry_weight,
  3101. Remakes: remark,
  3102. Ctime: time.Now().Unix(),
  3103. Mtime: time.Now().Unix(),
  3104. Creator: doctor_id,
  3105. Status: 1,
  3106. UserOrgId: adminUserInfo.CurrentOrgId,
  3107. AdjustedValue: "/",
  3108. UserId: adminUserInfo.AdminUser.Id,
  3109. }
  3110. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3111. loc, _ := time.LoadLocation("Local")
  3112. nowTime := time.Now()
  3113. nowDay := nowTime.Format("2006-01-02")
  3114. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3115. redis := service.RedisClient()
  3116. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  3117. redis.Set(keyOne, "", time.Second)
  3118. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3119. fmt.Println("敢提哦那个key23232332323223232332232323", key)
  3120. redis.Set(key, "", time.Second)
  3121. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3122. redis.Set(keyTwo, "", time.Second)
  3123. redis.Close()
  3124. if createErr == nil {
  3125. c.ServeSuccessJSON(map[string]interface{}{
  3126. "msg": "提交成功",
  3127. "weight": dryWeight,
  3128. })
  3129. }
  3130. } else {
  3131. dryWeight := &models.SgjPatientDryweight{
  3132. PatientId: patient_id,
  3133. DryWeight: dry_weight,
  3134. Remakes: remark,
  3135. Ctime: time.Now().Unix(),
  3136. Mtime: time.Now().Unix(),
  3137. Creator: doctor_id,
  3138. Status: 1,
  3139. UserOrgId: adminUserInfo.CurrentOrgId,
  3140. AdjustedValue: "/",
  3141. UserId: adminUserInfo.AdminUser.Id,
  3142. }
  3143. var value float64
  3144. value = dry_weight - weightAdjust.DryWeight
  3145. fmt.Println(value)
  3146. if value < 0 {
  3147. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  3148. } else if value == 0 {
  3149. dryWeight.AdjustedValue = "/"
  3150. } else if value > 0 {
  3151. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  3152. }
  3153. fmt.Println(value)
  3154. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3155. loc, _ := time.LoadLocation("Local")
  3156. nowTime := time.Now()
  3157. nowDay := nowTime.Format("2006-01-02")
  3158. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3159. redis := service.RedisClient()
  3160. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  3161. redis.Set(keyOne, "", time.Second)
  3162. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3163. redis.Set(key, "", time.Second)
  3164. fmt.Println("敢提哦那个key23232332323223232332232323", key)
  3165. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3166. redis.Set(keyTwo, "", time.Second)
  3167. redis.Close()
  3168. if createErr == nil {
  3169. c.ServeSuccessJSON(map[string]interface{}{
  3170. "msg": "提交成功",
  3171. "weight": dryWeight,
  3172. })
  3173. }
  3174. }
  3175. }
  3176. func (this *DialysisApiController) GetFuncPurview() {
  3177. adminUserInfo := this.GetAdminUserInfo()
  3178. user_id := adminUserInfo.AdminUser.Id
  3179. app_id := adminUserInfo.CurrentAppId
  3180. org_id := adminUserInfo.CurrentOrgId
  3181. create_url := this.GetString("create_url")
  3182. modify_url := this.GetString("modify_url")
  3183. modify_other_url := this.GetString("modify_other_url")
  3184. del_url := this.GetString("del_url")
  3185. del_other_url := this.GetString("del_other_url")
  3186. exce_url := this.GetString("exce_url")
  3187. check_url := this.GetString("check_url")
  3188. modify_exce_url := this.GetString("modify_exce_url")
  3189. module, _ := this.GetInt64("module", 0)
  3190. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  3191. var is_has_create bool
  3192. var is_has_modify bool
  3193. var is_has_modify_other bool
  3194. var is_has_del bool
  3195. var is_has_del_other bool
  3196. var is_has_exce bool
  3197. var is_has_check bool
  3198. var is_has_modify_exce bool
  3199. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  3200. if adminUserInfo.AdminUser.Id != org.Creator {
  3201. if app_role != nil {
  3202. if len(app_role.RoleIds) > 0 {
  3203. roles := strings.Split(app_role.RoleIds, ",")
  3204. var userRolePurviews string
  3205. for _, item := range roles {
  3206. role_id, _ := strconv.ParseInt(item, 10, 64)
  3207. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  3208. if len(userRolePurviews) == 0 {
  3209. userRolePurviews = purviews
  3210. } else {
  3211. userRolePurviews = userRolePurviews + "," + purviews
  3212. }
  3213. }
  3214. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  3215. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  3216. for _, item := range funcPurviews {
  3217. //for _, url := range strings.Split(item.Urlfor,","){
  3218. if strings.Split(item.Urlfor, ",")[1] == create_url {
  3219. is_has_create = true
  3220. }
  3221. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  3222. is_has_modify = true
  3223. }
  3224. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  3225. is_has_modify_other = true
  3226. }
  3227. if strings.Split(item.Urlfor, ",")[1] == del_url {
  3228. is_has_del = true
  3229. }
  3230. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  3231. is_has_del_other = true
  3232. }
  3233. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  3234. is_has_exce = true
  3235. }
  3236. if strings.Split(item.Urlfor, ",")[1] == check_url {
  3237. is_has_check = true
  3238. }
  3239. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  3240. is_has_modify_exce = true
  3241. }
  3242. }
  3243. } else {
  3244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  3245. return
  3246. }
  3247. this.ServeSuccessJSON(map[string]interface{}{
  3248. "is_has_create": is_has_create,
  3249. "is_has_modify": is_has_modify,
  3250. "is_has_modify_other": is_has_modify_other,
  3251. "is_has_del": is_has_del,
  3252. "is_has_del_other": is_has_del_other,
  3253. "is_has_exce": is_has_exce,
  3254. "is_has_check": is_has_check,
  3255. "is_has_modify_exce": is_has_modify_exce,
  3256. "module": module,
  3257. })
  3258. } else {
  3259. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  3260. return
  3261. }
  3262. } else {
  3263. this.ServeSuccessJSON(map[string]interface{}{
  3264. "is_has_create": true,
  3265. "is_has_modify": true,
  3266. "is_has_modify_other": true,
  3267. "is_has_del": true,
  3268. "is_has_del_other": true,
  3269. "is_has_exce": true,
  3270. "is_has_check": true,
  3271. "is_has_modify_exce": true,
  3272. "module": true,
  3273. })
  3274. }
  3275. }
  3276. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  3277. change_type, _ := this.GetInt64("type", 0)
  3278. record_date := this.GetString("record_time")
  3279. patient_id, _ := this.GetInt64("patient_id", 0)
  3280. timeLayout := "2006-01-02"
  3281. loc, _ := time.LoadLocation("Local")
  3282. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3283. record_time := theAdviceRecordTime.Unix()
  3284. adminUserInfo := this.GetAdminUserInfo()
  3285. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  3286. if err == nil {
  3287. if len(advices) == 0 {
  3288. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  3289. return
  3290. } else {
  3291. this.ServeSuccessJSON(map[string]interface{}{
  3292. "advices": advices,
  3293. "schedule": sch,
  3294. })
  3295. return
  3296. }
  3297. } else {
  3298. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3299. return
  3300. }
  3301. }
  3302. func (c *DialysisApiController) GetDialysisGoods() {
  3303. schedualDate := c.GetString("schedule_date")
  3304. schedule_type, _ := c.GetInt64("schedule_type")
  3305. partition_id, _ := c.GetInt64("partition_id")
  3306. page, _ := c.GetInt("page")
  3307. limit, _ := c.GetInt("limit")
  3308. keywords := c.GetString("keywords")
  3309. patient_id, _ := c.GetInt64("patient_id")
  3310. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  3311. if parseDateErr != nil && len(schedualDate) != 0 {
  3312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3313. return
  3314. }
  3315. schedualEndDate := int64(0)
  3316. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  3317. if parseDateErr != nil && len(schedualDate) != 0 {
  3318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3319. return
  3320. }
  3321. schedualEndDate = endDate.Unix()
  3322. adminUser := c.GetAdminUserInfo()
  3323. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  3324. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  3325. if err == gorm.ErrRecordNotFound {
  3326. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate)
  3327. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3328. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  3329. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  3330. item.LastAutomaticReduceDetail = goodUser
  3331. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3332. }
  3333. c.ServeSuccessJSON(map[string]interface{}{
  3334. "dialysis_goods": dialysisGoods,
  3335. "good_type": goodTypes,
  3336. "total": total,
  3337. })
  3338. return
  3339. } else if err == nil {
  3340. //获取当天排班的每个患者的库存使用情况
  3341. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate)
  3342. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3343. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  3344. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  3345. fmt.Println(goodUser)
  3346. fmt.Println(lastGoodUserDetial)
  3347. item.LastAutomaticReduceDetail = goodUser
  3348. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3349. }
  3350. if err == nil {
  3351. c.ServeSuccessJSON(map[string]interface{}{
  3352. "dialysis_goods": dialysisGoods,
  3353. "good_type": goodTypes,
  3354. "total": total,
  3355. })
  3356. return
  3357. } else {
  3358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3359. return
  3360. }
  3361. } else if err != nil {
  3362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3363. return
  3364. }
  3365. }
  3366. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  3367. start_time := c.GetString("start_time")
  3368. end_time := c.GetString("end_time")
  3369. timeLayout := "2006-01-02"
  3370. loc, _ := time.LoadLocation("Local")
  3371. var theStartTime int64
  3372. if len(start_time) > 0 {
  3373. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3374. if err != nil {
  3375. utils.ErrorLog(err.Error())
  3376. }
  3377. theStartTime = theTime.Unix()
  3378. }
  3379. var theEndtTime int64
  3380. if len(end_time) > 0 {
  3381. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3382. if err != nil {
  3383. utils.ErrorLog(err.Error())
  3384. }
  3385. theEndtTime = theTime.Unix()
  3386. }
  3387. adminUser := c.GetAdminUserInfo()
  3388. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  3389. if err == nil {
  3390. c.ServeSuccessJSON(map[string]interface{}{
  3391. "stock_out": outInfo,
  3392. })
  3393. return
  3394. } else {
  3395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3396. return
  3397. }
  3398. }