dialysis_api_controller.go 119KB

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