dialysis_api_controller.go 158KB

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