dialysis_api_controller.go 160KB

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