dialysis_api_controller.go 119KB

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