dialysis_api_controller.go 133KB

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