dialysis_api_controller.go 129KB

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