dialysis_api_controller.go 234KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157
  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. beego.Router("/api/patient/getsolutionlistbyorgid", &DialysisApiController{}, "Get:GetSolutionListByOrgId")
  71. beego.Router("/api/schedule/excutiondoctoradvice", &DialysisApiController{}, "Get:ExcutionDoctorAdvice")
  72. beego.Router("/api/schedule/checknewdoctoradvice", &DialysisApiController{}, "Get:CheckNewDoctorAdvice")
  73. beego.Router("/api/schedule/settlenewdoctoradvice", &DialysisApiController{}, "Get:SettleNewDoctorAdvice")
  74. beego.Router("/api/schedule/excutiondoctoradvicebyid", &DialysisApiController{}, "Get:ExcutionDoctorAdviceById")
  75. beego.Router("/api/patient/getdialysisadvicetoday", &DialysisApiController{}, "Get:GetDialysisAdviceToday")
  76. beego.Router("/api/schedule/getmobileschedulelist", &DialysisApiController{}, "Get:GetMobileScheduleList")
  77. beego.Router("/api/patient/savedialysisInformationsetting", &DialysisApiController{}, "Get:SaveDialysisInformationSetting")
  78. beego.Router("/api/patient/getdialyisinformationsetting", &DialysisApiController{}, "Get:GetDialysisInformationSetting")
  79. }
  80. func (c *DialysisApiController) GetQueueCall() {
  81. adminUserInfo := c.GetAdminUserInfo()
  82. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  83. if queueConfig.ID <= 0 {
  84. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  85. queueConfig.Qhsj = 10
  86. queueConfig.Jzdcbbcs = 3
  87. queueConfig.Jzbbsy = 1
  88. queueConfig.Jzjhyc = 0
  89. queueConfig.Sjdcbbcs = 3
  90. queueConfig.Sjbbsy = 0
  91. queueConfig.Sjjhyc = 0
  92. queueConfig.Txxqyxs = 0
  93. queueConfig.Txglsyxs = 0
  94. }
  95. c.ServeSuccessJSON(map[string]interface{}{
  96. "queue_config": queueConfig,
  97. })
  98. }
  99. func (c *DialysisApiController) UpdateQueueCall() {
  100. adminUserInfo := c.GetAdminUserInfo()
  101. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  102. if queueConfig.ID <= 0 {
  103. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  104. queueConfig.Qhsj = 10
  105. queueConfig.Jzdcbbcs = 3
  106. queueConfig.Jzbbsy = 1
  107. queueConfig.Jzjhyc = 0
  108. queueConfig.Sjdcbbcs = 3
  109. queueConfig.Sjbbsy = 0
  110. queueConfig.Sjjhyc = 0
  111. queueConfig.Txxqyxs = 0
  112. queueConfig.Txglsyxs = 0
  113. queueConfig.CreateTime = time.Now().Unix()
  114. queueConfig.UpdateTime = time.Now().Unix()
  115. }
  116. qhsj, _ := c.GetInt64("qhsj", 0)
  117. if qhsj > 0 {
  118. queueConfig.Qhsj = qhsj
  119. }
  120. jzdcbbcs, _ := c.GetInt64("jzdcbbcs", 0)
  121. if jzdcbbcs > 0 {
  122. queueConfig.Jzdcbbcs = jzdcbbcs
  123. }
  124. jzbbsy, _ := c.GetInt64("jzbbsy", 0)
  125. if jzbbsy > 0 {
  126. queueConfig.Jzbbsy = jzbbsy
  127. }
  128. jzjhyc, _ := c.GetInt64("jzjhyc", 0)
  129. queueConfig.Jzjhyc = jzjhyc
  130. sjdcbbcs, _ := c.GetInt64("sjdcbbcs", 0)
  131. if sjdcbbcs > 0 {
  132. queueConfig.Sjdcbbcs = sjdcbbcs
  133. }
  134. sjbbsy, _ := c.GetInt64("sjbbsy", 0)
  135. if sjbbsy > 0 {
  136. queueConfig.Sjbbsy = sjbbsy
  137. }
  138. sjjhyc, _ := c.GetInt64("sjjhyc", 0)
  139. queueConfig.Sjjhyc = sjjhyc
  140. txxqyxs, _ := c.GetInt64("txxqyxs", 0)
  141. queueConfig.Txxqyxs = txxqyxs
  142. txglsyxs, _ := c.GetInt64("txglsyxs", 0)
  143. queueConfig.Txglsyxs = txglsyxs
  144. queueConfig.UpdateTime = time.Now().Unix()
  145. service.UpDateQueueCallInfo(queueConfig)
  146. c.ServeSuccessJSON(map[string]interface{}{
  147. "queue_config": queueConfig,
  148. })
  149. }
  150. func (c *DialysisApiController) PostPrescription() {
  151. patient, _ := c.GetInt64("patient_id", 0)
  152. recordDateStr := c.GetString("record_date")
  153. if patient <= 0 {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  155. return
  156. }
  157. adminUserInfo := c.GetAdminUserInfo()
  158. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  159. if patientInfo.ID == 0 {
  160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  161. return
  162. }
  163. if len(recordDateStr) == 0 {
  164. recordDateStr = time.Now().Format("2006-01-02")
  165. }
  166. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  167. if parseDateErr != nil {
  168. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  170. return
  171. }
  172. mode_id, _ := c.GetInt64("mode_id", 0)
  173. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  174. dialyzer, _ := c.GetInt64("dialyzer", 0)
  175. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  176. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  177. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  178. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  179. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  180. replacement_way, _ := c.GetInt64("replacement_way", 0)
  181. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  182. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  183. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  184. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  185. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  186. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  187. kalium, _ := c.GetFloat("kalium", 0)
  188. sodium, _ := c.GetFloat("sodium", 0)
  189. replacement_total, _ := c.GetFloat("replacement_total", 0)
  190. calcium, _ := c.GetFloat("calcium", 0)
  191. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  192. glucose, _ := c.GetFloat("glucose", 0)
  193. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  194. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  195. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  196. conductivity, _ := c.GetFloat("conductivity", 0)
  197. remark := c.GetString("remark")
  198. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  199. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  200. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  201. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  202. body_fluid, _ := c.GetInt64("body_fluid", 0)
  203. special_medicine, _ := c.GetInt64("special_medicine", 0)
  204. special_medicine_other := c.GetString("special_medicine_other")
  205. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  206. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  207. blood_access, _ := c.GetInt64("blood_access", 0)
  208. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  209. body_fluid_other := c.GetString("body_fluid_other")
  210. target_ktv, _ := c.GetFloat("target_ktv", 0)
  211. niprocart, _ := c.GetInt64("niprocart", 0)
  212. jms, _ := c.GetInt64("jms", 0)
  213. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  214. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  215. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  216. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  217. filtryzer, _ := c.GetInt64("filtryzer", 0)
  218. dialyzers, _ := c.GetInt64("dialyzers", 0)
  219. injector, _ := c.GetInt64("injector", 0)
  220. bloodlines, _ := c.GetInt64("bloodlines", 0)
  221. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  222. safe_package, _ := c.GetInt64("package", 0)
  223. a_liquid, _ := c.GetInt64("a_liquid", 0)
  224. preImpules, _ := c.GetFloat("pre_impulse", 0)
  225. fmt.Println("", preImpules)
  226. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  227. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  228. //heparin_sodium := c.GetString("heparin_sodium")
  229. //fmt.Println("肝素钠",heparin_sodium)
  230. //nucleoprotamine := c.GetString("nucleoprotamine")
  231. //fmt.Println("鱼精蛋白",nucleoprotamine)
  232. //push_the_protamine := c.GetString("push_the_protamine")
  233. //fmt.Println("下机前推注鱼精蛋白",push_the_protamine)
  234. // var prescription_doctor int64
  235. blood := c.GetString("blood")
  236. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  237. dialysis_irrigation := c.GetString("dialysis_irrigation")
  238. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  239. displace_speed := c.GetString("displace_speed")
  240. illness, _ := c.GetInt64("illness")
  241. amylaceum := c.GetString("amylaceum")
  242. single_time := c.GetString("single_time")
  243. single_water := c.GetString("single_water")
  244. replacement_flow := c.GetString("replacement_flow")
  245. plasma_separator := c.GetString("plasma_separator")
  246. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  247. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  248. oxygen_flow := c.GetString("oxygen_flow")
  249. oxygen_time := c.GetString("oxygen_time")
  250. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  251. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  252. puncture_needle := c.GetString("puncture_needle")
  253. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  254. epo := c.GetString("epo")
  255. epo_count, _ := c.GetFloat("epo_count", 0)
  256. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  257. admin_user_id, _ := c.GetInt64("admin_user_id")
  258. is_water, _ := c.GetInt64("is_water")
  259. drhy_water := c.GetString("drhy_water")
  260. dry_water_hour := c.GetString("dry_water_hour")
  261. water_machine := c.GetString("water_machine")
  262. add_amount, _ := c.GetFloat("add_amount")
  263. reduce_amount, _ := c.GetFloat("reduce_amount")
  264. dialysis_remark := c.GetString("dialysis_remark")
  265. prescribing_number, _ := c.GetFloat("prescribing_number")
  266. treatment_remark := c.GetString("treatment_remark")
  267. prescription_sodium := c.GetString("prescription_sodium")
  268. start_sodium := c.GetString("start_sodium")
  269. sodium_curve := c.GetString("sodium_curve")
  270. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  271. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  272. prescription_water, _ := c.GetFloat("prescription_water")
  273. dialysis_strainer := c.GetString("dialysis_strainer")
  274. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  275. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  276. //if template.TemplateId == 2 || template.TemplateId == 6 {
  277. // if appRole.UserType == 3 {
  278. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  279. // if getPermissionErr != nil {
  280. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  281. // return
  282. // } else if headNursePermission == nil {
  283. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  284. // return
  285. // }
  286. // }
  287. //}
  288. prescription := models.DialysisPrescription{
  289. UserOrgId: adminUserInfo.CurrentOrgId,
  290. PatientId: patient,
  291. RecordDate: recordDate.Unix(),
  292. ModeId: mode_id,
  293. DialysisDuration: dialysis_duration,
  294. Dialyzer: dialyzer,
  295. ReplacementTotal: replacement_total,
  296. PerfusionApparatus: perfusion_apparatus,
  297. BloodFlowVolume: blood_flow_volume,
  298. DewaterAmount: dewater_amount,
  299. DisplaceLiqui: displace_liqui,
  300. ReplacementWay: replacement_way,
  301. Anticoagulant: anticoagulant,
  302. AnticoagulantShouji: anticoagulant_shouji,
  303. AnticoagulantWeichi: anticoagulant_weichi,
  304. AnticoagulantZongliang: anticoagulant_zongliang,
  305. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  306. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  307. Kalium: kalium,
  308. Sodium: sodium,
  309. Calcium: calcium,
  310. Bicarbonate: bicarbonate,
  311. Glucose: glucose,
  312. // DryWeight: dry_weight,
  313. DialysateFlow: dialysate_flow,
  314. DialysateTemperature: dialysate_temperature,
  315. Conductivity: conductivity,
  316. Remark: remark,
  317. Status: 1,
  318. CreatedTime: time.Now().Unix(),
  319. UpdatedTime: time.Now().Unix(),
  320. DialysisDurationMinute: dialysisDurationMinute,
  321. DialysisDurationHour: dialysisDurationHour,
  322. TargetUltrafiltration: targetUltrafiltration,
  323. DialysateFormulation: dialysateFormulation,
  324. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  325. BodyFluid: body_fluid,
  326. SpecialMedicine: special_medicine,
  327. SpecialMedicineOther: special_medicine_other,
  328. DisplaceLiquiPart: displace_liqui_part,
  329. DisplaceLiquiValue: displace_liqui_value,
  330. BloodAccess: blood_access,
  331. Ultrafiltration: ultrafiltration,
  332. BodyFluidOther: body_fluid_other,
  333. TargetKtv: target_ktv,
  334. Niprocart: niprocart,
  335. Jms: jms,
  336. FistulaNeedleSet: fistula_needle_set,
  337. FistulaNeedleSet16: fistula_needle_set_16,
  338. Hemoperfusion: hemoperfusion,
  339. DialyserSterilised: dialyser_sterilised,
  340. Filtryzer: filtryzer,
  341. Dialyzers: dialyzers,
  342. Injector: injector,
  343. Bloodlines: bloodlines,
  344. TubingHemodialysis: tubing_hemodialysis,
  345. Package: safe_package,
  346. ALiquid: a_liquid,
  347. PreImpulse: preImpules,
  348. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  349. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  350. Blood: blood,
  351. DialysisDialyszers: dialysis_dialyszers,
  352. DialysisIrrigation: dialysis_irrigation,
  353. AntioxidantCommodityName: antioxidant_commodity_name,
  354. DisplaceSpeed: displace_speed,
  355. Illness: illness,
  356. Amylaceum: amylaceum,
  357. SingleTime: single_time,
  358. SingleWater: single_water,
  359. ReplacementFlow: replacement_flow,
  360. PlasmaSeparator: plasma_separator,
  361. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  362. OxygenFlow: oxygen_flow,
  363. OxygenUptake: oxygen_uptake,
  364. OxygenTime: oxygen_time,
  365. HemodialysisPipelines: hemodialysis_pipelines,
  366. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  367. PunctureNeedle: puncture_needle,
  368. PunctureNeedleCount: puncture_needle_count,
  369. Epo: epo,
  370. EpoCount: epo_count,
  371. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  372. AdminUserId: admin_user_id,
  373. IsWater: is_water,
  374. DrhyWater: drhy_water,
  375. DryWaterHour: dry_water_hour,
  376. WaterMachine: water_machine,
  377. AddAmount: add_amount,
  378. ReduceAmount: reduce_amount,
  379. DialysisRemark: dialysis_remark,
  380. PrescribingNumber: prescribing_number,
  381. TreatmentRemark: treatment_remark,
  382. PrescriptionSodium: prescription_sodium,
  383. StartSodium: start_sodium,
  384. SodiumCurve: sodium_curve,
  385. DialysisFluidFlow: dialysis_fluid_flow,
  386. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  387. PrescriptionWater: prescription_water,
  388. DialysisStrainer: dialysis_strainer,
  389. }
  390. //长沙南雅医院,自动生成抗凝剂的临时处方
  391. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  392. if prescribing_number == 0 {
  393. prescribing_number = 1
  394. }
  395. advice := models.DoctorAdvice{
  396. UserOrgId: adminUserInfo.CurrentOrgId,
  397. PatientId: patient,
  398. GroupNo: 0,
  399. AdviceType: 2,
  400. RecordDate: recordDate.Unix(),
  401. AdviceDate: recordDate.Unix(),
  402. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  403. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  404. AdviceDesc: "",
  405. ReminderDate: 0,
  406. SingleDose: anticoagulant_zongliang,
  407. SingleDoseUnit: "iu",
  408. DrugSpec: 0,
  409. DrugSpecUnit: "",
  410. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  411. PrescribingNumberUnit: "支",
  412. DeliveryWay: "静脉注射",
  413. ExecutionFrequency: "上机前",
  414. AdviceDoctor: 0,
  415. Status: 1,
  416. CreatedTime: time.Now().Unix(),
  417. UpdatedTime: time.Now().Unix(),
  418. IsPrescription: 1,
  419. ExecutionState: 2,
  420. StopState: 2,
  421. IsSettle: 2,
  422. }
  423. // 查询排班信息
  424. schedulePatient, _ := service.GetScheduleByPatient(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  425. if schedulePatient.ID > 0 {
  426. if schedulePatient.ScheduleType == 1 {
  427. advice.StartTime = recordDate.Unix() + 6.5*60*60
  428. }
  429. if schedulePatient.ScheduleType == 2 {
  430. advice.StartTime = recordDate.Unix() + 11*60*60
  431. }
  432. }
  433. // 抗凝剂名称
  434. switch anticoagulant {
  435. case 1:
  436. advice.AdviceName = "无肝素"
  437. break
  438. case 2:
  439. advice.AdviceName = "普通肝素"
  440. break
  441. case 3:
  442. advice.AdviceName = "低分子肝素"
  443. break
  444. case 4:
  445. advice.AdviceName = "阿加曲班"
  446. break
  447. case 5:
  448. advice.AdviceName = "枸橼酸钠"
  449. break
  450. case 6:
  451. advice.AdviceName = "低分子肝素钙"
  452. break
  453. case 7:
  454. advice.AdviceName = "低分子肝素钠"
  455. break
  456. case 8:
  457. advice.AdviceName = "依诺肝素"
  458. break
  459. case 9:
  460. advice.AdviceName = "达肝素"
  461. break
  462. case 10:
  463. advice.AdviceName = "体外抗凝"
  464. break
  465. case 11:
  466. advice.AdviceName = "那曲肝素"
  467. break
  468. case 12:
  469. advice.AdviceName = "无抗凝剂"
  470. break
  471. }
  472. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  473. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 {
  474. advice.AdviceDoctor = appRole.AdminUserId
  475. }
  476. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  477. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  478. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  479. advice.AdviceName = "低分子肝素钠注射液"
  480. // 修改患者临时医嘱里的抗凝剂医嘱
  481. advice.ID = advicePrescription.ID
  482. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  483. //service.UpdateDoctorAdvice(&advice)
  484. } else {
  485. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  486. advice.AdviceName = "低分子肝素钠注射液"
  487. // 新增患者临时医嘱里的抗凝剂医嘱
  488. service.CreateDoctorAdvice(&advice)
  489. }
  490. }
  491. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  492. redis := service.RedisClient()
  493. //清空key 值
  494. redis.Set(key, "", time.Second)
  495. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  496. redis.Set(keyOne, "", time.Second)
  497. }
  498. if appRole.UserType == 2 || appRole.UserType == 1 {
  499. prescription.PrescriptionDoctor = appRole.AdminUserId
  500. }
  501. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  502. if dialysisPrescription.ID == 0 { //新增
  503. if mode_id > 0 {
  504. var str string
  505. //查找该机构用的是什么透析器
  506. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  507. if filedConfig.ID > 0 {
  508. str = dialyzerPerfusionApparatus
  509. } else {
  510. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  511. }
  512. if adminUserInfo.CurrentOrgId == 10346 {
  513. service.ModifyScheduleModeOne(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  514. } else {
  515. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  516. }
  517. }
  518. prescription.Creater = adminUserInfo.AdminUser.Id
  519. //针对河间咸得
  520. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  521. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  522. prescription.DisplaceLiquiPart = 0
  523. prescription.DisplaceLiquiValue = 0
  524. }
  525. }
  526. if adminUserInfo.CurrentOrgId == 10340 && prescription.AdminUserId == 0 {
  527. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  528. }
  529. err := service.AddSigleRecord(&prescription)
  530. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  531. redis := service.RedisClient()
  532. //清空key 值
  533. redis.Set(key, "", time.Second)
  534. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  535. redis.Set(keyTwo, "", time.Second)
  536. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  537. redis.Set(keyThree, "", time.Second)
  538. defer redis.Close()
  539. if err == nil {
  540. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  541. if updateErr != nil {
  542. utils.ErrorLog("%v", updateErr)
  543. }
  544. c.ServeSuccessJSON(map[string]interface{}{
  545. "prescription": &prescription,
  546. })
  547. } else {
  548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  549. }
  550. } else { //修改
  551. if mode_id > 0 {
  552. var str string
  553. //查找该机构用的是什么透析器
  554. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  555. if filedConfig.ID > 0 {
  556. str = dialyzerPerfusionApparatus
  557. } else {
  558. str = dialysis_dialyszers + "/" + dialysis_irrigation
  559. }
  560. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  561. }
  562. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  563. //if template.TemplateId == 1 {
  564. // if dialysisPrescription.Creater > 0 && dialysisPrescription.Creater != adminUserInfo.AdminUser.Id {
  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. if appRole.UserType == 2 || appRole.UserType == 1 {
  576. prescription_doctor := adminUserInfo.AdminUser.Id
  577. prescription.PrescriptionDoctor = prescription_doctor
  578. }
  579. if dialysisPrescription.Creater == 0 { //体重称
  580. prescription.Creater = adminUserInfo.AdminUser.Id
  581. } else {
  582. prescription.Creater = dialysisPrescription.Creater
  583. }
  584. prescription.CreatedTime = dialysisPrescription.CreatedTime
  585. prescription.UpdatedTime = time.Now().Unix()
  586. prescription.Modifier = adminUserInfo.AdminUser.Id
  587. prescription.ID = dialysisPrescription.ID
  588. updateErr := service.UpDateDialysisPrescription(&prescription)
  589. //修改处方
  590. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  591. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  592. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  593. if advicePrescription.ID > 0 {
  594. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  595. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  596. redis := service.RedisClient()
  597. defer redis.Close()
  598. //清空key 值
  599. redis.Set(key, "", time.Second)
  600. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  601. redis.Set(keyOne, "", time.Second)
  602. }
  603. }
  604. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  605. redis := service.RedisClient()
  606. defer redis.Close()
  607. //清空key 值
  608. redis.Set(key, "", time.Second)
  609. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  610. redis.Set(keyOne, "", time.Second)
  611. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  612. redis.Set(keyThree, "", time.Second)
  613. if updateErr == nil {
  614. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  615. if updateErr != nil {
  616. utils.ErrorLog("%v", updateErr)
  617. }
  618. c.ServeSuccessJSON(map[string]interface{}{
  619. "prescription": &prescription,
  620. })
  621. } else {
  622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  623. }
  624. }
  625. }
  626. func (c *DialysisApiController) PostSoulution() {
  627. patient, _ := c.GetInt64("patient", 0)
  628. recordDateStr := c.GetString("record_date")
  629. if patient <= 0 {
  630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  631. return
  632. }
  633. adminUserInfo := c.GetAdminUserInfo()
  634. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  635. if patientInfo.ID == 0 {
  636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  637. return
  638. }
  639. if len(recordDateStr) == 0 {
  640. recordDateStr = time.Now().Format("2006-01-02")
  641. }
  642. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  643. if parseDateErr != nil {
  644. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  646. return
  647. }
  648. mode_id, _ := c.GetInt64("mode_id", 0)
  649. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  650. dialyzer, _ := c.GetInt64("dialyzer", 0)
  651. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  652. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  653. replacement_total, _ := c.GetFloat("replacement_total", 0)
  654. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  655. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  656. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  657. replacement_way, _ := c.GetInt64("replacement_way", 0)
  658. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  659. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  660. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  661. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  662. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  663. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  664. kalium, _ := c.GetFloat("kalium", 0)
  665. sodium, _ := c.GetFloat("sodium", 0)
  666. calcium, _ := c.GetFloat("calcium", 0)
  667. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  668. glucose, _ := c.GetFloat("glucose", 0)
  669. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  670. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  671. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  672. conductivity, _ := c.GetFloat("conductivity", 0)
  673. remark := c.GetString("remark")
  674. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  675. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  676. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  677. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  678. body_fluid, _ := c.GetInt64("body_fluid", 0)
  679. special_medicine, _ := c.GetInt64("special_medicine", 0)
  680. special_medicine_other := c.GetString("special_medicine_other")
  681. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  682. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  683. blood_access, _ := c.GetInt64("blood_access", 0)
  684. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  685. body_fluid_other := c.GetString("body_fluid_other")
  686. target_ktv, _ := c.GetFloat("target_ktv", 0)
  687. niprocart, _ := c.GetInt64("niprocart", 0)
  688. jms, _ := c.GetInt64("jms", 0)
  689. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  690. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  691. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  692. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  693. filtryzer, _ := c.GetInt64("filtryzer", 0)
  694. dialyzers, _ := c.GetInt64("dialyzers", 0)
  695. injector, _ := c.GetInt64("injector", 0)
  696. bloodlines, _ := c.GetInt64("bloodlines", 0)
  697. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  698. safe_package, _ := c.GetInt64("package", 0)
  699. a_liquid, _ := c.GetInt64("a_liquid", 0)
  700. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  701. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  702. blood := c.GetString("blood")
  703. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  704. dialysis_irrigation := c.GetString("dialysis_irrigation")
  705. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  706. displace_speed := c.GetString("displace_speed")
  707. illness, _ := c.GetInt64("illness")
  708. amylaceum := c.GetString("amylaceum")
  709. single_time := c.GetString("single_time")
  710. single_water := c.GetString("single_water")
  711. replacement_flow := c.GetString("replacement_flow")
  712. plasma_separator := c.GetString("plasma_separator")
  713. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  714. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  715. oxygen_flow := c.GetString("oxygen_flow")
  716. oxygen_time := c.GetString("oxygen_time")
  717. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  718. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  719. puncture_needle := c.GetString("puncture_needle")
  720. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  721. epo := c.GetString("epo")
  722. epo_count, _ := c.GetFloat("epo_count", 0)
  723. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  724. impulse := c.GetString("impulse")
  725. preImpules, parseDateErr := strconv.ParseFloat(impulse, 64)
  726. admin_user_id, _ := c.GetInt64("admin_user_id")
  727. fmt.Println("", preImpules)
  728. is_water, _ := c.GetInt64("is_water")
  729. dry_water_hour := c.GetString("dry_water_hour")
  730. drhy_water := c.GetString("drhy_water")
  731. water_machine := c.GetString("water_machine")
  732. add_amount, _ := c.GetFloat("add_amount")
  733. reduce_amount, _ := c.GetFloat("reduce_amount")
  734. dialysis_remark := c.GetString("dialysis_remark")
  735. prescribing_number, _ := c.GetFloat("prescribing_number")
  736. treatment_remark := c.GetString("treatment_remark")
  737. prescription_sodium := c.GetString("prescription_sodium")
  738. start_sodium := c.GetString("start_sodium")
  739. sodium_curve := c.GetString("sodium_curve")
  740. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  741. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  742. prescription_water, _ := c.GetFloat("prescription_water")
  743. dialysis_strainer := c.GetString("dialysis_strainer")
  744. var prescription_doctor int64
  745. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  746. if appRole.UserType == 2 || appRole.UserType == 1 {
  747. prescription_doctor = appRole.AdminUserId
  748. }
  749. if mode_id > 0 {
  750. var str string
  751. //查找该机构用的是什么透析器
  752. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  753. if filedConfig.ID > 0 {
  754. str = dialyzerPerfusionApparatus
  755. } else {
  756. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  757. }
  758. if adminUserInfo.CurrentOrgId == 10346 {
  759. service.ModifyScheduleModeOne(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  760. } else {
  761. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  762. }
  763. }
  764. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  765. //
  766. //if template.TemplateId == 2 || template.TemplateId == 6 {
  767. // if appRole.UserType == 3 {
  768. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  769. // if getPermissionErr != nil {
  770. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  771. // return
  772. // } else if headNursePermission == nil {
  773. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  774. // return
  775. // }
  776. // }
  777. //}
  778. prescription := models.DialysisPrescription{
  779. UserOrgId: adminUserInfo.CurrentOrgId,
  780. PatientId: patient,
  781. RecordDate: recordDate.Unix(),
  782. ModeId: mode_id,
  783. DialysisDuration: dialysis_duration,
  784. Dialyzer: dialyzer,
  785. PerfusionApparatus: perfusion_apparatus,
  786. BloodFlowVolume: blood_flow_volume,
  787. DewaterAmount: dewater_amount,
  788. DisplaceLiqui: displace_liqui,
  789. ReplacementWay: replacement_way,
  790. Anticoagulant: anticoagulant,
  791. AnticoagulantShouji: anticoagulant_shouji,
  792. AnticoagulantWeichi: anticoagulant_weichi,
  793. AnticoagulantZongliang: anticoagulant_zongliang,
  794. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  795. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  796. Kalium: kalium,
  797. Sodium: sodium,
  798. Calcium: calcium,
  799. Bicarbonate: bicarbonate,
  800. Glucose: glucose,
  801. // DryWeight: dry_weight,
  802. DialysateFlow: dialysate_flow,
  803. DialysateTemperature: dialysate_temperature,
  804. Conductivity: conductivity,
  805. Remark: remark,
  806. PrescriptionDoctor: prescription_doctor,
  807. Status: 1,
  808. CreatedTime: time.Now().Unix(),
  809. UpdatedTime: time.Now().Unix(),
  810. DialysisDurationMinute: dialysisDurationMinute,
  811. DialysisDurationHour: dialysisDurationHour,
  812. TargetUltrafiltration: targetUltrafiltration,
  813. DialysateFormulation: dialysateFormulation,
  814. ReplacementTotal: replacement_total,
  815. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  816. BodyFluid: body_fluid,
  817. SpecialMedicine: special_medicine,
  818. SpecialMedicineOther: special_medicine_other,
  819. DisplaceLiquiPart: displace_liqui_part,
  820. DisplaceLiquiValue: displace_liqui_value,
  821. BloodAccess: blood_access,
  822. Ultrafiltration: ultrafiltration,
  823. BodyFluidOther: body_fluid_other,
  824. TargetKtv: target_ktv,
  825. Niprocart: niprocart,
  826. Jms: jms,
  827. FistulaNeedleSet: fistula_needle_set,
  828. FistulaNeedleSet16: fistula_needle_set_16,
  829. Hemoperfusion: hemoperfusion,
  830. DialyserSterilised: dialyser_sterilised,
  831. Filtryzer: filtryzer,
  832. Dialyzers: dialyzers,
  833. Injector: injector,
  834. Bloodlines: bloodlines,
  835. TubingHemodialysis: tubing_hemodialysis,
  836. Package: safe_package,
  837. ALiquid: a_liquid,
  838. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  839. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  840. Blood: blood,
  841. DialysisIrrigation: dialysis_irrigation,
  842. DialysisDialyszers: dialysis_dialyszers,
  843. AntioxidantCommodityName: antioxidant_commodity_name,
  844. DisplaceSpeed: displace_speed,
  845. Illness: illness,
  846. Amylaceum: amylaceum,
  847. SingleTime: single_time,
  848. SingleWater: single_water,
  849. ReplacementFlow: replacement_flow,
  850. PlasmaSeparator: plasma_separator,
  851. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  852. OxygenTime: oxygen_time,
  853. OxygenUptake: oxygen_uptake,
  854. OxygenFlow: oxygen_flow,
  855. HemodialysisPipelines: hemodialysis_pipelines,
  856. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  857. PunctureNeedle: puncture_needle,
  858. PunctureNeedleCount: puncture_needle_count,
  859. Epo: epo,
  860. EpoCount: epo_count,
  861. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  862. PreImpulse: preImpules,
  863. AdminUserId: admin_user_id,
  864. IsWater: is_water,
  865. DryWaterHour: dry_water_hour,
  866. DrhyWater: drhy_water,
  867. WaterMachine: water_machine,
  868. AddAmount: add_amount,
  869. ReduceAmount: reduce_amount,
  870. DialysisRemark: dialysis_remark,
  871. PrescribingNumber: prescribing_number,
  872. StartSodium: start_sodium,
  873. PrescriptionSodium: prescription_sodium,
  874. SodiumCurve: sodium_curve,
  875. TreatmentRemark: treatment_remark,
  876. DialysisFluidFlow: dialysis_fluid_flow,
  877. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  878. PrescriptionWater: prescription_water,
  879. DialysisStrainer: dialysis_strainer,
  880. }
  881. //查询最近透析准备表里是否存在 透析器 灌流器
  882. //splitStr := strings.Split(dialysis_dialyszers, ",")
  883. //
  884. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  885. //
  886. //mation, _ := service.GetGoodInfoMation(adminUserInfo.CurrentOrgId)
  887. //if len(mation)>0{
  888. // for _, item := range splitStr {
  889. // for _,it := range mation{
  890. // if(item == it.SpecificationName){
  891. //
  892. // //查询最近一次的透析器
  893. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  894. //
  895. // if errcode == gorm.ErrRecordNotFound{
  896. // //插入数据
  897. // prepare := models.DialysisBeforePrepare{
  898. // UserOrgId: adminUserInfo.CurrentOrgId,
  899. // PatientId: patient,
  900. // RecordDate: recordDate.Unix(),
  901. // GoodTypeId: it.GoodTypeId,
  902. // GoodId: it.ID,
  903. // Count: 1,
  904. // Ctime: time.Now().Unix(),
  905. // Creater: adminUserInfo.AdminUser.Id,
  906. // Status:1,
  907. //
  908. // }
  909. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  910. // fmt.Println("",errcode)
  911. // }
  912. // }
  913. // }
  914. //
  915. // }
  916. //
  917. // for _, item := range splitIrrigation {
  918. // for _,it := range mation{
  919. // if(item == it.SpecificationName){
  920. // //查询最近一次的透析器
  921. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  922. // if errcode == gorm.ErrRecordNotFound{
  923. // //插入数据
  924. // prepare := models.DialysisBeforePrepare{
  925. // UserOrgId: adminUserInfo.CurrentOrgId,
  926. // PatientId: patient,
  927. // RecordDate: recordDate.Unix(),
  928. // GoodTypeId: it.GoodTypeId,
  929. // GoodId: it.ID,
  930. // Count: 1,
  931. // Ctime: time.Now().Unix(),
  932. // Creater: adminUserInfo.AdminUser.Id,
  933. // Status:1,
  934. //
  935. // }
  936. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  937. // fmt.Println(errcode)
  938. // }
  939. // }
  940. // }
  941. // }
  942. //}
  943. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  944. if dialysisPrescription.ID == 0 { //新增
  945. if appRole.UserType == 2 || appRole.UserType == 1 {
  946. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  947. }
  948. prescription.Creater = adminUserInfo.AdminUser.Id
  949. } else { //修改
  950. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  951. //if template.TemplateId == 1 {
  952. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  953. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  954. // if getPermissionErr != nil {
  955. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  956. // return
  957. // } else if headNursePermission == nil {
  958. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  959. // return
  960. // }
  961. // }
  962. //}
  963. if appRole.UserType == 2 || appRole.UserType == 1 {
  964. prescription_doctor := adminUserInfo.AdminUser.Id
  965. prescription.PrescriptionDoctor = prescription_doctor
  966. } else {
  967. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  968. }
  969. if dialysisPrescription.Creater == 0 {
  970. prescription.Creater = adminUserInfo.AdminUser.Id
  971. } else {
  972. prescription.Creater = dialysisPrescription.Creater
  973. }
  974. prescription.CreatedTime = dialysisPrescription.CreatedTime
  975. prescription.UpdatedTime = time.Now().Unix()
  976. prescription.Modifier = adminUserInfo.AdminUser.Id
  977. prescription.ID = dialysisPrescription.ID
  978. }
  979. solution := models.DialysisSolution{
  980. RegistrarsId: adminUserInfo.AdminUser.Id,
  981. UserOrgId: adminUserInfo.CurrentOrgId,
  982. Doctor: prescription_doctor,
  983. PatientId: patient,
  984. ModeId: mode_id,
  985. DialysisDuration: dialysis_duration,
  986. PerfusionApparatus: perfusion_apparatus,
  987. BloodFlowVolume: blood_flow_volume,
  988. Dewater: dewater_amount,
  989. DisplaceLiqui: displace_liqui,
  990. ReplacementWay: replacement_way,
  991. Anticoagulant: anticoagulant,
  992. AnticoagulantShouji: anticoagulant_shouji,
  993. AnticoagulantWeichi: anticoagulant_weichi,
  994. AnticoagulantZongliang: anticoagulant_zongliang,
  995. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  996. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  997. Kalium: kalium,
  998. Sodium: sodium,
  999. Calcium: calcium,
  1000. Bicarbonate: bicarbonate,
  1001. Glucose: glucose,
  1002. // DryWeight: dry_weight,
  1003. DialysateFlow: dialysate_flow,
  1004. DialysateTemperature: dialysate_temperature,
  1005. Conductivity: conductivity,
  1006. Remark: remark,
  1007. Status: 1,
  1008. CreatedTime: time.Now().Unix(),
  1009. UpdatedTime: time.Now().Unix(),
  1010. DialysisDurationMinute: dialysisDurationMinute,
  1011. DialysisDurationHour: dialysisDurationHour,
  1012. TargetUltrafiltration: targetUltrafiltration,
  1013. DialysateFormulation: dialysateFormulation,
  1014. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1015. BodyFluid: body_fluid,
  1016. SpecialMedicine: special_medicine,
  1017. SpecialMedicineOther: special_medicine_other,
  1018. DisplaceLiquiPart: displace_liqui_part,
  1019. DisplaceLiquiValue: displace_liqui_value,
  1020. BloodAccess: blood_access,
  1021. Ultrafiltration: ultrafiltration,
  1022. BodyFluidOther: body_fluid_other,
  1023. ReplacementTotal: replacement_total,
  1024. TargetKtv: target_ktv,
  1025. DialysisIrrigation: dialysis_irrigation,
  1026. DialysisDialyszers: dialysis_dialyszers,
  1027. HemodialysisPipelines: hemodialysis_pipelines,
  1028. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1029. PunctureNeedle: puncture_needle,
  1030. PunctureNeedleCount: puncture_needle_count,
  1031. Epo: epo,
  1032. EpoCount: epo_count,
  1033. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1034. OxygenUptake: oxygen_uptake,
  1035. OxygenFlow: oxygen_flow,
  1036. OxygenTime: oxygen_time,
  1037. PreImpulse: preImpules,
  1038. SolutionStatus: 1,
  1039. DialysisRemark: dialysis_remark,
  1040. PrescribingNumber: prescribing_number,
  1041. StartSodium: start_sodium,
  1042. PrescriptionSodium: prescription_sodium,
  1043. SodiumCurve: sodium_curve,
  1044. TreatmentRemark: treatment_remark,
  1045. DialysisFluidFlow: dialysis_fluid_flow,
  1046. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1047. PrescriptionWater: prescribing_number,
  1048. DialysisStrainer: dialysis_strainer,
  1049. }
  1050. //针对河间咸得
  1051. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  1052. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1053. prescription.DisplaceLiquiPart = 0
  1054. prescription.DisplaceLiquiValue = 0
  1055. }
  1056. }
  1057. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  1058. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  1059. solution.DisplaceLiquiPart = 0
  1060. solution.DisplaceLiquiValue = 0
  1061. }
  1062. }
  1063. if adminUserInfo.CurrentOrgId == 10340 && prescription.AdminUserId == 0 {
  1064. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1065. }
  1066. err := service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  1067. //获取最新1条
  1068. dialysisSolution, _ := service.GetLastPatientDialysisSolution(patient, adminUserInfo.CurrentOrgId)
  1069. //更新状态
  1070. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  1071. //长沙南雅医院,自动生成抗凝剂的临时处方
  1072. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  1073. if prescribing_number == 0 {
  1074. prescribing_number = 1
  1075. }
  1076. advice := models.DoctorAdvice{
  1077. UserOrgId: adminUserInfo.CurrentOrgId,
  1078. PatientId: patient,
  1079. GroupNo: 0,
  1080. AdviceType: 2,
  1081. RecordDate: recordDate.Unix(),
  1082. AdviceDate: recordDate.Unix(),
  1083. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1084. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1085. AdviceDesc: "",
  1086. ReminderDate: 0,
  1087. SingleDose: anticoagulant_zongliang,
  1088. SingleDoseUnit: "iu",
  1089. DrugSpec: 0,
  1090. DrugSpecUnit: "",
  1091. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1092. PrescribingNumberUnit: "支",
  1093. DeliveryWay: "静脉注射",
  1094. ExecutionFrequency: "上机前",
  1095. AdviceDoctor: 0,
  1096. Status: 1,
  1097. CreatedTime: time.Now().Unix(),
  1098. UpdatedTime: time.Now().Unix(),
  1099. IsPrescription: 1,
  1100. ExecutionState: 2,
  1101. StopState: 2,
  1102. IsSettle: 2,
  1103. }
  1104. // 查询排班信息
  1105. schedulePatient, _ := service.GetScheduleByPatient(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1106. if schedulePatient.ID > 0 {
  1107. if schedulePatient.ScheduleType == 1 {
  1108. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1109. }
  1110. if schedulePatient.ScheduleType == 2 {
  1111. advice.StartTime = recordDate.Unix() + 11*60*60
  1112. }
  1113. }
  1114. // 抗凝剂名称
  1115. switch anticoagulant {
  1116. case 1:
  1117. advice.AdviceName = "无肝素"
  1118. break
  1119. case 2:
  1120. advice.AdviceName = "普通肝素"
  1121. break
  1122. case 3:
  1123. advice.AdviceName = "低分子肝素"
  1124. break
  1125. case 4:
  1126. advice.AdviceName = "阿加曲班"
  1127. break
  1128. case 5:
  1129. advice.AdviceName = "枸橼酸钠"
  1130. break
  1131. case 6:
  1132. advice.AdviceName = "低分子肝素钙"
  1133. break
  1134. case 7:
  1135. advice.AdviceName = "低分子肝素钠"
  1136. break
  1137. case 8:
  1138. advice.AdviceName = "依诺肝素"
  1139. break
  1140. case 9:
  1141. advice.AdviceName = "达肝素"
  1142. break
  1143. case 10:
  1144. advice.AdviceName = "体外抗凝"
  1145. break
  1146. case 11:
  1147. advice.AdviceName = "那曲肝素"
  1148. break
  1149. case 12:
  1150. advice.AdviceName = "无抗凝剂"
  1151. break
  1152. }
  1153. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1154. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 {
  1155. advice.AdviceDoctor = appRole.AdminUserId
  1156. }
  1157. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1158. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1159. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1160. advice.AdviceName = "低分子肝素钠注射液"
  1161. // 修改患者临时医嘱里的抗凝剂医嘱
  1162. advice.ID = advicePrescription.ID
  1163. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1164. } else {
  1165. // 新增患者临时医嘱里的抗凝剂医嘱
  1166. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1167. advice.AdviceName = "低分子肝素钠注射液"
  1168. service.CreateDoctorAdvice(&advice)
  1169. }
  1170. }
  1171. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1172. redis := service.RedisClient()
  1173. //清空key 值
  1174. redis.Set(key, "", time.Second)
  1175. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1176. redis.Set(keyOne, "", time.Second)
  1177. }
  1178. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1179. redis := service.RedisClient()
  1180. //清空key 值
  1181. redis.Set(key, "", time.Second)
  1182. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1183. //清空key 值
  1184. redis.Set(keyOne, "", time.Second)
  1185. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1186. redis.Set(keyTwo, "", time.Second)
  1187. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1188. redis.Set(keyThree, "", time.Second)
  1189. defer redis.Close()
  1190. if err == nil {
  1191. c.ServeSuccessJSON(map[string]interface{}{
  1192. "solution": &solution,
  1193. "prescription": &prescription,
  1194. })
  1195. } else {
  1196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1197. }
  1198. }
  1199. func (c *DialysisApiController) PostDouleCheck() {
  1200. id, _ := c.GetInt64("patient", 0)
  1201. recordDateStr := c.GetString("record_date")
  1202. checkTimeStr := c.GetString("check_time")
  1203. firstCheckTimeStr := c.GetString("first_check_time")
  1204. creater, _ := c.GetInt64("creater", 0)
  1205. modifier, _ := c.GetInt64("modifier", 0)
  1206. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  1207. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  1208. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  1209. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  1210. dialysis_item_desc := c.GetString("dialysis_item_desc")
  1211. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  1212. vascular_access_desc := c.GetString("vascular_access_desc")
  1213. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  1214. collator, _ := c.GetInt64("collator", 0)
  1215. employee_number := c.GetString("employee_number")
  1216. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  1217. needle_batch_number := c.GetString("needle_batch_number")
  1218. if id <= 0 {
  1219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1220. return
  1221. }
  1222. adminUserInfo := c.GetAdminUserInfo()
  1223. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1224. if patient.ID == 0 {
  1225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1226. return
  1227. }
  1228. if len(recordDateStr) == 0 {
  1229. recordDateStr = time.Now().Format("2006-01-02")
  1230. }
  1231. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1232. if parseDateErr != nil {
  1233. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1235. return
  1236. }
  1237. var checkDate int64
  1238. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1239. list, _ := service.GetRoleList(adminUserInfo.CurrentOrgId, modifier)
  1240. if employee_number != list.JobNumber {
  1241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorEmployeeNumber)
  1242. return
  1243. }
  1244. }
  1245. if len(checkTimeStr) == 0 {
  1246. //checkTimeStr = time.Now().Format("2006-01-02 15:04")
  1247. checkDate = 0
  1248. } else {
  1249. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
  1250. checkDate = checkDateUnix.Unix()
  1251. }
  1252. var firstCheckTimeDate int64
  1253. if len(firstCheckTimeStr) == 0 {
  1254. //firstCheckTimeStr = time.Now().Format("2006-01-02 15:04")
  1255. firstCheckTimeDate = 0
  1256. } else {
  1257. firstCheckTimeDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", firstCheckTimeStr)
  1258. firstCheckTimeDate = firstCheckTimeDateUnix.Unix()
  1259. }
  1260. doubleCheck := models.DoubleCheck{
  1261. UserOrgId: adminUserInfo.CurrentOrgId,
  1262. PatientId: id,
  1263. DialysisItemCheck: dialysis_item_check,
  1264. DialysisParameterCheck: dialysis_parameter_check,
  1265. VascularAccessVerification: vascular_access_verification,
  1266. PipelineConnectionCheck: pipeline_connection_check,
  1267. DialysisItemDesc: dialysis_item_desc,
  1268. DialysisParameterDesc: dialysis_parameter_desc,
  1269. VascularAccessDesc: vascular_access_desc,
  1270. PipelineConnectionDesc: pipeline_connection_desc,
  1271. Collator: collator,
  1272. Status: 1,
  1273. CreatedTime: time.Now().Unix(),
  1274. UpdatedTime: time.Now().Unix(),
  1275. CheckDate: recordDate.Unix(),
  1276. EmployeeNumber: employee_number,
  1277. DialyzerBatchNumber: dialyzer_batch_number,
  1278. NeedleBatchNumber: needle_batch_number,
  1279. }
  1280. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1281. if check.ID == 0 { //新增
  1282. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1283. doubleCheck.CheckTime = checkDate
  1284. doubleCheck.Creater = creater
  1285. doubleCheck.Modifier = modifier
  1286. err := service.AddSigleDoubleCheck(&doubleCheck)
  1287. redis := service.RedisClient()
  1288. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1289. //清空key 值
  1290. redis.Set(key, "", time.Second)
  1291. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1292. redis.Set(keyTwo, "", time.Second)
  1293. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1294. redis.Set(keyThree, "", time.Second)
  1295. defer redis.Close()
  1296. if err == nil {
  1297. c.ServeSuccessJSON(map[string]interface{}{
  1298. "doubleCheck": doubleCheck,
  1299. })
  1300. } else {
  1301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1302. }
  1303. } else { //修改
  1304. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1305. doubleCheck.CheckTime = checkDate
  1306. doubleCheck.Creater = creater
  1307. doubleCheck.Modifier = modifier
  1308. doubleCheck.CreatedTime = check.CreatedTime
  1309. doubleCheck.UpdatedTime = time.Now().Unix()
  1310. doubleCheck.ID = check.ID
  1311. redis := service.RedisClient()
  1312. err := service.UpdateDoubleCheck(&doubleCheck)
  1313. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1314. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1315. redis.Set(keyTwo, "", time.Second)
  1316. //清空key 值
  1317. redis.Set(key, "", time.Second)
  1318. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1319. redis.Set(keyThree, "", time.Second)
  1320. defer redis.Close()
  1321. if err == nil {
  1322. c.ServeSuccessJSON(map[string]interface{}{
  1323. "doubleCheck": doubleCheck,
  1324. })
  1325. } else {
  1326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1327. }
  1328. }
  1329. }
  1330. func (c *DialysisApiController) PostReceiveTreatmentAsses() {
  1331. id, _ := c.GetInt64("patient", 0)
  1332. recordDateStr := c.GetString("record_date")
  1333. way, _ := c.GetInt64("way", 0)
  1334. consciousness, _ := c.GetInt64("consciousness", 0)
  1335. appetite, _ := c.GetInt64("appetite", 0)
  1336. condition, _ := c.GetInt64("condition", 0)
  1337. posture, _ := c.GetInt64("posture")
  1338. score := c.GetString("score")
  1339. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1340. danger_level, _ := c.GetInt64("danger_level", 0)
  1341. intake, _ := c.GetInt64("intake", 0)
  1342. nutrition, _ := c.GetInt64("nutrition", 0)
  1343. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1344. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1345. sick_condition_other := c.GetString("sick_condition_other")
  1346. //precaution, _ := c.GetInt64("precaution", 0)
  1347. precaution := c.GetString("precaution")
  1348. precaution_other := c.GetString("precaution_other")
  1349. psychological_other := c.GetString("psychological_other")
  1350. admission_number := c.GetString("admission_number")
  1351. tumble, _ := c.GetInt64("tumble")
  1352. his_department := c.GetString("his_department")
  1353. his_bed := c.GetString("his_bed")
  1354. diacrisis := c.GetString("diacrisis")
  1355. if id <= 0 {
  1356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1357. return
  1358. }
  1359. adminUserInfo := c.GetAdminUserInfo()
  1360. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1361. if patient.ID == 0 {
  1362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1363. return
  1364. }
  1365. if len(recordDateStr) == 0 {
  1366. recordDateStr = time.Now().Format("2006-01-02")
  1367. }
  1368. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1369. if parseDateErr != nil {
  1370. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1372. return
  1373. }
  1374. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1375. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1376. UserOrgId: adminUserInfo.CurrentOrgId,
  1377. PatientId: id,
  1378. RecordDate: recordDate.Unix(),
  1379. Way: way,
  1380. Consciousness: consciousness,
  1381. Appetite: appetite,
  1382. Condition: condition,
  1383. SickCondition: sick_condition,
  1384. DangerLevel: danger_level,
  1385. Intake: intake,
  1386. Nutrition: nutrition,
  1387. PsychologicalAssessment: psychological_assessment,
  1388. PsychologicalAssessmentOther: psychological_assessment_other,
  1389. SickConditionOther: sick_condition_other,
  1390. Posture: posture,
  1391. CreatedTime: time.Now().Unix(),
  1392. UpdateTime: time.Now().Unix(),
  1393. Status: 1,
  1394. Score: score,
  1395. Precaution: precaution,
  1396. PrecautionOther: precaution_other,
  1397. PsychologicalOther: psychological_other,
  1398. AdmissionNumber: admission_number,
  1399. Tumble: tumble,
  1400. HisDepartment: his_department,
  1401. HisBed: his_bed,
  1402. Diacrisis: diacrisis,
  1403. }
  1404. if receiveTreatment.ID == 0 { //新增
  1405. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1406. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1407. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1408. redis := service.RedisClient()
  1409. //清空key 值
  1410. redis.Set(key, "", time.Second)
  1411. defer redis.Close()
  1412. if err == nil {
  1413. c.ServeSuccessJSON(map[string]interface{}{
  1414. "receiveTreatmentAsses": receiveTreatmentAsses,
  1415. })
  1416. } else {
  1417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1418. }
  1419. } else { //修改
  1420. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1421. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1422. // if getPermissionErr != nil {
  1423. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1424. // return
  1425. // } else if headNursePermission == nil {
  1426. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1427. // return
  1428. // }
  1429. //}
  1430. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1431. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1432. receiveTreatmentAsses.UpdateTime = time.Now().Unix()
  1433. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1434. receiveTreatmentAsses.ID = receiveTreatment.ID
  1435. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1436. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1437. redis := service.RedisClient()
  1438. defer redis.Close()
  1439. redis.Set(keyOne, "", time.Second*60*60*18)
  1440. if err == nil {
  1441. c.ServeSuccessJSON(map[string]interface{}{
  1442. "receiveTreatmentAsses": receiveTreatmentAsses,
  1443. })
  1444. } else {
  1445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1446. }
  1447. }
  1448. }
  1449. func (c *DialysisApiController) PostAssessmentAfterDislysis() {
  1450. patient, _ := c.GetInt64("patient", 0)
  1451. recordDateStr := c.GetString("record_date")
  1452. fmt.Println(recordDateStr)
  1453. if patient <= 0 {
  1454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1455. return
  1456. }
  1457. adminUserInfo := c.GetAdminUserInfo()
  1458. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1459. if patientInfo.ID == 0 {
  1460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1461. return
  1462. }
  1463. if len(recordDateStr) == 0 {
  1464. recordDateStr = time.Now().Format("2006-01-02")
  1465. }
  1466. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1467. if parseDateErr != nil {
  1468. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1470. return
  1471. }
  1472. // data := make(map[string]interface{}, 0)
  1473. var data models.AssessmentAfterDislysis
  1474. var err error
  1475. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  1476. fmt.Println(err)
  1477. if err != nil {
  1478. c.ErrorLog("数据解析错误:%v", err)
  1479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1480. return
  1481. }
  1482. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1483. assessment.DialysisOrderId = data.DialysisOrderId
  1484. assessment.Evaluator = adminUserInfo.AdminUser.Id
  1485. assessment.Status = 1
  1486. assessment.WeightAfter = data.WeightAfter
  1487. assessment.WeightLoss = data.WeightLoss
  1488. assessment.Temperature = data.Temperature
  1489. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  1490. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  1491. assessment.PulseFrequency = data.PulseFrequency
  1492. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  1493. assessment.ActualDisplacement = data.ActualDisplacement
  1494. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  1495. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  1496. assessment.Cruor = data.Cruor
  1497. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  1498. assessment.DialysisIntakes = data.DialysisIntakes
  1499. assessment.InternalFistula = data.InternalFistula
  1500. assessment.BloodAccessPartId = data.BloodAccessPartId
  1501. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  1502. assessment.Catheter = data.Catheter
  1503. assessment.Complication = data.Complication
  1504. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  1505. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  1506. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  1507. assessment.PatientGose = data.PatientGose
  1508. assessment.InpatientDepartment = data.InpatientDepartment
  1509. assessment.ObservationContent = data.ObservationContent
  1510. assessment.ObservationContentOther = data.ObservationContentOther
  1511. assessment.Remark = data.Remark
  1512. assessment.BreathingRate = data.BreathingRate
  1513. assessment.DialysisProcess = data.DialysisProcess
  1514. assessment.InAdvanceMinute = data.InAdvanceMinute
  1515. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  1516. assessment.InAdvanceReason = data.InAdvanceReason
  1517. assessment.HemostasisOpera = data.HemostasisOpera
  1518. assessment.HemostasisMinute = data.HemostasisMinute
  1519. assessment.TremorNoise = data.TremorNoise
  1520. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  1521. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  1522. assessment.ArterialTube = data.ArterialTube
  1523. assessment.IntravenousTube = data.IntravenousTube
  1524. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  1525. assessment.Dialyzer = data.Dialyzer
  1526. assessment.IsEat = data.IsEat
  1527. assessment.CvcA = data.CvcA
  1528. assessment.CvcV = data.CvcV
  1529. assessment.Channel = data.Channel
  1530. assessment.ReturnBlood = data.ReturnBlood
  1531. assessment.RehydrationVolume = data.RehydrationVolume
  1532. assessment.DialysisDuring = data.DialysisDuring
  1533. assessment.StrokeVolume = data.StrokeVolume
  1534. assessment.BloodFlow = data.BloodFlow
  1535. assessment.SealingFluidDispose = data.SealingFluidDispose
  1536. assessment.SealingFluidSpecial = data.SealingFluidSpecial
  1537. assessment.DosageOfAnticoagulants = data.DosageOfAnticoagulants
  1538. assessment.SupineSystolicBloodPressure = data.SupineSystolicBloodPressure
  1539. assessment.SettingPressure = data.SettingPressure
  1540. assessment.SupineDiastolicBloodPressure = data.SupineDiastolicBloodPressure
  1541. assessment.DiastolicPressure = data.DiastolicPressure
  1542. assessment.AdditionalWeight = data.AdditionalWeight
  1543. assessment.OtherComplication = data.OtherComplication
  1544. assessment.Ktv = data.Ktv
  1545. assessment.Urr = data.Urr
  1546. assessment.Hypertenison = data.Hypertenison
  1547. assessment.Hypopiesia = data.Hypopiesia
  1548. assessment.LeaveOfficeMethod = data.LeaveOfficeMethod
  1549. assessment.Lapse = data.Lapse
  1550. assessment.Consciousness = data.Consciousness
  1551. assessment.Fallrisk = data.Fallrisk
  1552. assessment.MachineRun = data.MachineRun
  1553. assessment.AfterUrea = data.AfterUrea
  1554. assessment.PipCoagulation = data.PipCoagulation
  1555. assessment.AccumulatedBloodVolume = data.AccumulatedBloodVolume
  1556. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1557. if assessment.ID > 0 {
  1558. if appRole.UserType == 2 || appRole.UserType == 1 {
  1559. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1560. assessment.AssessmentTime = time.Now().Unix()
  1561. } else {
  1562. if assessment.Creater == 0 {
  1563. assessment.Modifier = adminUserInfo.AdminUser.Id
  1564. assessment.Creater = adminUserInfo.AdminUser.Id
  1565. } else {
  1566. assessment.Modifier = adminUserInfo.AdminUser.Id
  1567. }
  1568. }
  1569. assessment.UpdatedTime = time.Now().Unix()
  1570. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  1571. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1572. redis := service.RedisClient()
  1573. //清空key 值
  1574. redis.Set(key, "", time.Second)
  1575. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1576. redis.Set(keyThree, "", time.Second)
  1577. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1578. redis.Set(keyTwo, "", time.Second)
  1579. defer redis.Close()
  1580. } else {
  1581. if appRole.UserType == 2 || appRole.UserType == 1 {
  1582. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1583. assessment.AssessmentTime = time.Now().Unix()
  1584. } else {
  1585. assessment.Creater = adminUserInfo.AdminUser.Id
  1586. }
  1587. assessment.CreatedTime = time.Now().Unix()
  1588. assessment.UpdatedTime = time.Now().Unix()
  1589. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  1590. assessment.PatientId = patient
  1591. assessment.AssessmentDate = recordDate.Unix()
  1592. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  1593. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1594. redis := service.RedisClient()
  1595. //清空key 值
  1596. redis.Set(key, "", time.Second)
  1597. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1598. redis.Set(keyThree, "", time.Second)
  1599. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1600. redis.Set(keyTwo, "", time.Second)
  1601. defer redis.Close()
  1602. }
  1603. if err != nil {
  1604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1605. return
  1606. }
  1607. c.ServeSuccessJSON(map[string]interface{}{
  1608. "AssessmentAfterDislysis": &assessment,
  1609. })
  1610. }
  1611. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  1612. patient, _ := c.GetInt64("patient", 0)
  1613. recordDateStr := c.GetString("record_date")
  1614. if patient <= 0 {
  1615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1616. return
  1617. }
  1618. adminUserInfo := c.GetAdminUserInfo()
  1619. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1620. if patientInfo.ID == 0 {
  1621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1622. return
  1623. }
  1624. if len(recordDateStr) == 0 {
  1625. recordDateStr = time.Now().Format("2006-01-02")
  1626. }
  1627. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1628. if parseDateErr != nil {
  1629. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1631. return
  1632. }
  1633. weight_before, _ := c.GetFloat("weight_before", 0)
  1634. dry_weight, _ := c.GetFloat("dry_weight", 0)
  1635. additional_weight, _ := c.GetFloat("additional_weight", 0)
  1636. temperature, _ := c.GetFloat("temperature", 0)
  1637. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1638. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1639. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1640. last_post_dialysis := c.GetString("last_post_dialysis")
  1641. dialysis_interphase := c.GetString("dialysis_interphase")
  1642. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  1643. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1644. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  1645. bloodAccessPartId := c.GetString("blood_access_part_id")
  1646. internalFistula := c.GetString("internal_fistula")
  1647. internal_fistula_skin := c.GetString("internal_fistula_skin")
  1648. catheter := c.GetString("catheter")
  1649. catheter_bend, _ := c.GetInt("catheter_bend")
  1650. complication := c.GetString("complication")
  1651. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  1652. hemorrhage := c.GetString("hemorrhage")
  1653. hemorrhage_other := c.GetString("hemorrhage_other")
  1654. remark := c.GetString("remark")
  1655. puncture_method := c.GetString("puncture_method")
  1656. dialysis_count := c.GetString("dialysis_count")
  1657. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  1658. emergency_treatment_other := c.GetString("emergency_treatment_other")
  1659. ductus_arantii := c.GetString("ductus_arantii")
  1660. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  1661. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  1662. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  1663. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  1664. puncture_way := c.GetString("puncture_way")
  1665. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  1666. internal_fistula_other := c.GetString("internal_fistula_other")
  1667. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  1668. breathing_rate := c.GetString("breathing_rate")
  1669. is_infect, _ := c.GetInt64("is_infect", 0)
  1670. exposed, _ := c.GetFloat("exposed", 0)
  1671. skin := c.GetString("skin")
  1672. skin_other := c.GetString("skin_other")
  1673. infect_other := c.GetString("infect_other")
  1674. ductus_arantii_other := c.GetString("ductus_arantii_other")
  1675. machine_type := c.GetString("machine_type")
  1676. puncture_needle := c.GetString("puncture_needle")
  1677. //humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
  1678. humor_excessive_symptom := c.GetString("humor_excessive_symptom")
  1679. phinholing := c.GetString("pinholing")
  1680. catheter_suture := c.GetString("catheter_suture")
  1681. catheter_suture_other := c.GetString("catheter_suture_other")
  1682. edema := c.GetString("edema")
  1683. urine_volume, _ := c.GetFloat("urine_volume", 0)
  1684. special_treatment := c.GetString("special_treatment")
  1685. catheter_maintenance := c.GetString("catheter_maintenance")
  1686. thrombusType := c.GetString("thromubus_type")
  1687. thrombusInt, _ := strconv.ParseInt(thrombusType, 10, 64)
  1688. thrombus_a := c.GetString("thromubus_a")
  1689. thrombus_av := c.GetString("thrombus_av")
  1690. thrombus_v := c.GetString("thromubus_v")
  1691. dehydration := c.GetString("dehydration")
  1692. pre_dialysis_drugs := c.GetString("pre_dialysis_drugs")
  1693. period, _ := c.GetInt64("period")
  1694. estimated_food_intake := c.GetString("estimated_food_intake")
  1695. blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
  1696. urea_befor := c.GetString("urea_befor")
  1697. suction := c.GetString("suction")
  1698. weight_befor_remake := c.GetString("weight_befor_remake")
  1699. height := c.GetString("height")
  1700. age := c.GetString("age")
  1701. his_department := c.GetString("his_department")
  1702. his_bed := c.GetString("his_bed")
  1703. point_puncture := c.GetString("point_puncture")
  1704. assessmentBeforeDislysis := models.PredialysisEvaluation{
  1705. DialysisCount: dialysis_count,
  1706. EmergencyTreatment: emergency_treatment,
  1707. EmergencyTreatmentOther: emergency_treatment_other,
  1708. DuctusArantii: ductus_arantii,
  1709. VenousCatheterization: venous_catheterization,
  1710. VenousCatheterizationPart: venous_catheterization_part,
  1711. VenousCatheterizationPartOther: venous_catheterization_part_other,
  1712. PunctureWay: puncture_way,
  1713. BloodAccessInternalFistula: blood_access_internal_fistula,
  1714. BloodAccessNoise: blood_access_noise,
  1715. InternalFistulaOther: internal_fistula_other,
  1716. Evaluator: adminUserInfo.AdminUser.Id,
  1717. UserOrgId: adminUserInfo.CurrentOrgId,
  1718. PatientId: patient,
  1719. AssessmentDate: recordDate.Unix(),
  1720. Temperature: temperature,
  1721. PulseFrequency: pulse_frequency,
  1722. SystolicBloodPressure: systolic_blood_pressure,
  1723. DiastolicBloodPressure: diastolic_blood_pressure,
  1724. WeightBefore: weight_before,
  1725. DryWeight: dry_weight,
  1726. AdditionalWeight: additional_weight,
  1727. DialysisInterphase: dialysis_interphase,
  1728. LastPostDialysis: last_post_dialysis,
  1729. SymptomBeforeDialysis: symptom_before_dialysis,
  1730. InternalFistula: internalFistula,
  1731. InternalFistulaSkin: internal_fistula_skin,
  1732. Catheter: catheter,
  1733. CatheterBend: catheter_bend,
  1734. Complication: complication,
  1735. CreatedTime: time.Now().Unix(),
  1736. Status: 1,
  1737. Remark: remark,
  1738. IsHemorrhage: is_hemorrhage,
  1739. Hemorrhage: hemorrhage,
  1740. HemorrhageOther: hemorrhage_other,
  1741. BloodAccessPartId: bloodAccessPartId,
  1742. BloodAccessPartOperaId: bloodAccessPartOperaId,
  1743. PunctureMethod: puncture_method,
  1744. BreathingRate: breathing_rate,
  1745. IsInfect: is_infect,
  1746. Exposed: exposed,
  1747. Skin: skin,
  1748. SkinOther: skin_other,
  1749. InfectOther: infect_other,
  1750. DuctusArantiiOther: ductus_arantii_other,
  1751. MachineType: machine_type,
  1752. PunctureNeedle: puncture_needle,
  1753. HumorExcessiveSymptom: humor_excessive_symptom,
  1754. Phinholing: phinholing,
  1755. CatheterSuture: catheter_suture,
  1756. CatheterSutureOther: catheter_suture_other,
  1757. Edema: edema,
  1758. UrineVolume: urine_volume,
  1759. SpecialTreatment: special_treatment,
  1760. CatheterMaintenance: catheter_maintenance,
  1761. ThromubusType: thrombusInt,
  1762. ThrombusAv: thrombus_av,
  1763. ThromubusA: thrombus_a,
  1764. ThromubusV: thrombus_v,
  1765. Dehydration: dehydration,
  1766. PreDialysisDrugs: pre_dialysis_drugs,
  1767. Period: period,
  1768. EstimatedFoodIntake: estimated_food_intake,
  1769. BloodPressureDuringDialysis: blood_pressure_during_dialysis,
  1770. UreaBefor: urea_befor,
  1771. Suction: suction,
  1772. WeightBeforRemake: weight_befor_remake,
  1773. Height: height,
  1774. Age: age,
  1775. HisDepartment: his_department,
  1776. HisBed: his_bed,
  1777. PointPuncture: point_puncture,
  1778. }
  1779. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1780. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1781. if evaluation.ID == 0 { //新增
  1782. if appRole.UserType == 2 || appRole.UserType == 1 {
  1783. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1784. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1785. } else {
  1786. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  1787. }
  1788. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  1789. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10469 {
  1790. var dewater_amount float64
  1791. dewater_amount = 0
  1792. if dry_weight > 0 {
  1793. dewater_amount = weight_before - dry_weight - additional_weight
  1794. dewater_amount = dewater_amount * 1000
  1795. if dewater_amount <= 0 {
  1796. dewater_amount = 0
  1797. }
  1798. } else {
  1799. dewater_amount = 0
  1800. }
  1801. // 计算透析处方的相关超滤量
  1802. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1803. var lastDialysisPrescribe *models.DialysisPrescription
  1804. var dialysisSolution *models.DialysisSolution
  1805. var dialysisPrescribe *models.DialysisPrescription
  1806. var mode_id int64
  1807. if schedual != nil {
  1808. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  1809. if dialysisPrescribe == nil {
  1810. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1811. }
  1812. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1813. // 获取透析模版
  1814. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1815. mode_id = schedual.ModeId
  1816. } else {
  1817. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  1818. // 获取透析模版
  1819. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1820. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  1821. if dialysisPrescribe == nil && dialysisSolution != nil {
  1822. mode_id = dialysisSolution.ModeId
  1823. }
  1824. if dialysisPrescribe == nil && dialysisSolution == nil {
  1825. mode_id = 0
  1826. }
  1827. }
  1828. // 插入透析处方
  1829. if dialysisPrescribe == nil && dialysisSolution != nil {
  1830. var newprescribe models.DialysisPrescription
  1831. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1832. newprescribe.PatientId = dialysisSolution.PatientId
  1833. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1834. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1835. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1836. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1837. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1838. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1839. newprescribe.ModeId = dialysisSolution.ModeId
  1840. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1841. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1842. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1843. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1844. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1845. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1846. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1847. newprescribe.Glucose = dialysisSolution.Glucose
  1848. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1849. newprescribe.Kalium = dialysisSolution.Kalium
  1850. newprescribe.Sodium = dialysisSolution.Sodium
  1851. newprescribe.Calcium = dialysisSolution.Calcium
  1852. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1853. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1854. newprescribe.Conductivity = dialysisSolution.Conductivity
  1855. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1856. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1857. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1858. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1859. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1860. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1861. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1862. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1863. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1864. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1865. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1866. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1867. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1868. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1869. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1870. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1871. newprescribe.CreatedTime = time.Now().Unix()
  1872. newprescribe.UpdatedTime = time.Now().Unix()
  1873. newprescribe.RecordDate = recordDate.Unix()
  1874. newprescribe.DewaterAmount = dewater_amount
  1875. newprescribe.TargetUltrafiltration = dewater_amount
  1876. newprescribe.Status = 1
  1877. err := service.AddSigleRecord(&newprescribe)
  1878. if err != nil {
  1879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1880. }
  1881. }
  1882. if dialysisPrescribe == nil && dialysisSolution == nil {
  1883. if lastDialysisPrescribe != nil {
  1884. var newprescribe models.DialysisPrescription
  1885. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  1886. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  1887. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  1888. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  1889. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  1890. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  1891. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  1892. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  1893. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  1894. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  1895. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  1896. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  1897. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  1898. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  1899. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  1900. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  1901. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  1902. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  1903. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  1904. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  1905. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  1906. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  1907. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  1908. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  1909. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  1910. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  1911. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  1912. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  1913. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  1914. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  1915. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  1916. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  1917. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  1918. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  1919. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  1920. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  1921. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  1922. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  1923. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  1924. newprescribe.CreatedTime = time.Now().Unix()
  1925. newprescribe.UpdatedTime = time.Now().Unix()
  1926. newprescribe.RecordDate = recordDate.Unix()
  1927. newprescribe.DewaterAmount = dewater_amount
  1928. newprescribe.TargetUltrafiltration = dewater_amount
  1929. newprescribe.Status = 1
  1930. newprescribe.Creater = adminUserInfo.AdminUser.Id
  1931. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1932. err := service.AddSigleRecord(&newprescribe)
  1933. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1934. redis := service.RedisClient()
  1935. defer redis.Close()
  1936. //清空key 值
  1937. redis.Set(key, "", time.Second)
  1938. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1939. redis.Set(keyOne, "", time.Second)
  1940. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1941. redis.Set(keyThree, "", time.Second)
  1942. if err != nil {
  1943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1944. }
  1945. } else {
  1946. var newprescribe models.DialysisPrescription
  1947. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  1948. newprescribe.PatientId = patient
  1949. newprescribe.ModeId = mode_id
  1950. newprescribe.CreatedTime = time.Now().Unix()
  1951. newprescribe.UpdatedTime = time.Now().Unix()
  1952. newprescribe.RecordDate = recordDate.Unix()
  1953. newprescribe.DewaterAmount = dewater_amount
  1954. newprescribe.TargetUltrafiltration = dewater_amount
  1955. newprescribe.Status = 1
  1956. newprescribe.Creater = adminUserInfo.AdminUser.Id
  1957. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1958. newprescribe.Modifier = adminUserInfo.AdminUser.Id
  1959. err := service.AddSigleRecord(&newprescribe)
  1960. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1961. redis := service.RedisClient()
  1962. defer redis.Close()
  1963. //清空key 值
  1964. redis.Set(key, "", time.Second)
  1965. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1966. redis.Set(keyOne, "", time.Second)
  1967. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1968. redis.Set(keyThree, "", time.Second)
  1969. if err != nil {
  1970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1971. }
  1972. }
  1973. }
  1974. }
  1975. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1976. redis := service.RedisClient()
  1977. //清空key 值
  1978. redis.Set(key, "", time.Second)
  1979. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1980. redis.Set(keyOne, "", time.Second)
  1981. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1982. redis.Set(keyTwo, "", time.Second)
  1983. defer redis.Close()
  1984. if err == nil {
  1985. c.ServeSuccessJSON(map[string]interface{}{
  1986. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  1987. })
  1988. } else {
  1989. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1991. }
  1992. } else { //修改
  1993. //if appRole.UserType == 3 {
  1994. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  1995. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1996. // if getPermissionErr != nil {
  1997. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1998. // return
  1999. // } else if headNursePermission == nil {
  2000. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2001. // return
  2002. // }
  2003. // }
  2004. //}
  2005. if appRole.UserType == 2 || appRole.UserType == 1 {
  2006. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2007. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  2008. } else {
  2009. if evaluation.Creater == 0 {
  2010. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2011. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2012. } else {
  2013. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2014. }
  2015. }
  2016. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  2017. assessmentBeforeDislysis.ID = evaluation.ID
  2018. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  2019. //
  2020. //新增逻辑
  2021. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2022. var dewater_amount float64
  2023. dewater_amount = 0
  2024. if evaluation.DryWeight > 0 {
  2025. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2026. if templateInfo.TemplateId == 17 || templateInfo.TemplateId == 22 || templateInfo.TemplateId == 21 || templateInfo.TemplateId == 34 {
  2027. dewater_amount = dewater_amount * 1000
  2028. }
  2029. if dewater_amount <= 0 {
  2030. dewater_amount = 0
  2031. }
  2032. } else {
  2033. dewater_amount = 0
  2034. }
  2035. // 计算透析处方的相关超滤量
  2036. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2037. var lastDialysisPrescribe *models.DialysisPrescription
  2038. var dialysisSolution *models.DialysisSolution
  2039. var dialysisPrescribe *models.DialysisPrescription
  2040. var mode_id int64
  2041. if schedual != nil {
  2042. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2043. if dialysisPrescribe == nil {
  2044. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2045. }
  2046. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2047. // 获取透析模版
  2048. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2049. mode_id = schedual.ModeId
  2050. } else {
  2051. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2052. // 获取透析模版
  2053. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2054. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  2055. if dialysisPrescribe == nil && dialysisSolution != nil {
  2056. mode_id = dialysisSolution.ModeId
  2057. }
  2058. if dialysisPrescribe == nil && dialysisSolution == nil {
  2059. mode_id = 0
  2060. }
  2061. }
  2062. // 插入透析处方
  2063. if dialysisPrescribe == nil && dialysisSolution != nil {
  2064. var newprescribe models.DialysisPrescription
  2065. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  2066. newprescribe.PatientId = dialysisSolution.PatientId
  2067. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2068. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2069. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2070. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2071. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2072. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2073. newprescribe.ModeId = dialysisSolution.ModeId
  2074. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2075. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2076. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2077. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2078. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2079. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2080. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2081. newprescribe.Glucose = dialysisSolution.Glucose
  2082. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2083. newprescribe.Kalium = dialysisSolution.Kalium
  2084. newprescribe.Sodium = dialysisSolution.Sodium
  2085. newprescribe.Calcium = dialysisSolution.Calcium
  2086. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2087. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2088. newprescribe.Conductivity = dialysisSolution.Conductivity
  2089. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2090. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2091. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2092. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2093. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2094. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2095. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2096. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2097. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2098. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2099. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2100. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2101. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2102. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2103. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2104. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2105. newprescribe.CreatedTime = time.Now().Unix()
  2106. newprescribe.UpdatedTime = time.Now().Unix()
  2107. newprescribe.RecordDate = recordDate.Unix()
  2108. newprescribe.DewaterAmount = dewater_amount
  2109. newprescribe.TargetUltrafiltration = dewater_amount
  2110. newprescribe.Status = 1
  2111. err := service.AddSigleRecord(&newprescribe)
  2112. if err != nil {
  2113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2114. }
  2115. }
  2116. if dialysisPrescribe == nil && dialysisSolution == nil {
  2117. if lastDialysisPrescribe != nil {
  2118. var newprescribe models.DialysisPrescription
  2119. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  2120. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  2121. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2122. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2123. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2124. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2125. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2126. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2127. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2128. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2129. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2130. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2131. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2132. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2133. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2134. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2135. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2136. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2137. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2138. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2139. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2140. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2141. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2142. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2143. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2144. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2145. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2146. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2147. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2148. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2149. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2150. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2151. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2152. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2153. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2154. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2155. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2156. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2157. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2158. newprescribe.CreatedTime = time.Now().Unix()
  2159. newprescribe.UpdatedTime = time.Now().Unix()
  2160. newprescribe.RecordDate = recordDate.Unix()
  2161. newprescribe.DewaterAmount = dewater_amount
  2162. newprescribe.TargetUltrafiltration = dewater_amount
  2163. newprescribe.Status = 1
  2164. err := service.AddSigleRecord(&newprescribe)
  2165. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2166. redis := service.RedisClient()
  2167. defer redis.Close()
  2168. //清空key 值
  2169. redis.Set(key, "", time.Second)
  2170. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2171. redis.Set(keyOne, "", time.Second)
  2172. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2173. redis.Set(keyThree, "", time.Second)
  2174. if err != nil {
  2175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2176. }
  2177. } else {
  2178. var newprescribe models.DialysisPrescription
  2179. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2180. newprescribe.PatientId = patient
  2181. newprescribe.ModeId = mode_id
  2182. newprescribe.CreatedTime = time.Now().Unix()
  2183. newprescribe.UpdatedTime = time.Now().Unix()
  2184. newprescribe.RecordDate = recordDate.Unix()
  2185. newprescribe.DewaterAmount = dewater_amount
  2186. newprescribe.TargetUltrafiltration = dewater_amount
  2187. newprescribe.Status = 1
  2188. err := service.AddSigleRecord(&newprescribe)
  2189. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2190. redis := service.RedisClient()
  2191. defer redis.Close()
  2192. //清空key 值
  2193. redis.Set(key, "", time.Second)
  2194. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2195. redis.Set(keyOne, "", time.Second)
  2196. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2197. redis.Set(keyThree, "", time.Second)
  2198. if err != nil {
  2199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2200. }
  2201. }
  2202. }
  2203. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  2204. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2205. redis := service.RedisClient()
  2206. //清空key 值
  2207. redis.Set(key, "", time.Second)
  2208. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2209. redis.Set(keyOne, "", time.Second)
  2210. defer redis.Close()
  2211. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2212. redis.Set(keyTwo, "", time.Second)
  2213. if err == nil {
  2214. c.ServeSuccessJSON(map[string]interface{}{
  2215. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2216. })
  2217. } else {
  2218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2219. }
  2220. }
  2221. }
  2222. func (c *DialysisApiController) PostTreatmentSummary() {
  2223. patient, _ := c.GetInt64("patient", 0)
  2224. recordDateStr := c.GetString("record_date")
  2225. if patient <= 0 {
  2226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2227. return
  2228. }
  2229. adminUserInfo := c.GetAdminUserInfo()
  2230. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2231. if patientInfo.ID == 0 {
  2232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2233. return
  2234. }
  2235. if len(recordDateStr) == 0 {
  2236. recordDateStr = time.Now().Format("2006-01-02")
  2237. }
  2238. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2239. if parseDateErr != nil {
  2240. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2242. return
  2243. }
  2244. mission := c.GetString("mission")
  2245. dialysis_summary := c.GetString("dialysis_summary")
  2246. nursingRecord := c.GetString("nursing_record")
  2247. specialRecord := c.GetString("special_record")
  2248. sj_nurse := adminUserInfo.AdminUser.Id
  2249. zl_nurse := adminUserInfo.AdminUser.Id
  2250. hd_nurse := adminUserInfo.AdminUser.Id
  2251. xj_nurse := adminUserInfo.AdminUser.Id
  2252. zl_doctor := adminUserInfo.AdminUser.Id
  2253. treatmentSummary := models.TreatmentSummary{
  2254. UserOrgId: adminUserInfo.CurrentOrgId,
  2255. PatientId: patient,
  2256. AssessmentDate: recordDate.Unix(),
  2257. Mission: mission,
  2258. DialysisSummary: dialysis_summary,
  2259. SjNurse: sj_nurse,
  2260. ZlNurse: zl_nurse,
  2261. HdNurse: hd_nurse,
  2262. XjNurse: xj_nurse,
  2263. ZlDoctor: zl_doctor,
  2264. Status: 1,
  2265. CreatedTime: time.Now().Unix(),
  2266. NursingRecord: nursingRecord,
  2267. SpecialRecord: specialRecord,
  2268. }
  2269. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2270. if tempTreatmentSummary.ID == 0 { //新增
  2271. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  2272. err := service.AddSigleSummaryRecord(&treatmentSummary)
  2273. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2274. redis := service.RedisClient()
  2275. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2276. redis.Set(keyOne, "", time.Second)
  2277. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2278. redis.Set(keyThree, "", time.Second)
  2279. defer redis.Close()
  2280. //清空key 值
  2281. redis.Set(key, "", time.Second)
  2282. if err == nil {
  2283. c.ServeSuccessJSON(map[string]interface{}{
  2284. "summary": treatmentSummary,
  2285. })
  2286. } else {
  2287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2288. }
  2289. } else { //修改
  2290. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  2291. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2292. // if getPermissionErr != nil {
  2293. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2294. // return
  2295. // } else if headNursePermission == nil {
  2296. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2297. // return
  2298. // }
  2299. //}
  2300. treatmentSummary.Creater = tempTreatmentSummary.Creater
  2301. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  2302. treatmentSummary.UpdatedTime = time.Now().Unix()
  2303. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  2304. treatmentSummary.ID = tempTreatmentSummary.ID
  2305. err := service.UpdateSummeRecord(&treatmentSummary)
  2306. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2307. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2308. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2309. //清空key 值
  2310. redis := service.RedisClient()
  2311. redis.Set(key, "", time.Second)
  2312. redis.Set(keyOne, "", time.Second)
  2313. redis.Set(keyThree, "", time.Second)
  2314. defer redis.Close()
  2315. if err == nil {
  2316. c.ServeSuccessJSON(map[string]interface{}{
  2317. "summary": treatmentSummary,
  2318. })
  2319. } else {
  2320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2321. }
  2322. }
  2323. }
  2324. func (c *DialysisApiController) GetDeviceList() {
  2325. adminUserInfo := c.GetAdminUserInfo()
  2326. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  2327. c.ServeSuccessJSON(map[string]interface{}{
  2328. "device": device,
  2329. })
  2330. }
  2331. func (c *DialysisApiController) GetAllDeviceZone() {
  2332. adminUserInfo := c.GetAdminUserInfo()
  2333. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  2334. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  2335. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  2336. if err == nil {
  2337. c.ServeSuccessJSON(map[string]interface{}{
  2338. "zone": zone,
  2339. "dics": dics,
  2340. "efs": efs,
  2341. })
  2342. }
  2343. }
  2344. func (c *DialysisApiController) GetDialysisWatch() {
  2345. page, _ := c.GetInt64("page", 1)
  2346. limit, _ := c.GetInt64("limit", 10)
  2347. schedulType, _ := c.GetInt64("schedul_type", 0)
  2348. startTime, _ := c.GetInt64("schedul_time", 0)
  2349. partitionType, _ := c.GetInt64("partition_type", 0)
  2350. keywords := c.GetString("keywords")
  2351. start_time, _ := c.GetInt64("start_time")
  2352. end_time, _ := c.GetInt64("end_time")
  2353. adminUserInfo := c.GetAdminUserInfo()
  2354. if len(keywords) > 0 {
  2355. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2356. if err == nil {
  2357. c.ServeSuccessJSON(map[string]interface{}{
  2358. "schedule": dialysisSchedule,
  2359. "total": total,
  2360. })
  2361. } else {
  2362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2363. }
  2364. } else {
  2365. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2366. if err == nil {
  2367. c.ServeSuccessJSON(map[string]interface{}{
  2368. "schedule": dialysisSchedule,
  2369. "total": total,
  2370. })
  2371. } else {
  2372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2373. }
  2374. }
  2375. }
  2376. //func (c *DialysisApiController) GetDialysisWatch() {
  2377. // page, _ := c.GetInt64("page", 1)
  2378. // limit, _ := c.GetInt64("limit", 10)
  2379. // schedulType, _ := c.GetInt64("schedul_type", 0)
  2380. // startTime, _ := c.GetInt64("schedul_time", 0)
  2381. // partitionType, _ := c.GetInt64("partition_type", 0)
  2382. // keywords := c.GetString("keywords")
  2383. //
  2384. // adminUserInfo := c.GetAdminUserInfo()
  2385. // if len(keywords) > 0 {
  2386. // dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  2387. //
  2388. // //获取所有床位号
  2389. // numberList, _ := service.GetAllDeviceNumberByListSix(adminUserInfo.CurrentOrgId)
  2390. //
  2391. // //获取透析处方
  2392. // prescriptions, _ := service.GetAllPrescriptionByListTwo(adminUserInfo.CurrentOrgId, startTime)
  2393. // //获取透前评估
  2394. // assessmentBefores, _ := service.GetAllAssessmentBeforesByListThree(adminUserInfo.CurrentOrgId, startTime)
  2395. // //获取上机
  2396. // dialysisOrders, _ := service.GetAllDialysisOrdersByListThree(adminUserInfo.CurrentOrgId, startTime)
  2397. // //获取透后
  2398. // AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListThree(adminUserInfo.CurrentOrgId, startTime)
  2399. //
  2400. // //获取透后监测
  2401. // monitorlist, _ := service.GetAllMonitorListThree(adminUserInfo.CurrentOrgId, startTime)
  2402. //
  2403. // //获取所有的患者
  2404. // patients, _ := service.GetAllPatientListByListSix(adminUserInfo.CurrentOrgId,keywords)
  2405. //
  2406. // //获取所有透析模式
  2407. // treatments, _ := service.GetAllTreatModeByList(adminUserInfo.CurrentOrgId)
  2408. //
  2409. // for key, scheduals := range dialysisSchedule {
  2410. // // 获取患者信息
  2411. // for _, patient := range patients {
  2412. // if scheduals.PatientId == patient.ID {
  2413. // dialysisSchedule[key].MonitorPatients = patient
  2414. // break
  2415. // }
  2416. // }
  2417. // // 床位信息
  2418. // for _, device := range numberList {
  2419. // if scheduals.BedId == device.ID {
  2420. // dialysisSchedule[key].DeviceNumber = device
  2421. // break
  2422. // }
  2423. // }
  2424. //
  2425. // // 医嘱信息
  2426. // for _, prescription := range prescriptions {
  2427. // if scheduals.PatientId == prescription.PatientId {
  2428. // dialysisSchedule[key].Prescription = prescription
  2429. // break
  2430. // }
  2431. // }
  2432. //
  2433. // // 透前评估
  2434. // for _, assessmentBefore := range assessmentBefores {
  2435. // if scheduals.PatientId == assessmentBefore.PatientId {
  2436. // dialysisSchedule[key].AssessmentBeforeDislysis = assessmentBefore
  2437. // break
  2438. // }
  2439. // }
  2440. //
  2441. // // 透析上下机
  2442. // for _, dialysisOrder := range dialysisOrders {
  2443. // if scheduals.PatientId == dialysisOrder.PatientId {
  2444. // dialysisSchedule[key].DialysisOrder = dialysisOrder
  2445. // break
  2446. // }
  2447. // }
  2448. //
  2449. // records := make([]*models.MonitoringRecord, 0)
  2450. // // 透析监测
  2451. // for _, it := range monitorlist {
  2452. // records := append(records, it)
  2453. // if scheduals.PatientId == it.PatientId {
  2454. // dialysisSchedule[key].MonitoringRecord = records
  2455. // }
  2456. // }
  2457. //
  2458. // // 透后评估
  2459. // for _, afterDislysis := range AssessmentAfterDislysis {
  2460. // if scheduals.PatientId == afterDislysis.PatientId {
  2461. // dialysisSchedule[key].AssessmentAfterDislysis = afterDislysis
  2462. // break
  2463. // }
  2464. // }
  2465. //
  2466. // //透析模式
  2467. // for _, treatment := range treatments {
  2468. // if scheduals.ModeId == treatment.ID {
  2469. // dialysisSchedule[key].TreatmentMode = treatment
  2470. // break
  2471. // }
  2472. // }
  2473. // }
  2474. // //获取所有床位号
  2475. // if err == nil {
  2476. // c.ServeSuccessJSON(map[string]interface{}{
  2477. // "schedule": dialysisSchedule,
  2478. // "total": total,
  2479. // })
  2480. // } else {
  2481. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2482. // }
  2483. //
  2484. // } else {
  2485. // dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  2486. // if err == nil {
  2487. // c.ServeSuccessJSON(map[string]interface{}{
  2488. // "schedule": dialysisSchedule,
  2489. // "total": total,
  2490. // })
  2491. // } else {
  2492. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2493. // }
  2494. // }
  2495. //}
  2496. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  2497. patientId, _ := c.GetInt64("id", 0)
  2498. record_date, _ := c.GetInt64("record_date", 0)
  2499. adminUserInfo := c.GetAdminUserInfo()
  2500. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2501. var dialysisStatus int64
  2502. if dialysisOrder == nil { //没有透析记录
  2503. dialysisStatus = 0 //未透析
  2504. } else {
  2505. dialysisStatus = dialysisOrder.Stage
  2506. }
  2507. //用户基本信息
  2508. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2509. //接诊评估
  2510. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2511. //透前评估
  2512. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2513. //临时医嘱
  2514. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2515. //双人核对
  2516. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2517. //透析监测
  2518. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  2519. //透后评估
  2520. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2521. //透析小结
  2522. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2523. //透析处方
  2524. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2525. if dialysisPrescription.ID == 0 {
  2526. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  2527. c.ServeSuccessJSON(map[string]interface{}{
  2528. "patientInfo": schedualPatientInfo,
  2529. "dialysisPrescription": solution,
  2530. "receiverTreatmentAccess": receiverTreatmentAccess,
  2531. "predialysisEvaluation": PredialysisEvaluation,
  2532. "doctorAdvice": DoctorAdvice,
  2533. "doubleCheck": DoubleCheck,
  2534. "assessmentAfterDislysis": AssessmentAfterDislysis,
  2535. "treatmentSummary": TreatmentSummary,
  2536. "monitorRecord": Record,
  2537. "dialysisStatus": dialysisStatus,
  2538. "dialysisOrder": dialysisOrder,
  2539. "isSolution": 1,
  2540. })
  2541. } else {
  2542. c.ServeSuccessJSON(map[string]interface{}{
  2543. "patientInfo": schedualPatientInfo,
  2544. "dialysisPrescription": dialysisPrescription,
  2545. "receiverTreatmentAccess": receiverTreatmentAccess,
  2546. "predialysisEvaluation": PredialysisEvaluation,
  2547. "doctorAdvice": DoctorAdvice,
  2548. "doubleCheck": DoubleCheck,
  2549. "assessmentAfterDislysis": AssessmentAfterDislysis,
  2550. "treatmentSummary": TreatmentSummary,
  2551. "monitorRecord": Record,
  2552. "dialysisStatus": dialysisStatus,
  2553. "dialysisOrder": dialysisOrder,
  2554. "isSolution": 2,
  2555. })
  2556. }
  2557. }
  2558. func (c *DialysisApiController) CreateDoctorAdvice() {
  2559. patient, _ := c.GetInt64("id", 0)
  2560. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  2561. record_date, _ := c.GetInt64("record_date", 0)
  2562. if patient <= 0 {
  2563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2564. return
  2565. }
  2566. adminUserInfo := c.GetAdminUserInfo()
  2567. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2568. if patientInfo.ID == 0 {
  2569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2570. return
  2571. }
  2572. var advice models.DoctorAdvice
  2573. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  2574. if code > 0 {
  2575. c.ServeFailJSONWithSGJErrorCode(code)
  2576. return
  2577. }
  2578. if advice.ParentId > 0 {
  2579. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  2580. if old.ID == 0 || old.PatientId != patient {
  2581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2582. return
  2583. }
  2584. if old.StopState == 1 || old.ExecutionState == 1 {
  2585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2586. return
  2587. }
  2588. if old.ParentId > 0 {
  2589. advice.ParentId = old.ParentId
  2590. }
  2591. advice.StartTime = old.StartTime
  2592. advice.AdviceDoctor = old.AdviceDoctor
  2593. advice.DeliveryWay = old.DeliveryWay
  2594. advice.ExecutionFrequency = old.ExecutionFrequency
  2595. }
  2596. advice.RecordDate = record_date
  2597. advice.DialysisOrderId = dialysis_id
  2598. advice.Status = 1
  2599. advice.CreatedTime = time.Now().Unix()
  2600. advice.UpdatedTime = time.Now().Unix()
  2601. advice.StopState = 2
  2602. advice.ExecutionState = 2
  2603. advice.AdviceType = 2
  2604. advice.UserOrgId = adminUserInfo.CurrentOrgId
  2605. advice.PatientId = patient
  2606. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2607. err := service.CreateDoctorAdvice(&advice)
  2608. if err != nil {
  2609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2610. return
  2611. }
  2612. for _, subAdvice := range subAdivice {
  2613. subAdvice.ParentId = advice.ID
  2614. subAdvice.PatientId = patient
  2615. subAdvice.RecordDate = record_date
  2616. subAdvice.CreatedTime = time.Now().Unix()
  2617. subAdvice.UpdatedTime = time.Now().Unix()
  2618. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  2619. }
  2620. service.CreateSubDoctorAdvice(subAdivice)
  2621. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  2622. c.ServeSuccessJSON(map[string]interface{}{
  2623. "msg": "ok",
  2624. "advice": advice,
  2625. "subAdvice": subAdivices,
  2626. })
  2627. return
  2628. }
  2629. func (c *DialysisApiController) EditDoctorAdvice() {
  2630. patient, _ := c.GetInt64("patient", 0)
  2631. id, _ := c.GetInt64("id", 0)
  2632. parent_id, _ := c.GetInt64("parent_id", 0)
  2633. execution_time := c.GetString("execution_time")
  2634. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  2635. // checker, _ := c.GetInt64("checker", 0)
  2636. if id <= 0 || patient <= 0 {
  2637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2638. return
  2639. }
  2640. adminUserInfo := c.GetAdminUserInfo()
  2641. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2642. if advice.ID == 0 || advice.PatientId != patient {
  2643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2644. return
  2645. }
  2646. if len(execution_time) <= 0 {
  2647. utils.ErrorLog("execution_time")
  2648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2649. return
  2650. }
  2651. execution_staff := adminUserInfo.AdminUser.Id
  2652. checker := adminUserInfo.AdminUser.Id
  2653. timeLayout2 := "2006-01-02 15:04"
  2654. loc, _ := time.LoadLocation("Local")
  2655. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  2656. if errs != nil {
  2657. utils.ErrorLog(errs.Error())
  2658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2659. return
  2660. }
  2661. advices := models.DoctorAdvice{
  2662. ExecutionStaff: execution_staff,
  2663. ExecutionTime: theTime.Unix(),
  2664. Checker: checker,
  2665. UpdatedTime: time.Now().Unix(),
  2666. }
  2667. var err error
  2668. if parent_id > 0 {
  2669. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  2670. } else {
  2671. err = service.ExceDoctorAdviceById(&advices, id, patient)
  2672. }
  2673. if err != nil {
  2674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2675. return
  2676. }
  2677. c.ServeSuccessJSON(map[string]interface{}{
  2678. "msg": "ok",
  2679. "advice": advice,
  2680. })
  2681. return
  2682. }
  2683. func (c *DialysisApiController) GetDoctorAdvice() {
  2684. patient, _ := c.GetInt64("patient_id", 0)
  2685. parent_id, _ := c.GetInt64("parent_id", 0)
  2686. adviceId, _ := c.GetInt64("id", 0)
  2687. if patient <= 0 {
  2688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2689. return
  2690. }
  2691. dminUserInfo := c.GetAdminUserInfo()
  2692. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  2693. if patientInfo.ID == 0 {
  2694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2695. return
  2696. }
  2697. var subAdvice []*models.DoctorAdvice
  2698. var advice models.DoctorAdvice
  2699. if parent_id > 0 {
  2700. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  2701. if advice.ID == 0 || advice.PatientId != patient {
  2702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2703. return
  2704. }
  2705. subAdvice = service.FindSubAdivceById(patient, parent_id)
  2706. } else {
  2707. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  2708. if advice.ID == 0 || advice.PatientId != patient {
  2709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2710. return
  2711. }
  2712. subAdvice = service.FindSubAdivceById(patient, adviceId)
  2713. }
  2714. c.ServeSuccessJSON(map[string]interface{}{
  2715. "msg": "ok",
  2716. "advice": advice,
  2717. "subAdvice": subAdvice,
  2718. })
  2719. }
  2720. func (this *DialysisApiController) DelMonitor() {
  2721. recordID, _ := this.GetInt64("record_id")
  2722. patientID, _ := this.GetInt64("patient_id")
  2723. if recordID <= 0 || patientID <= 0 {
  2724. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2725. return
  2726. }
  2727. adminInfo := this.GetAdminUserInfo()
  2728. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  2729. if getPatientErr != nil {
  2730. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2731. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2732. return
  2733. } else if patient == nil {
  2734. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2735. return
  2736. }
  2737. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  2738. if getMonitorErr != nil {
  2739. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2740. return
  2741. }
  2742. //if monitor != nil {
  2743. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  2744. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2745. // if getPermissionErr != nil {
  2746. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2747. // return
  2748. // } else if headNursePermission == nil {
  2749. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2750. // return
  2751. // }
  2752. // }
  2753. //}
  2754. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  2755. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  2756. redis := service.RedisClient()
  2757. //清空key 值
  2758. redis.Set(key, "", time.Second)
  2759. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  2760. redis.Set(keyOne, "", time.Second)
  2761. defer redis.Close()
  2762. if err != nil {
  2763. this.ErrorLog("删除透析监测记录失败:%v", err)
  2764. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  2765. return
  2766. }
  2767. this.ServeSuccessJSON(map[string]interface{}{
  2768. "record_id": monitor.ID,
  2769. })
  2770. }
  2771. func (c *DialysisApiController) CreateMonitor() {
  2772. patient, _ := c.GetInt64("id", 0)
  2773. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  2774. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  2775. operate_time, _ := c.GetInt64("operate_time", 0)
  2776. // monitoring_time := c.GetString("monitoring_time")
  2777. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  2778. breathing_rated := c.GetString("breathing_rated")
  2779. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  2780. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  2781. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  2782. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  2783. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  2784. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  2785. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  2786. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  2787. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  2788. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  2789. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  2790. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  2791. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  2792. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  2793. temperature, _ := c.GetFloat("temperature", 0)
  2794. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  2795. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  2796. conductivity, _ := c.GetFloat("conductivity", 0)
  2797. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  2798. heparin, _ := c.GetFloat("heparin", 0)
  2799. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  2800. ktv, _ := c.GetFloat("ktv", 0)
  2801. symptom := c.GetString("symptom")
  2802. dispose := c.GetString("dispose")
  2803. result := c.GetString("results")
  2804. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  2805. monitor_anticoagulant, _ := c.GetInt64("monitor_anticoagulant")
  2806. monitor_anticoagulant_value := c.GetString("monitor_anticoagulant_value")
  2807. replacement_speed, _ := c.GetFloat("replacement_speed")
  2808. dicarbonate, _ := c.GetFloat("dicarbonate")
  2809. monitoring_date = monitoring_date / 1000
  2810. // operate_time = operate_time / 1000
  2811. if patient <= 0 {
  2812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2813. return
  2814. }
  2815. adminUserInfo := c.GetAdminUserInfo()
  2816. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2817. if patientInfo.ID == 0 {
  2818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2819. return
  2820. }
  2821. monitorRecord := models.MonitoringRecord{
  2822. PatientId: patient,
  2823. MonitoringDate: monitoring_date,
  2824. DialysisOrderId: dialysis_order_id,
  2825. OperateTime: operate_time,
  2826. // MonitoringTime: monitoring_time,
  2827. PulseFrequency: pulse_frequency,
  2828. BreathingRate: breathing_rated,
  2829. SystolicBloodPressure: systolic_blood_pressure,
  2830. DiastolicBloodPressure: diastolic_blood_pressure,
  2831. BloodPressureType: blood_pressure_type,
  2832. BloodFlowVolume: blood_flow_volume,
  2833. VenousPressure: venous_pressure,
  2834. VenousPressureType: venous_pressure_type,
  2835. TransmembranePressure: transmembrane_pressure,
  2836. TransmembranePressureType: transmembrane_pressure_type,
  2837. UltrafiltrationRate: ultrafiltration_rate,
  2838. UltrafiltrationVolume: ultrafiltration_volume,
  2839. SodiumConcentration: sodium_concentration,
  2840. ArterialPressure: arterial_pressure,
  2841. ArterialPressureType: arterial_pressure_type,
  2842. DialysateTemperature: dialysate_temperature,
  2843. Temperature: temperature,
  2844. ReplacementRate: replacement_rate,
  2845. DisplacementQuantity: displacement_quantity,
  2846. Ktv: ktv,
  2847. Symptom: symptom,
  2848. Dispose: dispose,
  2849. Result: result,
  2850. MonitoringNurse: monitoring_nurse,
  2851. Status: 1,
  2852. CreatedTime: time.Now().Unix(),
  2853. UpdatedTime: time.Now().Unix(),
  2854. UserOrgId: adminUserInfo.CurrentOrgId,
  2855. Conductivity: conductivity,
  2856. DisplacementFlowQuantity: displacement_flow_quantity,
  2857. Heparin: heparin,
  2858. DialysateFlow: dialysate_flow,
  2859. MonitorAnticoagulant: monitor_anticoagulant,
  2860. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  2861. ReplacementSpeed: replacement_speed,
  2862. Dicarbonate: dicarbonate,
  2863. }
  2864. err := service.CreateMonitor(&monitorRecord)
  2865. redis := service.RedisClient()
  2866. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_record_list_all"
  2867. redis.Set(key, "", time.Second)
  2868. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  2869. redis.Set(keyOne, "", time.Second)
  2870. redis.Close()
  2871. if err != nil {
  2872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2873. return
  2874. }
  2875. c.ServeSuccessJSON(map[string]interface{}{
  2876. "msg": "ok",
  2877. "monitor": monitorRecord,
  2878. })
  2879. return
  2880. }
  2881. // 已弃用
  2882. // func (c *DialysisApiController) CreateRecordData() {
  2883. // patient, _ := c.GetInt64("id", 0)
  2884. // status, _ := c.GetInt64("status", 0)
  2885. // now := time.Now()
  2886. // year, month, day := now.Date()
  2887. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2888. // todayTimeStamp := today_time.Unix()
  2889. // if patient <= 0 {
  2890. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2891. // return
  2892. // }
  2893. // adminUserInfo := c.GetAdminUserInfo()
  2894. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2895. // if patientInfo.ID == 0 {
  2896. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2897. // return
  2898. // }
  2899. // record := &models.DialysisOrder{
  2900. // DialysisDate: todayTimeStamp,
  2901. // UserOrgId: adminUserInfo.CurrentOrgId,
  2902. // PatientId: patient,
  2903. // Stage: status,
  2904. // Status: 1,
  2905. // CreatedTime: time.Now().Unix(),
  2906. // UpdatedTime: time.Now().Unix(),
  2907. // }
  2908. // if status == 1 {
  2909. // //创建透析记录
  2910. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  2911. // if err == nil {
  2912. // c.ServeSuccessJSON(map[string]interface{}{
  2913. // "dialysisOrder": record,
  2914. // })
  2915. // } else {
  2916. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2917. // }
  2918. // } else {
  2919. // record_id, _ := c.GetInt64("record_id", 0)
  2920. // //修改透析记录状态
  2921. // errs := service.ModifyDialysisRecord(record_id)
  2922. // //结束时候透析次数加1
  2923. // service.UpdateSolutionByPatientId(patient)
  2924. // if errs == nil {
  2925. // c.ServeSuccessJSON(map[string]interface{}{
  2926. // "dialysisOrder": record,
  2927. // })
  2928. // } else {
  2929. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2930. // }
  2931. // }
  2932. // }
  2933. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  2934. dataBody := make(map[string]interface{}, 0)
  2935. err := json.Unmarshal(data, &dataBody)
  2936. if err != nil {
  2937. utils.ErrorLog(err.Error())
  2938. code = enums.ErrorCodeParamWrong
  2939. return
  2940. }
  2941. timeLayout := "2006-01-02 "
  2942. timeLayout2 := "2006-01-02 15:04"
  2943. loc, _ := time.LoadLocation("Local")
  2944. if action == "create" {
  2945. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2946. utils.ErrorLog("advice_type")
  2947. code = enums.ErrorCodeParamWrong
  2948. return
  2949. }
  2950. adviceType := int64(dataBody["advice_type"].(float64))
  2951. if adviceType != 1 && adviceType != 2 {
  2952. utils.ErrorLog("advice_type != 1&&2")
  2953. code = enums.ErrorCodeParamWrong
  2954. return
  2955. }
  2956. advice.AdviceType = adviceType
  2957. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2958. utils.ErrorLog("advice_date")
  2959. code = enums.ErrorCodeParamWrong
  2960. return
  2961. }
  2962. adviceDate, _ := dataBody["advice_date"].(string)
  2963. if len(adviceDate) == 0 {
  2964. utils.ErrorLog("len(adviceDate) == 0")
  2965. code = enums.ErrorCodeParamWrong
  2966. return
  2967. }
  2968. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2969. if err != nil {
  2970. utils.ErrorLog(err.Error())
  2971. code = enums.ErrorCodeParamWrong
  2972. return
  2973. }
  2974. advice.AdviceDate = theTime.Unix()
  2975. }
  2976. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2977. utils.ErrorLog("start_time")
  2978. code = enums.ErrorCodeParamWrong
  2979. return
  2980. }
  2981. startDate, _ := dataBody["start_time"].(string)
  2982. if len(startDate) == 0 {
  2983. utils.ErrorLog("len(startDate) == 0")
  2984. code = enums.ErrorCodeParamWrong
  2985. return
  2986. }
  2987. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  2988. if err != nil {
  2989. utils.ErrorLog(err.Error())
  2990. code = enums.ErrorCodeParamWrong
  2991. return
  2992. }
  2993. advice.StartTime = theTime.Unix()
  2994. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2995. utils.ErrorLog("advice_name")
  2996. code = enums.ErrorCodeParamWrong
  2997. return
  2998. }
  2999. adviceName, _ := dataBody["advice_name"].(string)
  3000. if len(adviceName) == 0 {
  3001. utils.ErrorLog("len(advice_name) == 0")
  3002. code = enums.ErrorCodeParamWrong
  3003. return
  3004. }
  3005. advice.AdviceName = adviceName
  3006. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  3007. utils.ErrorLog("delivery_way")
  3008. code = enums.ErrorCodeParamWrong
  3009. return
  3010. }
  3011. deliveryWay, _ := dataBody["delivery_way"].(string)
  3012. if len(deliveryWay) == 0 {
  3013. utils.ErrorLog("len(deliveryWay) == 0")
  3014. code = enums.ErrorCodeParamWrong
  3015. return
  3016. }
  3017. advice.DeliveryWay = deliveryWay
  3018. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  3019. utils.ErrorLog("execution_frequency")
  3020. code = enums.ErrorCodeParamWrong
  3021. return
  3022. }
  3023. execution_frequency, _ := dataBody["execution_frequency"].(string)
  3024. if len(execution_frequency) == 0 {
  3025. utils.ErrorLog("len(execution_frequency) == 0")
  3026. code = enums.ErrorCodeParamWrong
  3027. return
  3028. }
  3029. advice.ExecutionFrequency = execution_frequency
  3030. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3031. adviceDsc, _ := dataBody["advice_desc"].(string)
  3032. advice.AdviceDesc = adviceDsc
  3033. }
  3034. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3035. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3036. advice.DrugSpecUnit = drugSpecUnit
  3037. }
  3038. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3039. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3040. advice.SingleDose = singleDose
  3041. }
  3042. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3043. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3044. advice.SingleDoseUnit = singleDoseUnit
  3045. }
  3046. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3047. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3048. advice.PrescribingNumber = prescribingNumber
  3049. }
  3050. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3051. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3052. advice.PrescribingNumberUnit = prescribingNumberUnit
  3053. }
  3054. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  3055. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  3056. if len(thisContagions) > 0 {
  3057. for _, item := range thisContagions {
  3058. items := item.(map[string]interface{})
  3059. advice_name, _ := items["advice_name"].(string)
  3060. advice_desc, _ := items["advice_desc"].(string)
  3061. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  3062. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  3063. single_dose_unit, _ := items["single_dose_unit"].(string)
  3064. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  3065. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  3066. advice := &models.DoctorAdvice{
  3067. AdviceName: advice_name,
  3068. AdviceDesc: advice_desc,
  3069. SingleDose: single_dose,
  3070. SingleDoseUnit: single_dose_unit,
  3071. DrugSpecUnit: drug_spec_unit,
  3072. PrescribingNumber: prescribing_number,
  3073. PrescribingNumberUnit: prescribing_number_unit,
  3074. }
  3075. subAdvice = append(subAdvice, advice)
  3076. }
  3077. }
  3078. }
  3079. return
  3080. }
  3081. func (c *DialysisApiController) GetDialysisOrder() {
  3082. //xtno := c.GetString("xtno")
  3083. xtdate := c.GetString("xtdate")
  3084. patient_id, _ := c.GetInt64("patient_id")
  3085. timeLayout := "2006-01-02"
  3086. loc, _ := time.LoadLocation("Local")
  3087. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  3088. if err != nil {
  3089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3090. return
  3091. }
  3092. xttime := theTime.Unix()
  3093. operatorIDs := make([]int64, 0)
  3094. adminUserInfo := c.GetAdminUserInfo()
  3095. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  3096. patientInfo, _ := service.FindPatientWithDeviceByPatientId(adminUserInfo.CurrentOrgId, patient_id, xttime)
  3097. //透析单
  3098. dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3099. if dialysisOrder != nil {
  3100. if dialysisOrder.FinishNurse > 0 {
  3101. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  3102. }
  3103. if dialysisOrder.StartNurse > 0 {
  3104. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  3105. }
  3106. }
  3107. //透前评估
  3108. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3109. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  3110. //透后评估
  3111. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3112. if AssessmentAfterDislysis.Modifier > 0 {
  3113. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  3114. }
  3115. //上次透前评估
  3116. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3117. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3118. //透析处方
  3119. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3120. if dialysisPrescription.PrescriptionDoctor > 0 {
  3121. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  3122. }
  3123. //获取病人的透析模式
  3124. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3125. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3126. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3127. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3128. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3129. //获取透析处方
  3130. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3131. //获取临时医嘱
  3132. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3133. //config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3134. //获取医嘱内容
  3135. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3136. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3137. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3138. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3139. //获取上次的透后体重
  3140. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3141. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3142. //获取透析次数
  3143. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  3144. if len(DoctorAdvice) > 0 {
  3145. for _, item := range DoctorAdvice {
  3146. if item.AdviceDoctor > 0 {
  3147. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3148. }
  3149. if item.ExecutionStaff > 0 {
  3150. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3151. }
  3152. if item.Checker > 0 {
  3153. operatorIDs = append(operatorIDs, item.Checker)
  3154. }
  3155. }
  3156. }
  3157. //透析监测
  3158. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3159. //透析检测
  3160. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3161. //透析小结
  3162. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3163. //接诊评估
  3164. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3165. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3166. if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 10345 {
  3167. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3168. patientInfo.TotalDialysis = dialysis_count
  3169. }
  3170. if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 10345 {
  3171. if xttime <= 1672416000 {
  3172. dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3173. patientInfo.TotalDialysis = dialysis_count
  3174. }
  3175. if xttime >= 1672502400 {
  3176. dialysis_count, _ := service.GetDialysisOrderCountTwo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3177. patientInfo.TotalDialysis = dialysis_count
  3178. }
  3179. }
  3180. //相关操作对应的操作人
  3181. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3182. operators, err := service.GetAdminUserEsOne(adminUserInfo.CurrentOrgId)
  3183. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  3184. //获取当前日期月份的第一天
  3185. firstmonth := service.GetFirstDateOfMonth(theTime)
  3186. firstMonthDate := firstmonth.Unix()
  3187. //获取当前月份的病人透析次数
  3188. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  3189. //获取his数据
  3190. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3191. //hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3192. config, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3193. project_config, _ := service.GetHisProjectConfig(adminUserInfo.CurrentOrgId)
  3194. projects, _ := service.FindAllHisProjectById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3195. //if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  3196. // for _, item := range projects {
  3197. // var advice *models.HisDoctorAdviceInfo
  3198. // advice.ID = item.ID
  3199. // advice.Checker = item.Checker
  3200. // advice.CheckTime = item.CheckTime
  3201. // advice.CheckState = item.CheckState
  3202. // advice.ExecutionState = item.ExecutionState
  3203. // advice.ExecutionStaff = item.ExecutionStaff
  3204. // advice.PrescribingNumber = float64(item.Count)
  3205. // advice.PrescribingNumberUnit = item.Unit
  3206. // advice.AdviceDoctor = item.Doctor
  3207. // if item.Type == 3 {
  3208. // advice.AdviceName = item.GoodInfo.GoodName
  3209. // } else if item.Type == 2 {
  3210. // advice.AdviceName = item.HisProject.ProjectName
  3211. // }
  3212. // advice.StartTime = item.StartTime
  3213. // hisAdvice = append(hisAdvice, advice)
  3214. // }
  3215. //}
  3216. if config.IsOpen == 1 {
  3217. c.ServeSuccessJSON(map[string]interface{}{
  3218. "xtdate": xtdate,
  3219. "users": adminUser,
  3220. "patientInfo": patientInfo,
  3221. "PredialysisEvaluation": PredialysisEvaluation,
  3222. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3223. "dialysisPrescription": dialysisPrescription,
  3224. "advices": hisAdvice,
  3225. "monitors": Record,
  3226. "summary": TreatmentSummary,
  3227. "receiverTreatmentAccess": receiverTreatmentAccess,
  3228. "dialysisOrder": dialysisOrder,
  3229. "operators": operators,
  3230. "org_template_info": templateInfo,
  3231. "check": check,
  3232. "schedule": schedule,
  3233. "dialysisway": dialysisway,
  3234. "order": order,
  3235. "doctorAdvice": doctorAdvice,
  3236. "doctor": doctor,
  3237. "nurse": nurse,
  3238. "doctorAdevieInfo": doctorAdevieInfo,
  3239. "total": total,
  3240. "startNuse": startNuse,
  3241. "DoctorName": DoctorName,
  3242. "assessmentAfterDislysis": assessmentAfterDislysis,
  3243. "predialysName": predialysName,
  3244. "FinishNuse": FinishNuse,
  3245. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3246. "dialysiscount": dialysiscount,
  3247. "last_order": lastOrder,
  3248. "project_config": project_config,
  3249. "projects": projects,
  3250. })
  3251. }
  3252. if config.IsOpen == 0 || config.IsOpen == 2 {
  3253. c.ServeSuccessJSON(map[string]interface{}{
  3254. "xtdate": xtdate,
  3255. "users": adminUser,
  3256. "patientInfo": patientInfo,
  3257. "PredialysisEvaluation": PredialysisEvaluation,
  3258. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3259. "dialysisPrescription": dialysisPrescription,
  3260. "advices": DoctorAdvice,
  3261. "monitors": Record,
  3262. "summary": TreatmentSummary,
  3263. "receiverTreatmentAccess": receiverTreatmentAccess,
  3264. "dialysisOrder": dialysisOrder,
  3265. "operators": operators,
  3266. "org_template_info": templateInfo,
  3267. "check": check,
  3268. "schedule": schedule,
  3269. "dialysisway": dialysisway,
  3270. "order": order,
  3271. "doctorAdvice": doctorAdvice,
  3272. "doctor": doctor,
  3273. "nurse": nurse,
  3274. "doctorAdevieInfo": doctorAdevieInfo,
  3275. "total": total,
  3276. "startNuse": startNuse,
  3277. "DoctorName": DoctorName,
  3278. "assessmentAfterDislysis": assessmentAfterDislysis,
  3279. "predialysName": predialysName,
  3280. "FinishNuse": FinishNuse,
  3281. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3282. "dialysiscount": dialysiscount,
  3283. "last_order": lastOrder,
  3284. "project_config": project_config,
  3285. "projects": projects,
  3286. })
  3287. }
  3288. }
  3289. func (c *DialysisApiController) GetLongAdvice() {
  3290. patient_id, _ := c.GetInt64("patient_id")
  3291. adminUserInfo := c.GetAdminUserInfo()
  3292. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3293. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3294. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3295. c.ServeSuccessJSON(map[string]interface{}{
  3296. "status": "1",
  3297. })
  3298. return
  3299. } else { //开启推送提醒
  3300. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3301. var advice_three []*models.DoctorAdvice
  3302. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3303. recordDateStr := time.Now().Format("2006-01-02")
  3304. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3305. nowtime := recordDate.Unix()
  3306. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  3307. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  3308. for _, advice := range advices {
  3309. if advice.FrequencyType == 3 {
  3310. t := time.Now()
  3311. week := int(t.Weekday())
  3312. switch week {
  3313. case 1:
  3314. if strings.Index(advice.WeekDay, "周一") == -1 {
  3315. advice_three = append(advice_three, advice)
  3316. }
  3317. break
  3318. case 2:
  3319. if strings.Index(advice.WeekDay, "周二") == -1 {
  3320. advice_three = append(advice_three, advice)
  3321. }
  3322. break
  3323. case 3:
  3324. if strings.Index(advice.WeekDay, "周三") == -1 {
  3325. advice_three = append(advice_three, advice)
  3326. }
  3327. break
  3328. case 4:
  3329. if strings.Index(advice.WeekDay, "周四") == -1 {
  3330. advice_three = append(advice_three, advice)
  3331. }
  3332. break
  3333. case 5:
  3334. if strings.Index(advice.WeekDay, "周五") == -1 {
  3335. advice_three = append(advice_three, advice)
  3336. }
  3337. break
  3338. case 6:
  3339. if strings.Index(advice.WeekDay, "周六") == -1 {
  3340. advice_three = append(advice_three, advice)
  3341. }
  3342. break
  3343. case 0:
  3344. if strings.Index(advice.WeekDay, "周日") == -1 {
  3345. advice_three = append(advice_three, advice)
  3346. }
  3347. break
  3348. }
  3349. }
  3350. }
  3351. for _, advice := range advices_two {
  3352. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3353. now := p.Unix()
  3354. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3355. dayStr2 := "-" + dayStr
  3356. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3357. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3358. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3359. for _, ad := range advices {
  3360. advice_three = append(advice_three, ad)
  3361. }
  3362. }
  3363. if err == nil {
  3364. c.ServeSuccessJSON(map[string]interface{}{
  3365. "status": "2",
  3366. "advices": advices,
  3367. "advices_two": RemoveRepeatedElement(advice_three),
  3368. "is_open_remind": config.IsOpenRemind,
  3369. })
  3370. }
  3371. }
  3372. }
  3373. func (c *DialysisApiController) GetLongAdviceOne() {
  3374. patient_id, _ := c.GetInt64("patient_id")
  3375. schedule_date := c.GetString("schedule_date")
  3376. adminUserInfo := c.GetAdminUserInfo()
  3377. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3378. timeLayout := "2006-01-02"
  3379. loc, _ := time.LoadLocation("Local")
  3380. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  3381. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3382. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3383. c.ServeSuccessJSON(map[string]interface{}{
  3384. "status": "1",
  3385. })
  3386. return
  3387. } else { //开启推送提醒
  3388. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3389. var advice_three []*models.DoctorAdvice
  3390. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3391. //recordDateStr := time.Now().Format("2006-01-02")
  3392. //recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3393. //
  3394. //nowtime := recordDate.Unix()
  3395. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  3396. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  3397. for _, advice := range advices {
  3398. if advice.FrequencyType == 3 {
  3399. t := time.Now()
  3400. week := int(t.Weekday())
  3401. switch week {
  3402. case 1:
  3403. if strings.Index(advice.WeekDay, "周一") == -1 {
  3404. advice_three = append(advice_three, advice)
  3405. }
  3406. break
  3407. case 2:
  3408. if strings.Index(advice.WeekDay, "周二") == -1 {
  3409. advice_three = append(advice_three, advice)
  3410. }
  3411. break
  3412. case 3:
  3413. if strings.Index(advice.WeekDay, "周三") == -1 {
  3414. advice_three = append(advice_three, advice)
  3415. }
  3416. break
  3417. case 4:
  3418. if strings.Index(advice.WeekDay, "周四") == -1 {
  3419. advice_three = append(advice_three, advice)
  3420. }
  3421. break
  3422. case 5:
  3423. if strings.Index(advice.WeekDay, "周五") == -1 {
  3424. advice_three = append(advice_three, advice)
  3425. }
  3426. break
  3427. case 6:
  3428. if strings.Index(advice.WeekDay, "周六") == -1 {
  3429. advice_three = append(advice_three, advice)
  3430. }
  3431. break
  3432. case 0:
  3433. if strings.Index(advice.WeekDay, "周日") == -1 {
  3434. advice_three = append(advice_three, advice)
  3435. }
  3436. break
  3437. }
  3438. }
  3439. }
  3440. for _, advice := range advices_two {
  3441. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3442. now := p.Unix()
  3443. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3444. dayStr2 := "-" + dayStr
  3445. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3446. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3447. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3448. for _, ad := range advices {
  3449. advice_three = append(advice_three, ad)
  3450. }
  3451. }
  3452. if err == nil {
  3453. c.ServeSuccessJSON(map[string]interface{}{
  3454. "status": "2",
  3455. "advices": advices,
  3456. "advices_two": RemoveRepeatedElement(advice_three),
  3457. "is_open_remind": config.IsOpenRemind,
  3458. })
  3459. }
  3460. }
  3461. }
  3462. func (c *DialysisApiController) GetLongAdviceTwo() {
  3463. patient_id, _ := c.GetInt64("patient_id")
  3464. schedule_date, _ := c.GetInt64("schedule_date")
  3465. adminUserInfo := c.GetAdminUserInfo()
  3466. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3467. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3468. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3469. c.ServeSuccessJSON(map[string]interface{}{
  3470. "status": "1",
  3471. })
  3472. return
  3473. } else { //开启推送提醒
  3474. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3475. var advice_three []*models.DoctorAdvice
  3476. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3477. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  3478. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  3479. for _, advice := range advices {
  3480. if advice.FrequencyType == 3 {
  3481. t := time.Now()
  3482. week := int(t.Weekday())
  3483. switch week {
  3484. case 1:
  3485. if strings.Index(advice.WeekDay, "周一") == -1 {
  3486. advice_three = append(advice_three, advice)
  3487. }
  3488. break
  3489. case 2:
  3490. if strings.Index(advice.WeekDay, "周二") == -1 {
  3491. advice_three = append(advice_three, advice)
  3492. }
  3493. break
  3494. case 3:
  3495. if strings.Index(advice.WeekDay, "周三") == -1 {
  3496. advice_three = append(advice_three, advice)
  3497. }
  3498. break
  3499. case 4:
  3500. if strings.Index(advice.WeekDay, "周四") == -1 {
  3501. advice_three = append(advice_three, advice)
  3502. }
  3503. break
  3504. case 5:
  3505. if strings.Index(advice.WeekDay, "周五") == -1 {
  3506. advice_three = append(advice_three, advice)
  3507. }
  3508. break
  3509. case 6:
  3510. if strings.Index(advice.WeekDay, "周六") == -1 {
  3511. advice_three = append(advice_three, advice)
  3512. }
  3513. break
  3514. case 0:
  3515. if strings.Index(advice.WeekDay, "周日") == -1 {
  3516. advice_three = append(advice_three, advice)
  3517. }
  3518. break
  3519. }
  3520. }
  3521. }
  3522. for _, advice := range advices_two {
  3523. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3524. now := p.Unix()
  3525. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3526. dayStr2 := "-" + dayStr
  3527. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3528. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3529. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3530. for _, ad := range advices {
  3531. advice_three = append(advice_three, ad)
  3532. }
  3533. }
  3534. if err == nil {
  3535. c.ServeSuccessJSON(map[string]interface{}{
  3536. "status": "2",
  3537. "advices": advices,
  3538. "advices_two": RemoveRepeatedElement(advice_three),
  3539. "is_open_remind": config.IsOpenRemind,
  3540. })
  3541. }
  3542. }
  3543. }
  3544. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  3545. newArr = make([]*models.DoctorAdvice, 0)
  3546. for i := 0; i < len(arr); i++ {
  3547. repeat := false
  3548. for j := i + 1; j < len(arr); j++ {
  3549. if arr[i].ID == arr[j].ID {
  3550. repeat = true
  3551. break
  3552. }
  3553. }
  3554. if !repeat {
  3555. newArr = append(newArr, arr[i])
  3556. }
  3557. }
  3558. return
  3559. }
  3560. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  3561. patient, _ := c.GetInt64("id", 0)
  3562. groupNo, _ := c.GetInt64("groupno", 0)
  3563. if patient <= 0 {
  3564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3565. return
  3566. }
  3567. adminUserInfo := c.GetAdminUserInfo()
  3568. dataBody := make(map[string]interface{}, 0)
  3569. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3570. if err != nil {
  3571. utils.ErrorLog(err.Error())
  3572. return
  3573. }
  3574. utils.ErrorLog("%v", dataBody)
  3575. timeLayout := "2006-01-02 15:04"
  3576. loc, _ := time.LoadLocation("Local")
  3577. timeLayout2 := "2006-01-02"
  3578. loc2, _ := time.LoadLocation("Local")
  3579. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3580. utils.ErrorLog("advice_type")
  3581. return
  3582. }
  3583. adviceType := int64(2)
  3584. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3585. utils.ErrorLog("advice_date")
  3586. return
  3587. }
  3588. adviceDate, _ := dataBody["advice_date"].(string)
  3589. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  3590. AdviceDate := theTime.Unix()
  3591. RecordDate := theTime.Unix()
  3592. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3593. utils.ErrorLog("start_time")
  3594. return
  3595. }
  3596. startTime, _ := dataBody["start_time"].(string)
  3597. if len(startTime) == 0 {
  3598. utils.ErrorLog("len(start_time) == 0")
  3599. return
  3600. }
  3601. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  3602. if err != nil {
  3603. utils.ErrorLog(err.Error())
  3604. return
  3605. }
  3606. StartTime := theTimeUnix.Unix()
  3607. fmt.Println("startTIME", StartTime)
  3608. Remark := ""
  3609. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3610. remark, _ := dataBody["remark"].(string)
  3611. Remark = remark
  3612. }
  3613. var advices []*models.GroupAdvice
  3614. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  3615. utils.ErrorLog("advices")
  3616. return
  3617. }
  3618. adviceNames := dataBody["advices"].([]interface{})
  3619. for _, adviceNameMap := range adviceNames {
  3620. adviceNameM := adviceNameMap.(map[string]interface{})
  3621. var advice models.GroupAdvice
  3622. advice.Remark = Remark
  3623. advice.AdviceType = adviceType
  3624. advice.StartTime = StartTime
  3625. advice.AdviceDate = AdviceDate
  3626. advice.RecordDate = RecordDate
  3627. advice.Status = 1
  3628. advice.CreatedTime = time.Now().Unix()
  3629. advice.UpdatedTime = time.Now().Unix()
  3630. advice.StopState = 2
  3631. advice.ExecutionState = 2
  3632. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3633. advice.PatientId = patient
  3634. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3635. advice.IsSettle = 2
  3636. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  3637. utils.ErrorLog("advice_name")
  3638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3639. return
  3640. }
  3641. adviceName, _ := adviceNameM["advice_name"].(string)
  3642. if len(adviceName) == 0 {
  3643. utils.ErrorLog("len(advice_name) == 0")
  3644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3645. return
  3646. }
  3647. advice.AdviceName = adviceName
  3648. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  3649. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  3650. advice.DrugSpec = drugSpec
  3651. }
  3652. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  3653. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  3654. advice.AdviceDesc = adviceDesc
  3655. }
  3656. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  3657. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  3658. advice.DrugSpecUnit = drugSpecUnit
  3659. }
  3660. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  3661. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  3662. // advice.SingleDose = singleDose
  3663. //}
  3664. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  3665. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3666. advice.SingleDose = adviceNameM["single_dose"].(float64)
  3667. }
  3668. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  3669. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  3670. advice.SingleDoseUnit = singleDoseUnit
  3671. }
  3672. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  3673. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  3674. // advice.PrescribingNumber = prescribingNumber
  3675. //}
  3676. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  3677. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  3678. }
  3679. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  3680. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  3681. advice.PrescribingNumberUnit = prescribingNumberUnit
  3682. }
  3683. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  3684. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  3685. advice.DeliveryWay = deliveryWay
  3686. }
  3687. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3688. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3689. advice.ExecutionFrequency = executionFrequency
  3690. }
  3691. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  3692. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  3693. advice.FrequencyType = frequency_type
  3694. }
  3695. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  3696. day_count := int64(adviceNameM["day_count"].(float64))
  3697. advice.DayCount = day_count
  3698. }
  3699. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  3700. way := int64(adviceNameM["way"].(float64))
  3701. advice.Way = way
  3702. }
  3703. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  3704. drug_id := int64(adviceNameM["drug_id"].(float64))
  3705. advice.DrugId = drug_id
  3706. }
  3707. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  3708. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  3709. advice.DrugNameId = drug_name_id
  3710. }
  3711. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  3712. week_day, _ := adviceNameM["week_day"].(string)
  3713. advice.WeekDay = week_day
  3714. }
  3715. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  3716. template_id, _ := adviceNameM["template_id"].(string)
  3717. advice.TemplateId = template_id
  3718. }
  3719. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3720. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3721. advice.ExecutionFrequency = executionFrequency
  3722. }
  3723. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  3724. children := adviceNameM["child"].([]interface{})
  3725. if len(children) > 0 {
  3726. for _, childrenMap := range children {
  3727. childMap := childrenMap.(map[string]interface{})
  3728. var child models.GroupAdvice
  3729. child.Remark = Remark
  3730. child.AdviceType = adviceType
  3731. child.StartTime = StartTime
  3732. child.AdviceDate = AdviceDate
  3733. child.RecordDate = RecordDate
  3734. child.Status = 1
  3735. child.CreatedTime = time.Now().Unix()
  3736. child.UpdatedTime = time.Now().Unix()
  3737. child.StopState = 2
  3738. child.ExecutionState = 2
  3739. child.UserOrgId = adminUserInfo.CurrentOrgId
  3740. child.PatientId = patient
  3741. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  3742. child.IsSettle = 2
  3743. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  3744. utils.ErrorLog("child advice_name")
  3745. return
  3746. }
  3747. childAdviceName, _ := childMap["advice_name"].(string)
  3748. if len(childAdviceName) == 0 {
  3749. utils.ErrorLog("len(child advice_name) == 0")
  3750. return
  3751. }
  3752. child.AdviceName = childAdviceName
  3753. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  3754. childAdviceDesc, _ := childMap["advice_desc"].(string)
  3755. child.AdviceDesc = childAdviceDesc
  3756. }
  3757. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  3758. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  3759. child.DrugSpec = childDrugSpec
  3760. }
  3761. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  3762. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  3763. child.DrugSpecUnit = childDrugSpecUnit
  3764. }
  3765. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  3766. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3767. child.SingleDose = childSingleDose
  3768. }
  3769. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  3770. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3771. child.SingleDose = childMap["single_dose"].(float64)
  3772. }
  3773. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  3774. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3775. child.Remark = childMap["remark"].(string)
  3776. }
  3777. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  3778. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3779. child.DrugId = int64(childMap["drug_id"].(float64))
  3780. }
  3781. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  3782. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  3783. child.SingleDoseUnit = childSingleDoseUnit
  3784. }
  3785. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  3786. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  3787. child.PrescribingNumber = childPrescribingNumber
  3788. }
  3789. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  3790. //childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  3791. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  3792. }
  3793. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  3794. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  3795. child.PrescribingNumberUnit = childPrescribingNumberUnit
  3796. }
  3797. child.DeliveryWay = advice.DeliveryWay
  3798. child.ExecutionFrequency = advice.ExecutionFrequency
  3799. advice.Children = append(advice.Children, &child)
  3800. }
  3801. }
  3802. }
  3803. advices = append(advices, &advice)
  3804. }
  3805. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  3806. redis := service.RedisClient()
  3807. formatAdviceDate := theTime.Format("2006-01-02")
  3808. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3809. redis.Set(key, "", time.Second)
  3810. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  3811. redis.Set(keyOne, "", time.Second)
  3812. keyFour := "scheduals_" + formatAdviceDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3813. redis.Set(keyFour, "", time.Second)
  3814. defer redis.Close()
  3815. if err != nil {
  3816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3817. return
  3818. }
  3819. c.ServeSuccessJSON(map[string]interface{}{
  3820. "msg": "ok",
  3821. "advices": list,
  3822. })
  3823. return
  3824. }
  3825. func (c *DialysisApiController) GetSolution() {
  3826. patient_id, _ := c.GetInt64("patient_id")
  3827. mode_id, _ := c.GetInt64("mode_id")
  3828. adminUserInfo := c.GetAdminUserInfo()
  3829. solution, err := service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  3830. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  3831. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, mode_id)
  3832. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.CurrentOrgId)
  3833. if err != nil {
  3834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3835. return
  3836. }
  3837. c.ServeSuccessJSON(map[string]interface{}{
  3838. "solution": solution,
  3839. "prescription": prescription,
  3840. "system_prescription": system_prescription,
  3841. "dialysisPrescription": dialysisPrescription,
  3842. })
  3843. }
  3844. func (c *DialysisApiController) GetSchedule() {
  3845. schedual_type, _ := c.GetInt64("schedual_type")
  3846. adminUserInfo := c.GetAdminUserInfo()
  3847. //timeLayout := "2006-01-02 15:04:05"
  3848. //
  3849. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  3850. //loc, _ := time.LoadLocation("Local")
  3851. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  3852. //scheduleTime := theStartTime.Unix()
  3853. scheduleTime, _ := c.GetInt64("record_date")
  3854. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  3855. c.ServeSuccessJSON(map[string]interface{}{
  3856. "number": deviceNumber,
  3857. })
  3858. }
  3859. func (this *DialysisApiController) GetTodayMonitor() {
  3860. thisTime := time.Now()
  3861. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3862. timeLayout := "2006-01-02 15:04:05"
  3863. loc, _ := time.LoadLocation("Local")
  3864. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3865. theAssessmentDateTime := theStartTime.Unix()
  3866. patientID, _ := this.GetInt64("patient_id")
  3867. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3868. adminInfo := this.GetAdminUserInfo()
  3869. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  3870. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  3871. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  3872. var ultrafiltration_rate float64
  3873. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  3874. //针对福建医师汇 获取透前评估预增脱水量
  3875. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  3876. fmt.Println("透前评估数据", evaluation)
  3877. if prescription.ID > 0 {
  3878. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3879. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3880. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  3881. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3882. record.UltrafiltrationRate = ultrafiltration_rate
  3883. }
  3884. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10121 {
  3885. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3886. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3887. record.UltrafiltrationRate = ultrafiltration_rate
  3888. }
  3889. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10234 {
  3890. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3891. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3892. record.UltrafiltrationRate = ultrafiltration_rate
  3893. }
  3894. if template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.CurrentOrgId == 9538
  3895. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3896. record.UltrafiltrationRate = ultrafiltration_rate
  3897. }
  3898. if template.TemplateId == 41 { //adminInfo.CurrentOrgId == 9538
  3899. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3900. record.UltrafiltrationRate = ultrafiltration_rate
  3901. }
  3902. if template.TemplateId == 43 { //adminInfo.CurrentOrgId == 9538
  3903. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3904. record.UltrafiltrationRate = ultrafiltration_rate
  3905. }
  3906. if template.TemplateId == 46 || template.TemplateId == 54 { //adminInfo.CurrentOrgId == 9538
  3907. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3908. record.UltrafiltrationRate = ultrafiltration_rate
  3909. }
  3910. if template.TemplateId == 47 { //adminInfo.CurrentOrgId == 9538
  3911. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3912. record.UltrafiltrationRate = ultrafiltration_rate
  3913. }
  3914. // 只针对方济医院
  3915. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  3916. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3917. ultrafiltration_rate = value
  3918. record.UltrafiltrationRate = ultrafiltration_rate
  3919. }
  3920. //长沙南雅
  3921. if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10340 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 9829 || adminInfo.CurrentOrgId == 10440 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
  3922. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3923. record.UltrafiltrationRate = ultrafiltration_rate
  3924. }
  3925. }
  3926. }
  3927. // record.UltrafiltrationRate = ultrafiltration_rate
  3928. record.UltrafiltrationVolume = 0
  3929. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  3930. if ultrafiltration_rate > 0 {
  3931. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3932. record.UltrafiltrationVolume = value
  3933. }
  3934. }
  3935. 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 {
  3936. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  3937. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3938. record.UltrafiltrationVolume = ultrafiltration_volume
  3939. }
  3940. }
  3941. //长沙南雅
  3942. if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
  3943. if ultrafiltration_rate > 0 {
  3944. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3945. record.UltrafiltrationVolume = ultrafiltration_volume
  3946. }
  3947. }
  3948. if template.TemplateId == 47 || template.TemplateId == 54 {
  3949. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3950. }
  3951. this.ServeSuccessJSON(map[string]interface{}{
  3952. "monitor": record,
  3953. })
  3954. }
  3955. func (c *DialysisApiController) UploadDryWeight() {
  3956. patient_id, _ := c.GetInt64("id")
  3957. dry_weight, _ := c.GetFloat("dry_weight")
  3958. doctor_id, _ := c.GetInt64("doctor_id")
  3959. remark := c.GetString("remark")
  3960. adminUserInfo := c.GetAdminUserInfo()
  3961. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  3962. fmt.Println(err)
  3963. if err == gorm.ErrRecordNotFound {
  3964. dryWeight := &models.SgjPatientDryweight{
  3965. PatientId: patient_id,
  3966. DryWeight: dry_weight,
  3967. Remakes: remark,
  3968. Ctime: time.Now().Unix(),
  3969. Mtime: time.Now().Unix(),
  3970. Creator: doctor_id,
  3971. Status: 1,
  3972. UserOrgId: adminUserInfo.CurrentOrgId,
  3973. AdjustedValue: "/",
  3974. UserId: adminUserInfo.AdminUser.Id,
  3975. }
  3976. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3977. loc, _ := time.LoadLocation("Local")
  3978. nowTime := time.Now()
  3979. nowDay := nowTime.Format("2006-01-02")
  3980. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3981. redis := service.RedisClient()
  3982. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  3983. redis.Set(keyOne, "", time.Second)
  3984. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3985. redis.Set(key, "", time.Second)
  3986. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3987. redis.Set(keyTwo, "", time.Second)
  3988. redis.Close()
  3989. if createErr == nil {
  3990. c.ServeSuccessJSON(map[string]interface{}{
  3991. "msg": "提交成功",
  3992. "weight": dryWeight,
  3993. })
  3994. }
  3995. } else {
  3996. dryWeight := &models.SgjPatientDryweight{
  3997. PatientId: patient_id,
  3998. DryWeight: dry_weight,
  3999. Remakes: remark,
  4000. Ctime: time.Now().Unix(),
  4001. Mtime: time.Now().Unix(),
  4002. Creator: doctor_id,
  4003. Status: 1,
  4004. UserOrgId: adminUserInfo.CurrentOrgId,
  4005. AdjustedValue: "/",
  4006. UserId: adminUserInfo.AdminUser.Id,
  4007. }
  4008. var value float64
  4009. value = dry_weight - weightAdjust.DryWeight
  4010. fmt.Println(value)
  4011. if value < 0 {
  4012. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4013. } else if value == 0 {
  4014. dryWeight.AdjustedValue = "/"
  4015. } else if value > 0 {
  4016. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4017. }
  4018. fmt.Println(value)
  4019. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4020. loc, _ := time.LoadLocation("Local")
  4021. nowTime := time.Now()
  4022. nowDay := nowTime.Format("2006-01-02")
  4023. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4024. redis := service.RedisClient()
  4025. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4026. redis.Set(keyOne, "", time.Second)
  4027. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4028. redis.Set(key, "", time.Second)
  4029. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4030. redis.Set(keyTwo, "", time.Second)
  4031. redis.Close()
  4032. if createErr == nil {
  4033. c.ServeSuccessJSON(map[string]interface{}{
  4034. "msg": "提交成功",
  4035. "weight": dryWeight,
  4036. })
  4037. }
  4038. }
  4039. }
  4040. func (this *DialysisApiController) GetFuncPurview() {
  4041. adminUserInfo := this.GetAdminUserInfo()
  4042. user_id := adminUserInfo.AdminUser.Id
  4043. app_id := adminUserInfo.CurrentAppId
  4044. org_id := adminUserInfo.CurrentOrgId
  4045. create_url := this.GetString("create_url")
  4046. modify_url := this.GetString("modify_url")
  4047. modify_other_url := this.GetString("modify_other_url")
  4048. del_url := this.GetString("del_url")
  4049. del_other_url := this.GetString("del_other_url")
  4050. exce_url := this.GetString("exce_url")
  4051. check_url := this.GetString("check_url")
  4052. modify_exce_url := this.GetString("modify_exce_url")
  4053. module, _ := this.GetInt64("module", 0)
  4054. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  4055. var is_has_create bool
  4056. var is_has_modify bool
  4057. var is_has_modify_other bool
  4058. var is_has_del bool
  4059. var is_has_del_other bool
  4060. var is_has_exce bool
  4061. var is_has_check bool
  4062. var is_has_modify_exce bool
  4063. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  4064. if adminUserInfo.AdminUser.Id != org.Creator {
  4065. if app_role != nil {
  4066. if len(app_role.RoleIds) > 0 {
  4067. roles := strings.Split(app_role.RoleIds, ",")
  4068. var userRolePurviews string
  4069. for _, item := range roles {
  4070. role_id, _ := strconv.ParseInt(item, 10, 64)
  4071. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  4072. if len(userRolePurviews) == 0 {
  4073. userRolePurviews = purviews
  4074. } else {
  4075. userRolePurviews = userRolePurviews + "," + purviews
  4076. }
  4077. }
  4078. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  4079. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  4080. for _, item := range funcPurviews {
  4081. //for _, url := range strings.Split(item.Urlfor,","){
  4082. if strings.Split(item.Urlfor, ",")[1] == create_url {
  4083. is_has_create = true
  4084. }
  4085. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  4086. is_has_modify = true
  4087. }
  4088. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  4089. is_has_modify_other = true
  4090. }
  4091. if strings.Split(item.Urlfor, ",")[1] == del_url {
  4092. is_has_del = true
  4093. }
  4094. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  4095. is_has_del_other = true
  4096. }
  4097. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  4098. is_has_exce = true
  4099. }
  4100. if strings.Split(item.Urlfor, ",")[1] == check_url {
  4101. is_has_check = true
  4102. }
  4103. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  4104. is_has_modify_exce = true
  4105. }
  4106. }
  4107. } else {
  4108. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  4109. return
  4110. }
  4111. this.ServeSuccessJSON(map[string]interface{}{
  4112. "is_has_create": is_has_create,
  4113. "is_has_modify": is_has_modify,
  4114. "is_has_modify_other": is_has_modify_other,
  4115. "is_has_del": is_has_del,
  4116. "is_has_del_other": is_has_del_other,
  4117. "is_has_exce": is_has_exce,
  4118. "is_has_check": is_has_check,
  4119. "is_has_modify_exce": is_has_modify_exce,
  4120. "module": module,
  4121. })
  4122. } else {
  4123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  4124. return
  4125. }
  4126. } else {
  4127. this.ServeSuccessJSON(map[string]interface{}{
  4128. "is_has_create": true,
  4129. "is_has_modify": true,
  4130. "is_has_modify_other": true,
  4131. "is_has_del": true,
  4132. "is_has_del_other": true,
  4133. "is_has_exce": true,
  4134. "is_has_check": true,
  4135. "is_has_modify_exce": true,
  4136. "module": true,
  4137. })
  4138. }
  4139. }
  4140. func (this *DialysisApiController) GetOrderDoctorAdvice() {
  4141. patient_id, _ := this.GetInt64("patient_id", 0)
  4142. advice_date, _ := this.GetInt64("advice_date")
  4143. adminUserInfo := this.GetAdminUserInfo()
  4144. doctorAdvice, _ := service.GetBloodDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4145. hisDoctorAdvice, _ := service.GetHisDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4146. this.ServeSuccessJSON(map[string]interface{}{
  4147. "doctorAdvice": doctorAdvice,
  4148. "hisDoctorAdvice": hisDoctorAdvice,
  4149. })
  4150. }
  4151. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  4152. change_type, _ := this.GetInt64("type", 0)
  4153. record_date := this.GetString("record_time")
  4154. patient_id, _ := this.GetInt64("patient_id", 0)
  4155. timeLayout := "2006-01-02"
  4156. loc, _ := time.LoadLocation("Local")
  4157. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4158. record_time := theAdviceRecordTime.Unix()
  4159. adminUserInfo := this.GetAdminUserInfo()
  4160. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  4161. if err == nil {
  4162. if len(advices) == 0 {
  4163. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4164. return
  4165. } else {
  4166. this.ServeSuccessJSON(map[string]interface{}{
  4167. "advices": advices,
  4168. "schedule": sch,
  4169. })
  4170. return
  4171. }
  4172. } else {
  4173. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4174. return
  4175. }
  4176. }
  4177. func (c *DialysisApiController) GetDialysisGoods() {
  4178. schedualDate := c.GetString("schedule_date")
  4179. schedule_type, _ := c.GetInt64("schedule_type")
  4180. partition_id, _ := c.GetInt64("partition_id")
  4181. page, _ := c.GetInt("page")
  4182. limit, _ := c.GetInt("limit")
  4183. keywords := c.GetString("keywords")
  4184. patient_id, _ := c.GetInt64("patient_id")
  4185. good_type, _ := c.GetInt64("good_type")
  4186. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  4187. if parseDateErr != nil && len(schedualDate) != 0 {
  4188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4189. return
  4190. }
  4191. schedualEndDate := int64(0)
  4192. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  4193. if parseDateErr != nil && len(schedualDate) != 0 {
  4194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4195. return
  4196. }
  4197. schedualEndDate = endDate.Unix()
  4198. adminUser := c.GetAdminUserInfo()
  4199. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  4200. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  4201. if err == gorm.ErrRecordNotFound {
  4202. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4203. var ids []int64
  4204. for _, item := range list {
  4205. ids = append(ids, item.PatientId)
  4206. }
  4207. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4208. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4209. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4210. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4211. item.LastAutomaticReduceDetail = goodUser
  4212. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4213. }
  4214. c.ServeSuccessJSON(map[string]interface{}{
  4215. "dialysis_goods": dialysisGoods,
  4216. "good_type": goodTypes,
  4217. "total": total,
  4218. })
  4219. return
  4220. } else if err == nil {
  4221. //获取当天排班的每个患者的库存使用情况
  4222. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4223. var ids []int64
  4224. for _, item := range list {
  4225. ids = append(ids, item.PatientId)
  4226. }
  4227. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4228. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4229. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4230. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4231. fmt.Println(goodUser)
  4232. fmt.Println(lastGoodUserDetial)
  4233. item.LastAutomaticReduceDetail = goodUser
  4234. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4235. }
  4236. if err == nil {
  4237. c.ServeSuccessJSON(map[string]interface{}{
  4238. "dialysis_goods": dialysisGoods,
  4239. "good_type": goodTypes,
  4240. "total": total,
  4241. })
  4242. return
  4243. } else {
  4244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4245. return
  4246. }
  4247. } else if err != nil {
  4248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4249. return
  4250. }
  4251. }
  4252. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  4253. start_time := c.GetString("start_time")
  4254. end_time := c.GetString("end_time")
  4255. timeLayout := "2006-01-02"
  4256. loc, _ := time.LoadLocation("Local")
  4257. var theStartTime int64
  4258. if len(start_time) > 0 {
  4259. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4260. if err != nil {
  4261. utils.ErrorLog(err.Error())
  4262. }
  4263. theStartTime = theTime.Unix()
  4264. }
  4265. var theEndtTime int64
  4266. if len(end_time) > 0 {
  4267. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4268. if err != nil {
  4269. utils.ErrorLog(err.Error())
  4270. }
  4271. theEndtTime = theTime.Unix()
  4272. }
  4273. adminUser := c.GetAdminUserInfo()
  4274. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  4275. if err == nil {
  4276. c.ServeSuccessJSON(map[string]interface{}{
  4277. "stock_out": outInfo,
  4278. })
  4279. return
  4280. } else {
  4281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4282. return
  4283. }
  4284. }
  4285. func (c *DialysisApiController) GetRoleList() {
  4286. orgId := c.GetAdminUserInfo().CurrentOrgId
  4287. admin_user_id, _ := c.GetInt64("admin_user_id")
  4288. list, err := service.GetRoleList(orgId, admin_user_id)
  4289. if err == nil {
  4290. c.ServeSuccessJSON(map[string]interface{}{
  4291. "adminRole": list,
  4292. })
  4293. return
  4294. } else {
  4295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4296. return
  4297. }
  4298. }
  4299. func (c *DialysisApiController) GetInitPrintData() {
  4300. patient_id, _ := c.GetInt64("patient_id")
  4301. record_date, _ := c.GetInt64("record_date")
  4302. orgId := c.GetAdminUserInfo().CurrentOrgId
  4303. list, err := service.GetInitPrintData(patient_id, record_date, orgId)
  4304. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, record_date, orgId)
  4305. if err == nil {
  4306. c.ServeSuccessJSON(map[string]interface{}{
  4307. "list": list,
  4308. "assessmentAfterDislysis": assessmentAfterDislysis,
  4309. })
  4310. return
  4311. } else {
  4312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4313. return
  4314. }
  4315. }
  4316. func (c *DialysisApiController) GetInitPrintDataOne() {
  4317. patient_id, _ := c.GetInt64("patient_id")
  4318. start_time := c.GetString("record_date")
  4319. timeLayout := "2006-01-02"
  4320. loc, _ := time.LoadLocation("Local")
  4321. var theStartTime int64
  4322. if len(start_time) > 0 {
  4323. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4324. if err != nil {
  4325. utils.ErrorLog(err.Error())
  4326. }
  4327. theStartTime = theTime.Unix()
  4328. }
  4329. orgId := c.GetAdminUserInfo().CurrentOrgId
  4330. list, err := service.GetInitPrintData(patient_id, theStartTime, orgId)
  4331. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, theStartTime, orgId)
  4332. if err == nil {
  4333. c.ServeSuccessJSON(map[string]interface{}{
  4334. "list": list,
  4335. "assessmentAfterDislysis": assessmentAfterDislysis,
  4336. })
  4337. return
  4338. } else {
  4339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4340. return
  4341. }
  4342. }
  4343. // 新接口
  4344. func (this *DialysisApiController) GetPatientDialysisSolutionGroupList() {
  4345. keyword := this.GetString("keywords")
  4346. limit, _ := this.GetInt64("limit")
  4347. page, _ := this.GetInt64("page")
  4348. partition_id, _ := this.GetInt64("partition_id")
  4349. schedule_type, _ := this.GetInt64("schedule_type")
  4350. start_time := this.GetString("schedule_date")
  4351. advice_ids := this.GetString("ids")
  4352. var ids []string
  4353. if advice_ids != "" {
  4354. ids = strings.Split(advice_ids, ",")
  4355. }
  4356. timeLayout := "2006-01-02"
  4357. loc, _ := time.LoadLocation("Local")
  4358. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4359. orgId := this.GetAdminUserInfo().CurrentOrgId
  4360. _, config := service.FindXTHisRecordByOrgId(orgId)
  4361. goodType, _ := service.GetAllGoodType(orgId)
  4362. if config.IsOpen != 1 {
  4363. list, total, err := service.GetPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4364. if err == nil {
  4365. this.ServeSuccessJSON(map[string]interface{}{
  4366. "list": list,
  4367. "total": total,
  4368. "config": config,
  4369. "goodType": goodType,
  4370. })
  4371. return
  4372. } else {
  4373. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4374. return
  4375. }
  4376. }
  4377. if config.IsOpen == 1 {
  4378. list, total, err := service.GetHisPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4379. if err == nil {
  4380. this.ServeSuccessJSON(map[string]interface{}{
  4381. "list": list,
  4382. "total": total,
  4383. "config": config,
  4384. "goodType": goodType,
  4385. })
  4386. return
  4387. }
  4388. }
  4389. }
  4390. func (this *DialysisApiController) GetDialysisAdviceTemplateList() {
  4391. keyword := this.GetString("keywords")
  4392. limit, _ := this.GetInt64("limit")
  4393. page, _ := this.GetInt64("page")
  4394. partition_id, _ := this.GetInt64("partition_id")
  4395. schedule_type, _ := this.GetInt64("schedule_type")
  4396. start_time := this.GetString("schedule_date")
  4397. ids := this.GetString("ids")
  4398. var idArray []string
  4399. if ids != "" {
  4400. idArray = strings.Split(ids, ",")
  4401. }
  4402. timeLayout := "2006-01-02"
  4403. loc, _ := time.LoadLocation("Local")
  4404. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4405. orgId := this.GetAdminUserInfo().CurrentOrgId
  4406. list, total, err := service.GetDialysisAdviceTemplateList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  4407. tablelist, _, err := service.GetDialysisAdviceSchedulistSix(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  4408. //获取长期医嘱
  4409. adviceList, _ := service.GetAllLongAdviceList(orgId)
  4410. _, config := service.FindXTHisRecordByOrgId(orgId)
  4411. drugList, _ := service.GetAllBaseDrugListTwenty(orgId)
  4412. if err == nil {
  4413. this.ServeSuccessJSON(map[string]interface{}{
  4414. "list": list,
  4415. "total": total,
  4416. "adviceList": adviceList,
  4417. "config": config,
  4418. "drugList": drugList,
  4419. "tablelist": tablelist,
  4420. })
  4421. return
  4422. } else {
  4423. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4424. return
  4425. }
  4426. }
  4427. func (this *DialysisApiController) SaveDialysisSetting() {
  4428. orgId := this.GetAdminUserInfo().CurrentOrgId
  4429. device_number_set, _ := this.GetInt64("device_number_set")
  4430. device_type_set, _ := this.GetInt64("device_type_set")
  4431. name_set, _ := this.GetInt64("name_set")
  4432. admission_number_set, _ := this.GetInt64("admission_number_set")
  4433. dialysis_no_set, _ := this.GetInt64("dialysis_no_set")
  4434. weight_befor_set, _ := this.GetInt64("weight_befor_set")
  4435. dry_weight_set, _ := this.GetInt64("dry_weight_set")
  4436. blood_pressure_set, _ := this.GetInt64("blood_pressure_set")
  4437. ultrafiltration_volume_set, _ := this.GetInt64("ultrafiltration_volume_set")
  4438. internal_fistula_set, _ := this.GetInt64("internal_fistula_set")
  4439. blood_flow_volume_set, _ := this.GetInt64("blood_flow_volume_set")
  4440. anticoagulant_set, _ := this.GetInt64("anticoagulant_set")
  4441. sealing_fluid_dispose_set, _ := this.GetInt64("sealing_fluid_dispose_set")
  4442. mode_id_set, _ := this.GetInt64("mode_id_set")
  4443. dialysis_time_set, _ := this.GetInt64("dialysis_time_set")
  4444. dialysis_dialyszers_set, _ := this.GetInt64("dialysis_dialyszers_set")
  4445. dialysis_irrigation_set, _ := this.GetInt64("dialysis_irrigation_set")
  4446. gaijiliang_set, _ := this.GetInt64("gaijiliang_set")
  4447. kalium_set, _ := this.GetInt64("kalium_set")
  4448. displace_liqui_value_set, _ := this.GetInt64("displace_liqui_value_set")
  4449. bicarbonate_set, _ := this.GetInt64("bicarbonate_set")
  4450. glucose_set, _ := this.GetInt64("glucose_set")
  4451. sodium_set, _ := this.GetInt64("sodium_set")
  4452. calcium_set, _ := this.GetInt64("calcium_set")
  4453. blood_access_set, _ := this.GetInt64("blood_access_set")
  4454. dialyzer_perfusion_apparatus_set, _ := this.GetInt64("dialyzer_perfusion_apparatus_set")
  4455. displace_liqui_part_set, _ := this.GetInt64("displace_liqui_part_set")
  4456. dialysisSetting := models.XtDialysisSetting{
  4457. Sodium: sodium_set,
  4458. Calcium: calcium_set,
  4459. BloodAccess: blood_access_set,
  4460. DialyzerPerfusionApparatus: dialyzer_perfusion_apparatus_set,
  4461. DisplaceLiquiPart: displace_liqui_part_set,
  4462. UserOrgId: orgId,
  4463. Status: 1,
  4464. DeviceNumber: device_number_set,
  4465. DeviceType: device_type_set,
  4466. Name: name_set,
  4467. AdmissionNumber: admission_number_set,
  4468. DialysisNo: dialysis_no_set,
  4469. WeightBefor: weight_befor_set,
  4470. DryWeight: dry_weight_set,
  4471. BloodPressure: blood_pressure_set,
  4472. UltrafiltrationVolume: ultrafiltration_volume_set,
  4473. InternalFistula: internal_fistula_set,
  4474. BloodFlowVolume: blood_flow_volume_set,
  4475. Anticoagulant: anticoagulant_set,
  4476. SealingFluidDispose: sealing_fluid_dispose_set,
  4477. ModeId: mode_id_set,
  4478. DialysisTime: dialysis_time_set,
  4479. DialysisDialyszers: dialysis_dialyszers_set,
  4480. DialysisIrrigation: dialysis_irrigation_set,
  4481. Gaijiliang: gaijiliang_set,
  4482. Kalium: kalium_set,
  4483. DisplaceLiquiValue: displace_liqui_value_set,
  4484. Bicarbonate: bicarbonate_set,
  4485. Glucose: glucose_set,
  4486. Ctime: time.Now().Unix(),
  4487. Mtime: time.Now().Unix(),
  4488. }
  4489. err := service.SaveDialysisSetting(dialysisSetting)
  4490. if err == nil {
  4491. this.ServeSuccessJSON(map[string]interface{}{
  4492. "dialysisSetting": dialysisSetting,
  4493. })
  4494. return
  4495. } else {
  4496. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4497. return
  4498. }
  4499. }
  4500. func (this *DialysisApiController) GetDialysisSetting() {
  4501. orgId := this.GetAdminUserInfo().CurrentOrgId
  4502. dialysisSett, _ := service.GetDialysisSetting(orgId)
  4503. this.ServeSuccessJSON(map[string]interface{}{
  4504. "dialysisSett": dialysisSett,
  4505. })
  4506. return
  4507. }
  4508. func (this *DialysisApiController) GetDialysisParameterList() {
  4509. keyword := this.GetString("keywords")
  4510. limit, _ := this.GetInt64("limit")
  4511. page, _ := this.GetInt64("page")
  4512. //partition_id, _ := this.GetInt64("partition_id")
  4513. partion_type := this.GetString("partition_id")
  4514. idSplit := strings.Split(partion_type, ",")
  4515. schedule_type, _ := this.GetInt64("schedule_type")
  4516. start_time := this.GetString("schedule_date")
  4517. timeLayout := "2006-01-02"
  4518. loc, _ := time.LoadLocation("Local")
  4519. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4520. orgId := this.GetAdminUserInfo().CurrentOrgId
  4521. scheduids := this.GetString("ids")
  4522. var ids []string
  4523. if scheduids != "" {
  4524. ids = strings.Split(scheduids, ",")
  4525. }
  4526. list, total, err := service.GetDialysisParameterList(keyword, limit, page, idSplit, schedule_type, startTime.Unix(), orgId, ids)
  4527. dialysisSett, _ := service.GetDialysisSetting(orgId)
  4528. if err == nil {
  4529. this.ServeSuccessJSON(map[string]interface{}{
  4530. "list": list,
  4531. "total": total,
  4532. "dialysisSett": dialysisSett,
  4533. })
  4534. return
  4535. } else {
  4536. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4537. return
  4538. }
  4539. }
  4540. func (this *DialysisApiController) GetDialysisGoodTotalCount() {
  4541. orgId := this.GetAdminUserInfo().CurrentOrgId
  4542. schedule_type, _ := this.GetInt64("schedule_type")
  4543. //partion_type, _ := this.GetInt64("partion_type")
  4544. start_time := this.GetString("selected_date")
  4545. partion_type := this.GetString("partion_type")
  4546. var ids []string
  4547. ids = strings.Split(partion_type, ",")
  4548. timeLayout := "2006-01-02"
  4549. loc, _ := time.LoadLocation("Local")
  4550. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4551. list, err := service.GetDialysisGoodTotalCount(orgId, schedule_type, ids, startTime.Unix())
  4552. if err == nil {
  4553. this.ServeSuccessJSON(map[string]interface{}{
  4554. "list": list,
  4555. })
  4556. return
  4557. } else {
  4558. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4559. return
  4560. }
  4561. }
  4562. func (this *DialysisApiController) GetDialysisAdviceSchedulist() {
  4563. orgId := this.GetAdminUserInfo().CurrentOrgId
  4564. schedule_type, _ := this.GetInt64("schedule_type")
  4565. //partion_type, _ := this.GetInt64("partion_type")
  4566. partion_type := this.GetString("partion_type")
  4567. var ids []string
  4568. ids = strings.Split(partion_type, ",")
  4569. start_time := this.GetString("selected_date")
  4570. timeLayout := "2006-01-02"
  4571. loc, _ := time.LoadLocation("Local")
  4572. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4573. list, err := service.GetDialysisAdviceSchedulist(orgId, schedule_type, ids, startTime.Unix())
  4574. tablelist, _ := service.GetDialysisAdviceSchedulistTwo(orgId, schedule_type, ids, startTime.Unix())
  4575. //获取长期医嘱
  4576. adviceList, _ := service.GetAllLongAdviceList(orgId)
  4577. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  4578. _, config := service.FindXTHisRecordByOrgId(orgId)
  4579. if err == nil {
  4580. this.ServeSuccessJSON(map[string]interface{}{
  4581. "list": list,
  4582. "drug": drug,
  4583. "adviceList": adviceList,
  4584. "config": config,
  4585. "tablelist": tablelist,
  4586. })
  4587. return
  4588. } else {
  4589. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4590. return
  4591. }
  4592. }
  4593. func (this *DialysisApiController) GetDialysisParameterGoodList() {
  4594. orgId := this.GetAdminUserInfo().CurrentOrgId
  4595. schedule_type, _ := this.GetInt64("schedule_type")
  4596. partion_type, _ := this.GetInt64("partion_type")
  4597. start_time := this.GetString("selected_date")
  4598. timeLayout := "2006-01-02"
  4599. loc, _ := time.LoadLocation("Local")
  4600. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4601. list, err := service.GetDialysisParameterGoodList(orgId, schedule_type, partion_type, startTime.Unix())
  4602. if err == nil {
  4603. this.ServeSuccessJSON(map[string]interface{}{
  4604. "list": list,
  4605. })
  4606. return
  4607. } else {
  4608. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4609. return
  4610. }
  4611. }
  4612. func (this *DialysisApiController) SaveHisDialysis() {
  4613. var ids []string
  4614. advice_ids := this.GetString("ids")
  4615. ids = strings.Split(advice_ids, ",")
  4616. orgId := this.GetAdminUserInfo().CurrentOrgId
  4617. service.SaveHisDialysis(orgId, ids)
  4618. returnData := make(map[string]interface{}, 0)
  4619. returnData["msg"] = "ok"
  4620. this.ServeSuccessJSON(returnData)
  4621. return
  4622. }
  4623. func (this *DialysisApiController) GetHisDialysisGoodCount() {
  4624. orgId := this.GetAdminUserInfo().CurrentOrgId
  4625. schedule_type, _ := this.GetInt64("schedule_type")
  4626. //partion_type, _ := this.GetInt64("partion_type")
  4627. partion_type := this.GetString("partion_type")
  4628. var ids []string
  4629. ids = strings.Split(partion_type, ",")
  4630. start_time := this.GetString("selected_date")
  4631. timeLayout := "2006-01-02"
  4632. loc, _ := time.LoadLocation("Local")
  4633. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4634. list, _ := service.GetHisDialysisGoodCountTwo(orgId, schedule_type, ids, startTime.Unix())
  4635. this.ServeSuccessJSON(map[string]interface{}{
  4636. "list": list,
  4637. })
  4638. return
  4639. }
  4640. func (this *DialysisApiController) GetPatientSchedule() {
  4641. orgId := this.GetAdminUserInfo().CurrentOrgId
  4642. patient_id, _ := this.GetInt64("patient_id")
  4643. schedule_date, _ := this.GetInt64("schedule_date")
  4644. schedulePatient, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgId)
  4645. this.ServeSuccessJSON(map[string]interface{}{
  4646. "schedulePatient": schedulePatient,
  4647. })
  4648. }
  4649. func (c *DialysisApiController) GetSchedulePrintList() {
  4650. page, _ := c.GetInt64("page", 1)
  4651. limit, _ := c.GetInt64("limit", 10)
  4652. schedulType, _ := c.GetInt64("schedule_type", 0)
  4653. partitionType, _ := c.GetInt64("partition_type", 0)
  4654. keywords := c.GetString("keywords")
  4655. schedule_date := c.GetString("schedule_date")
  4656. timeLayout := "2006-01-02"
  4657. loc, _ := time.LoadLocation("Local")
  4658. var theStartTime int64
  4659. if len(schedule_date) > 0 {
  4660. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  4661. if err != nil {
  4662. utils.ErrorLog(err.Error())
  4663. }
  4664. theStartTime = theTime.Unix()
  4665. }
  4666. adminUserInfo := c.GetAdminUserInfo()
  4667. list, total, _ := service.GetSchedulePrintList(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  4668. for _, item := range list {
  4669. order, _ := service.GetLastOrder(item.UserOrgId, item.PatientId, item.ScheduleDate)
  4670. item.DialysisOrderTwenty = order
  4671. }
  4672. listOne, _ := service.GetSchedulePrintListOne(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  4673. numberList, _ := service.GetAllBedNumberSix(adminUserInfo.CurrentOrgId)
  4674. c.ServeSuccessJSON(map[string]interface{}{
  4675. "list": list,
  4676. "total": total,
  4677. "numberList": numberList,
  4678. "listOne": listOne,
  4679. })
  4680. }
  4681. func (this *DialysisApiController) GetSolutionListByOrgId() {
  4682. orgId := this.GetAdminUserInfo().CurrentOrgId
  4683. list, _ := service.GetSolutionListByOrgId(orgId)
  4684. for _, item := range list {
  4685. //获取该模式最新的1条数据
  4686. solution, _ := service.GetNewPatientSolutionByModeId(item.PatientId, item.ModeId, orgId)
  4687. //更新状态值
  4688. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, orgId, item.PatientId)
  4689. }
  4690. this.ServeSuccessJSON(map[string]interface{}{
  4691. "list": list,
  4692. })
  4693. }
  4694. func (this *DialysisApiController) ExcutionDoctorAdvice() {
  4695. orgId := this.GetAdminUserInfo().CurrentOrgId
  4696. is_open, _ := this.GetInt64("is_open")
  4697. idsStr := this.GetString("str")
  4698. recordIDStrs := strings.Split(idsStr, ",")
  4699. start_time := this.GetString("advice_date")
  4700. exec_time, _ := this.GetInt64("exec_time")
  4701. timeLayout := "2006-01-02"
  4702. loc, _ := time.LoadLocation("Local")
  4703. var startTime int64
  4704. if len(start_time) > 0 {
  4705. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4706. if err != nil {
  4707. //fmt.Println(err)
  4708. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4709. return
  4710. }
  4711. startTime = theTime.Unix()
  4712. }
  4713. config, _ := service.GetDrugOpenConfigOne(orgId)
  4714. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  4715. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  4716. //his医嘱
  4717. if is_open == 1 {
  4718. groupList, _ := service.GetHisExcutionDoctorAdviceListGroupList(recordIDStrs, startTime, orgId)
  4719. //查找未执行医嘱
  4720. list, _ := service.GetHisExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  4721. for _, item := range list {
  4722. if item.Checker == this.GetAdminUserInfo().AdminUser.Id {
  4723. this.ServeSuccessJSON(map[string]interface{}{
  4724. "msg": "3",
  4725. })
  4726. return
  4727. }
  4728. }
  4729. for _, item := range groupList {
  4730. for _, it := range list {
  4731. if item.DrugId == it.DrugId {
  4732. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  4733. }
  4734. }
  4735. }
  4736. for _, item := range groupList {
  4737. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4738. var sum_out_count int64
  4739. for _, it := range item.ChildDoctorAdvice {
  4740. var prescribing_number int64
  4741. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  4742. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  4743. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4744. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  4745. }
  4746. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4747. prescribing_number = parseIntPrescribingNumber
  4748. }
  4749. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  4750. prescribing_number = parseIntPrescribingNumber
  4751. }
  4752. sum_out_count += prescribing_number
  4753. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  4754. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  4755. //库存不足
  4756. if sum_out_count > drugStockOut.FlushCount {
  4757. this.ServeSuccessJSON(map[string]interface{}{
  4758. "msg": "2",
  4759. "drug": medical,
  4760. })
  4761. return
  4762. }
  4763. }
  4764. }
  4765. creater := this.GetAdminUserInfo().AdminUser.Id
  4766. //执行出库逻辑
  4767. for _, item := range list {
  4768. hisadvice := &models.HisDoctorAdviceInfo{
  4769. ID: item.ID,
  4770. UserOrgId: item.UserOrgId,
  4771. PatientId: item.PatientId,
  4772. AdviceType: item.AdviceType,
  4773. AdviceDate: item.AdviceDate,
  4774. StartTime: item.StartTime,
  4775. AdviceName: item.AdviceName,
  4776. AdviceDesc: item.AdviceDesc,
  4777. ReminderDate: item.ReminderDate,
  4778. SingleDose: item.SingleDose,
  4779. SingleDoseUnit: item.SingleDoseUnit,
  4780. DrugSpec: item.DrugSpec,
  4781. DrugSpecUnit: item.DrugSpecUnit,
  4782. PrescribingNumber: item.PrescribingNumber,
  4783. PrescribingNumberUnit: item.PrescribingNumberUnit,
  4784. DeliveryWay: item.DeliveryWay,
  4785. ExecutionFrequency: item.ExecutionFrequency,
  4786. AdviceDoctor: item.AdviceDoctor,
  4787. Status: 1,
  4788. CreatedTime: item.CreatedTime,
  4789. UpdatedTime: item.UpdatedTime,
  4790. AdviceAffirm: item.AdviceAffirm,
  4791. Remark: item.Remark,
  4792. StopTime: item.StopTime,
  4793. StopReason: item.StopReason,
  4794. StopDoctor: item.StopDoctor,
  4795. StopState: item.StopState,
  4796. ParentId: item.ParentId,
  4797. ExecutionTime: item.ExecutionTime,
  4798. ExecutionStaff: creater,
  4799. ExecutionState: item.ExecutionState,
  4800. Checker: item.Checker,
  4801. RecordDate: item.RecordDate,
  4802. DialysisOrderId: item.DialysisOrderId,
  4803. CheckTime: item.CheckTime,
  4804. CheckState: item.CheckState,
  4805. RemindType: item.RemindType,
  4806. FrequencyType: item.FrequencyType,
  4807. DayCount: item.DayCount,
  4808. WeekDay: item.WeekDay,
  4809. TemplateId: item.TemplateId,
  4810. Modifier: item.Modifier,
  4811. Way: item.Way,
  4812. DrugId: item.DrugId,
  4813. ExecutionFrequencyId: item.ExecutionFrequencyId,
  4814. }
  4815. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4816. if medical.IsUse == 2 {
  4817. if config.IsOpen != 1 {
  4818. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  4819. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  4820. }
  4821. //不通过药房发药
  4822. if pharmacyConfig.IsOpen != 1 {
  4823. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  4824. }
  4825. //查询默认仓库
  4826. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4827. //查询默认仓库剩余多少库存
  4828. var sum_count int64
  4829. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4830. for _, its := range stockInfo {
  4831. if its.MaxUnit == medical.MaxUnit {
  4832. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  4833. }
  4834. sum_count += its.StockMaxNumber + its.StockMinNumber
  4835. }
  4836. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4837. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  4838. }
  4839. }
  4840. info := models.HisDoctorAdviceInfo{
  4841. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  4842. ExecutionTime: exec_time,
  4843. ExecutionState: 1,
  4844. UpdatedTime: time.Now().Unix(),
  4845. }
  4846. //执行医嘱
  4847. service.UpdateHisDoctorAdviceExecution(info, item.ID)
  4848. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  4849. redis := service.RedisClient()
  4850. //清空key 值
  4851. redis.Set(key, "", time.Second)
  4852. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  4853. redis.Set(keyTwo, "", time.Second)
  4854. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4855. redis.Set(keyThree, "", time.Second)
  4856. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4857. theTime := toTime.Format("2006-01-02")
  4858. fmt.Println("theTIME", theTime)
  4859. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  4860. redis.Set(keyFour, "", time.Second)
  4861. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4862. redis.Set(keyFive, "", time.Second)
  4863. }
  4864. } else {
  4865. groupList, _ := service.GetExcutionDoctorAdviceGroupList(recordIDStrs, startTime, orgId)
  4866. //查找未执行医嘱
  4867. list, _ := service.GetExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  4868. for _, item := range groupList {
  4869. for _, it := range list {
  4870. if item.DrugId == it.DrugId {
  4871. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  4872. }
  4873. }
  4874. }
  4875. for _, item := range groupList {
  4876. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4877. var sum_out_count int64
  4878. for _, it := range item.ChildDoctorAdvice {
  4879. var prescribing_number int64
  4880. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  4881. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  4882. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4883. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  4884. }
  4885. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4886. prescribing_number = parseIntPrescribingNumber
  4887. }
  4888. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  4889. prescribing_number = parseIntPrescribingNumber
  4890. }
  4891. sum_out_count += prescribing_number
  4892. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  4893. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  4894. //库存不足
  4895. if sum_out_count > drugStockOut.FlushCount {
  4896. this.ServeSuccessJSON(map[string]interface{}{
  4897. "msg": "2",
  4898. "drug": medical,
  4899. })
  4900. return
  4901. }
  4902. }
  4903. }
  4904. for _, item := range list {
  4905. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4906. dadvice := &models.DoctorAdvice{
  4907. ID: item.ID,
  4908. UserOrgId: item.UserOrgId,
  4909. PatientId: item.PatientId,
  4910. AdviceType: item.AdviceType,
  4911. AdviceDate: item.AdviceDate,
  4912. StartTime: item.StartTime,
  4913. AdviceName: item.AdviceName,
  4914. AdviceDesc: item.AdviceDesc,
  4915. ReminderDate: item.ReminderDate,
  4916. SingleDose: item.SingleDose,
  4917. SingleDoseUnit: item.SingleDoseUnit,
  4918. DrugSpec: item.DrugSpec,
  4919. DrugSpecUnit: item.DrugSpecUnit,
  4920. PrescribingNumber: item.PrescribingNumber,
  4921. PrescribingNumberUnit: item.PrescribingNumberUnit,
  4922. DeliveryWay: item.DeliveryWay,
  4923. ExecutionFrequency: item.ExecutionFrequency,
  4924. AdviceDoctor: item.AdviceDoctor,
  4925. Status: 1,
  4926. CreatedTime: item.CreatedTime,
  4927. UpdatedTime: item.UpdatedTime,
  4928. AdviceAffirm: item.AdviceAffirm,
  4929. Remark: item.Remark,
  4930. StopTime: item.StopTime,
  4931. StopReason: item.StopReason,
  4932. StopDoctor: item.StopDoctor,
  4933. StopState: item.StopState,
  4934. ParentId: item.ParentId,
  4935. ExecutionTime: item.ExecutionTime,
  4936. ExecutionStaff: item.ExecutionStaff,
  4937. ExecutionState: item.ExecutionState,
  4938. Checker: item.Checker,
  4939. RecordDate: item.ReminderDate,
  4940. DialysisOrderId: item.DialysisOrderId,
  4941. CheckTime: item.CheckTime,
  4942. CheckState: item.CheckState,
  4943. RemindType: item.RemindType,
  4944. FrequencyType: item.FrequencyType,
  4945. DayCount: item.DayCount,
  4946. WeekDay: item.WeekDay,
  4947. TemplateId: item.TemplateId,
  4948. Modifier: item.Modifier,
  4949. Way: item.Way,
  4950. DrugId: item.DrugId,
  4951. }
  4952. if medical.IsUse == 2 {
  4953. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  4954. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  4955. }
  4956. if pharmacyConfig.IsOpen != 1 {
  4957. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  4958. }
  4959. //更新字典里面的库存
  4960. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4961. var sum_count int64
  4962. for _, its := range stockInfo {
  4963. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4964. if its.MaxUnit == baseDrug.MaxUnit {
  4965. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4966. }
  4967. sum_count += its.StockMaxNumber + its.StockMinNumber
  4968. }
  4969. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4970. //剩余库存
  4971. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  4972. }
  4973. info := models.DoctorAdvice{
  4974. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  4975. ExecutionTime: exec_time,
  4976. ExecutionState: 1,
  4977. UpdatedTime: time.Now().Unix(),
  4978. }
  4979. //执行医嘱
  4980. service.UpdateDoctorAdviceExecution(info, item.ID)
  4981. }
  4982. }
  4983. this.ServeSuccessJSON(map[string]interface{}{
  4984. "msg": "1",
  4985. })
  4986. return
  4987. }
  4988. func (this *DialysisApiController) CheckNewDoctorAdvice() {
  4989. orgId := this.GetAdminUserInfo().CurrentOrgId
  4990. idsStr := this.GetString("str")
  4991. recordIDStrs := strings.Split(idsStr, ",")
  4992. start_time := this.GetString("advice_date")
  4993. timeLayout := "2006-01-02"
  4994. loc, _ := time.LoadLocation("Local")
  4995. var startTime int64
  4996. if len(start_time) > 0 {
  4997. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4998. if err != nil {
  4999. //fmt.Println(err)
  5000. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5001. return
  5002. }
  5003. startTime = theTime.Unix()
  5004. }
  5005. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  5006. if config.IsOpen == 1 {
  5007. creater := this.GetAdminUserInfo().AdminUser.Id
  5008. //查询未核对的医嘱
  5009. advicelist, _ := service.GetHisCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  5010. for _, item := range advicelist {
  5011. if item.ExecutionStaff == creater {
  5012. this.ServeSuccessJSON(map[string]interface{}{
  5013. "msg": "2",
  5014. "advice": item,
  5015. })
  5016. return
  5017. }
  5018. service.CheckHisDoctorAdvice(item.ID, creater)
  5019. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5020. redis := service.RedisClient()
  5021. //清空key 值
  5022. redis.Set(key, "", time.Second)
  5023. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5024. redis.Set(keyTwo, "", time.Second)
  5025. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5026. redis.Set(keyThree, "", time.Second)
  5027. theTime := time.Now()
  5028. recordDate := theTime.Format("2006-01-02")
  5029. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5030. redis.Set(keyFour, "", time.Second)
  5031. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5032. redis.Set(keyFive, "", time.Second)
  5033. }
  5034. } else {
  5035. //查询未核对的医嘱
  5036. advicelist, _ := service.GetCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  5037. creater := this.GetAdminUserInfo().AdminUser.Id
  5038. for _, item := range advicelist {
  5039. if item.ExecutionStaff == creater {
  5040. this.ServeSuccessJSON(map[string]interface{}{
  5041. "msg": "2",
  5042. "advice": item,
  5043. })
  5044. return
  5045. }
  5046. service.CheckDoctorAdvice(item.ID, creater)
  5047. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5048. redis := service.RedisClient()
  5049. //清空key 值
  5050. redis.Set(key, "", time.Second)
  5051. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5052. redis.Set(keyTwo, "", time.Second)
  5053. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5054. redis.Set(keyThree, "", time.Second)
  5055. theTime := time.Now()
  5056. recordDate := theTime.Format("2006-01-02")
  5057. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5058. redis.Set(keyFour, "", time.Second)
  5059. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5060. redis.Set(keyFive, "", time.Second)
  5061. }
  5062. }
  5063. this.ServeSuccessJSON(map[string]interface{}{
  5064. "msg": "1",
  5065. })
  5066. return
  5067. }
  5068. func (this *DialysisApiController) SettleNewDoctorAdvice() {
  5069. orgId := this.GetAdminUserInfo().CurrentOrgId
  5070. is_open, _ := this.GetInt64("is_open")
  5071. idsStr := this.GetString("str")
  5072. recordIDStrs := strings.Split(idsStr, ",")
  5073. start_time := this.GetString("advice_date")
  5074. timeLayout := "2006-01-02"
  5075. loc, _ := time.LoadLocation("Local")
  5076. var startTime int64
  5077. if len(start_time) > 0 {
  5078. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5079. if err != nil {
  5080. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5081. return
  5082. }
  5083. startTime = theTime.Unix()
  5084. }
  5085. if is_open == 1 {
  5086. service.SettleHisNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5087. } else {
  5088. service.SettleNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5089. }
  5090. this.ServeSuccessJSON(map[string]interface{}{
  5091. "msg": "1",
  5092. })
  5093. return
  5094. }
  5095. func (this *DialysisApiController) ExcutionDoctorAdviceById() {
  5096. advice_id, _ := this.GetInt64("advice_id")
  5097. start_time := this.GetString("advice_date")
  5098. orgId := this.GetAdminUserInfo().CurrentOrgId
  5099. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  5100. exec_time, _ := this.GetInt64("exec_time")
  5101. //his医嘱
  5102. if config.IsOpen == 1 {
  5103. //查询医嘱
  5104. advice, _ := service.GetHisDocById(advice_id, orgId)
  5105. if advice.Checker == this.GetAdminUserInfo().AdminUser.Id {
  5106. this.ServeSuccessJSON(map[string]interface{}{
  5107. "msg": "3",
  5108. })
  5109. return
  5110. }
  5111. medical, _ := service.GetBaseDrugMedical(orgId)
  5112. var prescribing_number int64
  5113. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5114. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5115. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5116. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5117. }
  5118. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5119. prescribing_number = parseIntPrescribingNumber
  5120. }
  5121. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5122. prescribing_number = parseIntPrescribingNumber
  5123. }
  5124. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5125. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5126. //库存不足
  5127. if prescribing_number > drugStockOut.FlushCount {
  5128. this.ServeSuccessJSON(map[string]interface{}{
  5129. "msg": "2",
  5130. "drug": medical,
  5131. })
  5132. return
  5133. }
  5134. info := models.HisDoctorAdviceInfo{
  5135. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5136. ExecutionTime: exec_time,
  5137. ExecutionState: 1,
  5138. UpdatedTime: time.Now().Unix(),
  5139. }
  5140. //执行医嘱
  5141. service.UpdateHisDoctorAdviceExecution(info, advice.ID)
  5142. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  5143. redis := service.RedisClient()
  5144. //清空key 值
  5145. redis.Set(key, "", time.Second)
  5146. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  5147. redis.Set(keyTwo, "", time.Second)
  5148. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5149. redis.Set(keyThree, "", time.Second)
  5150. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5151. theTime := toTime.Format("2006-01-02")
  5152. fmt.Println("theTIME", theTime)
  5153. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  5154. redis.Set(keyFour, "", time.Second)
  5155. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5156. redis.Set(keyFive, "", time.Second)
  5157. //出库
  5158. if prescribing_number <= drugStockOut.FlushCount {
  5159. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5160. //执行出库逻辑
  5161. hisadvice := &models.HisDoctorAdviceInfo{
  5162. ID: advice.ID,
  5163. UserOrgId: advice.UserOrgId,
  5164. PatientId: advice.PatientId,
  5165. AdviceType: advice.AdviceType,
  5166. AdviceDate: advice.AdviceDate,
  5167. StartTime: advice.StartTime,
  5168. AdviceName: advice.AdviceName,
  5169. AdviceDesc: advice.AdviceDesc,
  5170. ReminderDate: advice.ReminderDate,
  5171. SingleDose: advice.SingleDose,
  5172. SingleDoseUnit: advice.SingleDoseUnit,
  5173. DrugSpec: advice.DrugSpec,
  5174. DrugSpecUnit: advice.DrugSpecUnit,
  5175. PrescribingNumber: advice.PrescribingNumber,
  5176. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  5177. DeliveryWay: advice.DeliveryWay,
  5178. ExecutionFrequency: advice.ExecutionFrequency,
  5179. AdviceDoctor: advice.AdviceDoctor,
  5180. Status: 1,
  5181. CreatedTime: advice.CreatedTime,
  5182. UpdatedTime: advice.UpdatedTime,
  5183. AdviceAffirm: advice.AdviceAffirm,
  5184. Remark: advice.Remark,
  5185. StopTime: advice.StopTime,
  5186. StopReason: advice.StopReason,
  5187. StopDoctor: advice.StopDoctor,
  5188. StopState: advice.StopState,
  5189. ParentId: advice.ParentId,
  5190. ExecutionTime: advice.ExecutionTime,
  5191. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5192. ExecutionState: advice.ExecutionState,
  5193. Checker: advice.Checker,
  5194. RecordDate: advice.RecordDate,
  5195. DialysisOrderId: advice.DialysisOrderId,
  5196. CheckTime: advice.CheckTime,
  5197. CheckState: advice.CheckState,
  5198. RemindType: advice.RemindType,
  5199. FrequencyType: advice.FrequencyType,
  5200. DayCount: advice.DayCount,
  5201. WeekDay: advice.WeekDay,
  5202. TemplateId: advice.TemplateId,
  5203. Modifier: advice.Modifier,
  5204. Way: advice.Way,
  5205. DrugId: advice.DrugId,
  5206. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  5207. }
  5208. if medical.IsUse == 2 {
  5209. if config.IsOpen != 1 {
  5210. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5211. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5212. }
  5213. //不通过药房发药
  5214. if pharmacyConfig.IsOpen != 1 {
  5215. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5216. }
  5217. //查询默认仓库
  5218. storeHouseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  5219. //查询默认仓库剩余多少库存
  5220. var sum_count int64
  5221. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  5222. for _, its := range stockInfo {
  5223. if its.MaxUnit == medical.MaxUnit {
  5224. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5225. }
  5226. sum_count += its.StockMaxNumber + its.StockMinNumber
  5227. }
  5228. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  5229. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5230. }
  5231. }
  5232. }
  5233. this.ServeSuccessJSON(map[string]interface{}{
  5234. "msg": "1",
  5235. })
  5236. return
  5237. }
  5238. if config.IsOpen == 2 || config.IsOpen == 0 {
  5239. advice, _ := service.GetBloodDocById(advice_id, orgId)
  5240. medical, _ := service.GetBaseDrugMedical(orgId)
  5241. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5242. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5243. var prescribing_number int64
  5244. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5245. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5246. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5247. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5248. }
  5249. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5250. prescribing_number = parseIntPrescribingNumber
  5251. }
  5252. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5253. prescribing_number = parseIntPrescribingNumber
  5254. }
  5255. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5256. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5257. //库存不足
  5258. if prescribing_number > drugStockOut.FlushCount {
  5259. this.ServeSuccessJSON(map[string]interface{}{
  5260. "msg": "2",
  5261. "drug": medical,
  5262. })
  5263. return
  5264. }
  5265. info := models.DoctorAdvice{
  5266. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5267. ExecutionTime: exec_time,
  5268. ExecutionState: 1,
  5269. UpdatedTime: time.Now().Unix(),
  5270. }
  5271. //执行医嘱
  5272. service.UpdateDoctorAdviceExecution(info, advice.ID)
  5273. dadvice := &models.DoctorAdvice{
  5274. ID: advice.ID,
  5275. UserOrgId: advice.UserOrgId,
  5276. PatientId: advice.PatientId,
  5277. AdviceType: advice.AdviceType,
  5278. AdviceDate: advice.AdviceDate,
  5279. StartTime: advice.StartTime,
  5280. AdviceName: advice.AdviceName,
  5281. AdviceDesc: advice.AdviceDesc,
  5282. ReminderDate: advice.ReminderDate,
  5283. SingleDose: advice.SingleDose,
  5284. SingleDoseUnit: advice.SingleDoseUnit,
  5285. DrugSpec: advice.DrugSpec,
  5286. DrugSpecUnit: advice.DrugSpecUnit,
  5287. PrescribingNumber: advice.PrescribingNumber,
  5288. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  5289. DeliveryWay: advice.DeliveryWay,
  5290. ExecutionFrequency: advice.ExecutionFrequency,
  5291. AdviceDoctor: advice.AdviceDoctor,
  5292. Status: 1,
  5293. CreatedTime: advice.CreatedTime,
  5294. UpdatedTime: advice.UpdatedTime,
  5295. AdviceAffirm: advice.AdviceAffirm,
  5296. Remark: advice.Remark,
  5297. StopTime: advice.StopTime,
  5298. StopReason: advice.StopReason,
  5299. StopDoctor: advice.StopDoctor,
  5300. StopState: advice.StopState,
  5301. ParentId: advice.ParentId,
  5302. ExecutionTime: advice.ExecutionTime,
  5303. ExecutionStaff: advice.ExecutionStaff,
  5304. ExecutionState: advice.ExecutionState,
  5305. Checker: advice.Checker,
  5306. RecordDate: advice.ReminderDate,
  5307. DialysisOrderId: advice.DialysisOrderId,
  5308. CheckTime: advice.CheckTime,
  5309. CheckState: advice.CheckState,
  5310. RemindType: advice.RemindType,
  5311. FrequencyType: advice.FrequencyType,
  5312. DayCount: advice.DayCount,
  5313. WeekDay: advice.WeekDay,
  5314. TemplateId: advice.TemplateId,
  5315. Modifier: advice.Modifier,
  5316. Way: advice.Way,
  5317. DrugId: advice.DrugId,
  5318. }
  5319. if medical.IsUse == 2 {
  5320. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5321. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  5322. }
  5323. if pharmacyConfig.IsOpen != 1 {
  5324. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  5325. }
  5326. //更新字典里面的库存
  5327. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  5328. var sum_count int64
  5329. for _, its := range stockInfo {
  5330. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5331. if its.MaxUnit == baseDrug.MaxUnit {
  5332. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5333. }
  5334. sum_count += its.StockMaxNumber + its.StockMinNumber
  5335. }
  5336. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  5337. //剩余库存
  5338. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5339. }
  5340. }
  5341. this.ServeSuccessJSON(map[string]interface{}{
  5342. "msg": "1",
  5343. })
  5344. return
  5345. }
  5346. func (this *DialysisApiController) GetDialysisAdviceToday() {
  5347. orgId := this.GetAdminUserInfo().CurrentOrgId
  5348. schedule_type, _ := this.GetInt64("schedule_type")
  5349. //partion_type, _ := this.GetInt64("partion_type")
  5350. partion_type := this.GetString("partion_type")
  5351. var ids []string
  5352. ids = strings.Split(partion_type, ",")
  5353. start_time := this.GetString("selected_date")
  5354. timeLayout := "2006-01-02"
  5355. loc, _ := time.LoadLocation("Local")
  5356. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5357. list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
  5358. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  5359. _, config := service.FindXTHisRecordByOrgId(orgId)
  5360. appId := this.GetAdminUserInfo().CurrentAppId
  5361. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  5362. if err == nil {
  5363. this.ServeSuccessJSON(map[string]interface{}{
  5364. "list": list,
  5365. "drug": drug,
  5366. "config": config,
  5367. "doctorList": doctorList,
  5368. })
  5369. return
  5370. } else {
  5371. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5372. return
  5373. }
  5374. }
  5375. func (this *DialysisApiController) GetMobileScheduleList() {
  5376. orgId := this.GetAdminUserInfo().CurrentOrgId
  5377. schedule, _ := service.GetMobileScheduleList(orgId)
  5378. if len(schedule) > 0 {
  5379. for _, its := range schedule {
  5380. //prescription, _ := service.GetPrescriptionList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5381. //its.DialysisPrescription = prescription
  5382. //monitor, _ := service.GetLastMonitorRecordList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5383. //its.MonitoringRecord = monitor
  5384. //after, _ := service.GetLastAfter(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5385. //its.XtAssessmentAfterDislysis = after
  5386. order, _ := service.GetLastOrder(its.UserOrgId, its.PatientId, its.ScheduleDate)
  5387. service.UpdateDoctorSix(order.StartTime, order.PatientId, order.DialysisDate, order.UserOrgId)
  5388. }
  5389. }
  5390. this.ServeSuccessJSON(map[string]interface{}{
  5391. "schedule": schedule,
  5392. })
  5393. return
  5394. }
  5395. func (this *DialysisApiController) SaveDialysisInformationSetting() {
  5396. week_day, _ := this.GetInt64("week_day")
  5397. orgId := this.GetAdminUserInfo().CurrentOrgId
  5398. informaitonSetting := models.XtDialysisInformaitonSetting{
  5399. WeekDay: week_day,
  5400. UserOrgId: orgId,
  5401. Status: 1,
  5402. Ctime: time.Now().Unix(),
  5403. Mtime: 0,
  5404. }
  5405. information, _ := service.GetInformationSettingByOrgId(orgId)
  5406. if information.ID == 0 {
  5407. service.CreateInformationSetting(informaitonSetting)
  5408. }
  5409. if information.ID > 0 {
  5410. service.UpdateInformationSettingById(orgId, week_day)
  5411. }
  5412. this.ServeSuccessJSON(map[string]interface{}{
  5413. "informaitonSetting": informaitonSetting,
  5414. })
  5415. return
  5416. }
  5417. func (this *DialysisApiController) GetDialysisInformationSetting() {
  5418. orgId := this.GetAdminUserInfo().CurrentOrgId
  5419. informationSetting, _ := service.GetDialysisInformationSetting(orgId)
  5420. this.ServeSuccessJSON(map[string]interface{}{
  5421. "informaitonSetting": informationSetting,
  5422. })
  5423. return
  5424. }