dialysis_api_controller.go 172KB

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