dialysis_api_controller.go 134KB

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