dialysis_api_controller.go 127KB

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