dialysis_api_controller.go 176KB

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