dialysis_api_controller.go 127KB

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