dialysis_api_controller.go 131KB

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