dialysis_api_controller.go 452KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "math"
  7. "net/http"
  8. "net/url"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "XT_New/enums"
  14. "XT_New/models"
  15. "XT_New/service"
  16. "XT_New/utils"
  17. "github.com/astaxie/beego"
  18. "github.com/jinzhu/gorm"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var projectsOne []*models.HisPrescriptionProject
  342. var stockType []*models.GoodsTypeOne
  343. var prepare []*models.XtDialysisBeforePrepare
  344. var lastAssessment models.XtPatientVascularAccess
  345. var lastDryWeightDislysis *models.SgjPatientDryweight
  346. var gobalConfig models.GobalConfig
  347. var operators []*models.SgjUserAdminRoles
  348. // 先走redis,没有走数据库
  349. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  350. go func() {
  351. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  352. ch <- struct{}{}
  353. }()
  354. go func() {
  355. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  356. ch <- struct{}{}
  357. }()
  358. go func() {
  359. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  360. ch <- struct{}{}
  361. }()
  362. go func() {
  363. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  364. ch <- struct{}{}
  365. }()
  366. go func() {
  367. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  368. ch <- struct{}{}
  369. }()
  370. go func() {
  371. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  372. ch <- struct{}{}
  373. }()
  374. go func() {
  375. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  376. ch <- struct{}{}
  377. }()
  378. go func() {
  379. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  380. ch <- struct{}{}
  381. }()
  382. go func() {
  383. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  384. ch <- struct{}{}
  385. }()
  386. go func() {
  387. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  388. ch <- struct{}{}
  389. }()
  390. go func() {
  391. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  392. ch <- struct{}{}
  393. }()
  394. go func() {
  395. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  396. ch <- struct{}{}
  397. }()
  398. go func() {
  399. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  400. ch <- struct{}{}
  401. }()
  402. go func() {
  403. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  404. ch <- struct{}{}
  405. }()
  406. go func() {
  407. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  408. ch <- struct{}{}
  409. }()
  410. go func() {
  411. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  412. ch <- struct{}{}
  413. }()
  414. go func() {
  415. // 先走redis,没有走数据库
  416. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  417. ch <- struct{}{}
  418. }()
  419. go func() {
  420. // 先走redis,没有走数据库
  421. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  422. ch <- struct{}{}
  423. }()
  424. go func() {
  425. // // 先走redis,没有走数据库
  426. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  427. ch <- struct{}{}
  428. }()
  429. go func() {
  430. // 先走redis,没有走数据库
  431. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  432. ch <- struct{}{}
  433. }()
  434. go func() {
  435. // //获取最后一次血管通路
  436. // 先走redis,没有走数据库
  437. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  438. ch <- struct{}{}
  439. }()
  440. go func() {
  441. // 先走redis,没有走数据库
  442. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  443. ch <- struct{}{}
  444. }()
  445. go func() {
  446. // 先走redis,没有走数据库
  447. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  448. ch <- struct{}{}
  449. }()
  450. go func() {
  451. // 先走redis,没有走数据库
  452. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  453. ch <- struct{}{}
  454. }()
  455. for range ch {
  456. // 每次从ch中接收数据,表明一个活动的协程结束
  457. count--
  458. // 当所有活动的协程都结束时,关闭管道
  459. if count == 0 {
  460. close(ch)
  461. }
  462. }
  463. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  464. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  465. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  466. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  468. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  469. var team_projects []*models.HisPrescriptionProject
  470. //var index int64 = 0
  471. for _, item := range temp_team_projects {
  472. //组套里面非检验项目的
  473. if item.HisProject.CostClassify != 3 && item.HisProject.CostClassify != 104 {
  474. projects = append(projects, item)
  475. }
  476. //组套里面检验项目的
  477. if item.HisProject.CostClassify == 3 || item.HisProject.CostClassify == 104 {
  478. team_projects = append(team_projects, item)
  479. }
  480. }
  481. //针对茂名舒和
  482. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  483. if len(projects) > 0 {
  484. for _, item := range projects {
  485. if item.Type == 2 {
  486. if item.HisProject.IsShow == 1 {
  487. projectsOne = append(projectsOne, item)
  488. }
  489. }
  490. if item.Type == 3 {
  491. if item.GoodInfo.IsShow == 1 {
  492. projectsOne = append(projectsOne, item)
  493. }
  494. }
  495. }
  496. }
  497. } else {
  498. for _, item := range projects {
  499. projectsOne = append(projectsOne, item)
  500. }
  501. }
  502. team_projects = RemoveRepeatedCheckRecod(team_projects)
  503. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  504. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  505. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  506. var his_advices []*models.HisDoctorAdviceInfo
  507. var his_advices_one []*models.HisDoctorAdviceInfo
  508. if is_open_config.IsOpen == 1 {
  509. // 先走redis,没有走数据库
  510. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  511. }
  512. //针对茂名舒和
  513. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  514. if len(his_advices) > 0 {
  515. for _, item := range his_advices {
  516. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  517. if drug.IsShow == 1 {
  518. his_advices_one = append(his_advices_one, item)
  519. }
  520. }
  521. }
  522. } else {
  523. if len(his_advices) > 0 {
  524. for _, item := range his_advices {
  525. his_advices_one = append(his_advices_one, item)
  526. }
  527. }
  528. }
  529. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  530. if is_advice_open.IsAdviceOpen == 1 {
  531. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  532. }
  533. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  534. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  535. var remind_lists []models.XtCheckRemind
  536. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  537. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  538. }
  539. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  540. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  541. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  542. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  543. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  544. returnData := map[string]interface{}{
  545. "patient": patient,
  546. "schedual": schedual,
  547. "prescription": dialysisPrescribe,
  548. "solution": dialysisSolution,
  549. "last_prescription": lastDialysisPrescribe,
  550. "receiver_treatment_access": receiverTreatmentAccess,
  551. "predialysis_evaluation": predialysisEvaluation,
  552. "doctor_advices": doctorAdvices,
  553. "double_check": doubleCheck,
  554. "assessment_after_dislysis": assessmentAfterDislysis,
  555. "treatment_summary": treatmentSummary,
  556. "monitor_records": monitorRecords,
  557. "dialysis_order": dialysisOrder,
  558. "operators": operators,
  559. "last_predialysis_evaluation": lastPredialysisEvaluation,
  560. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  561. "last_monitor_record": lastMonitorRecord,
  562. "config": gobalConfig,
  563. "dry_weight": lastDryWeightDislysis,
  564. "system_prescription": systemDialysisPrescribe,
  565. "his_advices": his_advices_one,
  566. "is_open_config": is_open_config,
  567. "stockType": stockType,
  568. "prepare": prepare,
  569. "lastAssessment": lastAssessment,
  570. "prescribeOne": prescribeOne,
  571. "is_project_open_config": is_project_open_config,
  572. "project": projectsOne,
  573. "team_projects": team_projects,
  574. "is_advice_open": is_advice_open,
  575. "prescription_open": prescriptionConfig.IsOpen,
  576. "lastOrder": lastOrder,
  577. "remind_lists": remind_lists,
  578. "lastDialysisPrescription": lastDialysisPrescription,
  579. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  580. "dryWeightList": dryWeightList,
  581. "firstMonitor": firstMonitor,
  582. "lastMonitor": lastMonitor,
  583. }
  584. this.ServeSuccessJSON(returnData)
  585. }
  586. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  587. adminInfo := c.GetMobileAdminUserInfo()
  588. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  589. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  590. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  591. returnData := map[string]interface{}{
  592. "admin_users": adminUsers,
  593. "devices": devices,
  594. "device_numbers": device_numbers,
  595. }
  596. c.ServeSuccessJSON(returnData)
  597. }
  598. func (c *DialysisAPIController) PostAtreatmentInfo() {
  599. id, _ := c.GetInt64("patient", 0)
  600. recordDateStr := c.GetString("record_date")
  601. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  602. summaryContent := c.GetString("summaryContent")
  603. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  604. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  605. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  606. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  607. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  608. nursingRecord := c.GetString("nursing_record")
  609. fmt.Println("护理记录", nursingRecord)
  610. specialRecord := c.GetString("special_record")
  611. fmt.Println("特殊记录", specialRecord)
  612. adminUserInfo := c.GetMobileAdminUserInfo()
  613. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  614. checkStaffId = adminUserInfo.AdminUser.Id
  615. deboardNurseId = adminUserInfo.AdminUser.Id
  616. treatDoctor = adminUserInfo.AdminUser.Id
  617. if id <= 0 {
  618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  619. return
  620. }
  621. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  622. if patient.ID == 0 {
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  624. return
  625. }
  626. if len(recordDateStr) == 0 {
  627. recordDateStr = time.Now().Format("2006-01-02")
  628. }
  629. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  630. if parseDateErr != nil {
  631. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. return
  634. }
  635. summary := models.TreatmentSummary{
  636. UserOrgId: adminUserInfo.Org.Id,
  637. PatientId: id,
  638. AssessmentDate: recordDate.Unix(),
  639. Mission: propagandaAndEducationContent,
  640. DialysisSummary: summaryContent,
  641. SjNurse: changeMedicalNurseId,
  642. ZlNurse: treatNurseId,
  643. HdNurse: checkStaffId,
  644. XjNurse: deboardNurseId,
  645. ZlDoctor: treatDoctor,
  646. CreatedTime: time.Now().Unix(),
  647. Status: 1,
  648. NursingRecord: nursingRecord,
  649. SpecialRecord: specialRecord,
  650. }
  651. // 查询信息规挡的设置天数
  652. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  653. if infor.ID > 0 && infor.WeekDay > 0 {
  654. var cha_time int64
  655. timeNowStr := time.Now().Format("2006-01-02")
  656. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  657. //今日的日期减去设置的日期
  658. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  659. if cha_time >= recordDate.Unix() {
  660. //查询审核是否允许
  661. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  662. //申请状态不允许的情况 拒绝修改
  663. if infor.ApplicationStatus != 1 {
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  665. return
  666. }
  667. }
  668. }
  669. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  670. if treatmentSummary.ID == 0 { //新增
  671. summary.Creater = adminUserInfo.AdminUser.Id
  672. service.AddSigleSummaryRecord(&summary)
  673. finish := models.XtDialysisFinish{
  674. IsFinish: 1,
  675. UserOrgId: adminUserInfo.Org.Id,
  676. Status: 1,
  677. Ctime: time.Now().Unix(),
  678. Mtime: 0,
  679. Module: 10,
  680. RecordDate: recordDate.Unix(),
  681. Sourse: 1,
  682. PatientId: id,
  683. }
  684. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  685. if dialysisFinish.ID == 0 {
  686. service.CreateDialysisFinish(finish)
  687. }
  688. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  689. redis := service.RedisClient()
  690. //清空key 值
  691. redis.Set(key, "", time.Second)
  692. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  693. redis.Set(keyOne, "", time.Second)
  694. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  695. redis.Set(keyThree, "", time.Second)
  696. defer redis.Close()
  697. c.ServeSuccessJSON(map[string]interface{}{
  698. "summary": summary,
  699. })
  700. } else { //修改
  701. summary.Creater = treatmentSummary.Creater
  702. summary.CreatedTime = treatmentSummary.CreatedTime
  703. summary.Modifier = adminUserInfo.AdminUser.Id
  704. summary.ID = treatmentSummary.ID
  705. service.UpdateSummeRecord(&summary)
  706. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  707. redis := service.RedisClient()
  708. //清空key 值
  709. redis.Set(key, "", time.Second)
  710. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  711. redis.Set(keyOne, "", time.Second)
  712. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  713. redis.Set(keyThree, "", time.Second)
  714. defer redis.Close()
  715. c.ServeSuccessJSON(map[string]interface{}{
  716. "summary": summary,
  717. })
  718. }
  719. }
  720. func (c *DialysisAPIController) PostDoubleCheck() {
  721. id, _ := c.GetInt64("patient", 0)
  722. recordDateStr := c.GetString("record_date")
  723. checkTimeStr := c.GetString("check_time")
  724. firstCheckTimeStr := c.GetString("first_check_time")
  725. creater, _ := c.GetInt64("creater", 0)
  726. modifier, _ := c.GetInt64("modifier", 0)
  727. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  728. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  729. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  730. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  731. dialysis_item_desc := c.GetString("dialysis_item_desc")
  732. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  733. vascular_access_desc := c.GetString("vascular_access_desc")
  734. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  735. collator, _ := c.GetInt64("collator", 0)
  736. employee_number := c.GetString("employee_number")
  737. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  738. needle_batch_number := c.GetString("needle_batch_number")
  739. if id <= 0 {
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. adminUserInfo := c.GetMobileAdminUserInfo()
  744. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  745. if patient.ID == 0 {
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  747. return
  748. }
  749. if len(recordDateStr) == 0 {
  750. recordDateStr = time.Now().Format("2006-01-02")
  751. }
  752. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  753. if parseDateErr != nil {
  754. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  756. return
  757. }
  758. var checkDate int64
  759. if len(checkTimeStr) == 0 {
  760. checkDate = 0
  761. } else {
  762. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  763. checkDate = checkDateUnix.Unix()
  764. }
  765. var firstCheckDate int64
  766. if len(firstCheckTimeStr) == 0 {
  767. firstCheckDate = 0
  768. } else {
  769. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  770. firstCheckDate = firstCheckDateUnix.Unix()
  771. }
  772. if adminUserInfo.Org.Id == 10644 {
  773. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  774. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  775. if check.ID == 0 {
  776. if employee_number != list.JobNumber {
  777. c.ServeSuccessJSON(map[string]interface{}{
  778. "doubleCheck": check,
  779. "msg": "2",
  780. })
  781. return
  782. }
  783. }
  784. if check.ID > 0 {
  785. if employee_number != list.JobNumber {
  786. c.ServeSuccessJSON(map[string]interface{}{
  787. "doubleCheck": check,
  788. "msg": "2",
  789. })
  790. return
  791. }
  792. }
  793. }
  794. doubleCheck := models.DoubleCheck{
  795. UserOrgId: adminUserInfo.Org.Id,
  796. PatientId: id,
  797. DialysisItemCheck: dialysis_item_check,
  798. DialysisParameterCheck: dialysis_parameter_check,
  799. VascularAccessVerification: vascular_access_verification,
  800. PipelineConnectionCheck: pipeline_connection_check,
  801. DialysisItemDesc: dialysis_item_desc,
  802. DialysisParameterDesc: dialysis_parameter_desc,
  803. VascularAccessDesc: vascular_access_desc,
  804. PipelineConnectionDesc: pipeline_connection_desc,
  805. Collator: collator,
  806. Status: 1,
  807. CreatedTime: time.Now().Unix(),
  808. CheckDate: recordDate.Unix(),
  809. UpdatedTime: time.Now().Unix(),
  810. EmployeeNumber: employee_number,
  811. DialyzerBatchNumber: dialyzer_batch_number,
  812. NeedleBatchNumber: needle_batch_number,
  813. }
  814. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  815. if check.ID == 0 { //新增
  816. doubleCheck.FirstCheckTime = firstCheckDate
  817. doubleCheck.CheckTime = checkDate
  818. doubleCheck.Creater = creater
  819. doubleCheck.Modifier = modifier
  820. if adminUserInfo.Org.Id == 10340 {
  821. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  822. doubleCheck.Creater = order.StartNurse
  823. }
  824. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  825. //查询未核对的医嘱
  826. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  827. for _, advice := range doctorList {
  828. if advice.ExecutionStaff == modifier {
  829. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  830. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  831. return
  832. }
  833. }
  834. }
  835. // 查询信息规挡的设置天数
  836. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  837. if infor.ID > 0 && infor.WeekDay > 0 {
  838. var cha_time int64
  839. timeNowStr := time.Now().Format("2006-01-02")
  840. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  841. //今日的日期减去设置的日期
  842. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  843. if cha_time >= recordDate.Unix() {
  844. //查询审核是否允许
  845. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  846. //申请状态不允许的情况 拒绝修改
  847. if infor.ApplicationStatus != 1 {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  849. return
  850. }
  851. }
  852. }
  853. err := service.AddSigleDoubleCheck(&doubleCheck)
  854. finish := models.XtDialysisFinish{
  855. IsFinish: 1,
  856. UserOrgId: adminUserInfo.Org.Id,
  857. Status: 1,
  858. Ctime: time.Now().Unix(),
  859. Mtime: 0,
  860. Module: 5,
  861. RecordDate: recordDate.Unix(),
  862. Sourse: 1,
  863. PatientId: id,
  864. }
  865. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  866. if dialysisFinish.ID == 0 {
  867. service.CreateDialysisFinish(finish)
  868. }
  869. //针对长沙南雅
  870. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  871. //查询未核对的医嘱
  872. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  873. if len(doctorList) > 0 && modifier > 0 {
  874. for _, advice := range doctorList {
  875. service.UpdateDoctorAdviceList(advice.ID, modifier)
  876. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  877. redis := service.RedisClient()
  878. //清空key 值
  879. redis.Set(key, "", time.Second)
  880. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  881. redis.Set(keyTwo, "", time.Second)
  882. theTime := time.Now()
  883. recordDate := theTime.Format("2006-01-02")
  884. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  885. redis.Set(keyFour, "", time.Second)
  886. defer redis.Close()
  887. }
  888. }
  889. }
  890. //针对溪康
  891. if adminUserInfo.Org.Id == 10721 {
  892. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  893. if len(adviceInfoList) > 0 {
  894. for _, item := range adviceInfoList {
  895. service.UpdateHisAdviceList(item.ID, creater)
  896. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  897. redis := service.RedisClient()
  898. //清空key 值
  899. redis.Set(key, "", time.Second)
  900. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  901. redis.Set(keyTwo, "", time.Second)
  902. theTime := time.Now()
  903. recordDate := theTime.Format("2006-01-02")
  904. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  905. redis.Set(keyFour, "", time.Second)
  906. defer redis.Close()
  907. }
  908. }
  909. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  910. if len(adviceList) > 0 {
  911. for _, item := range adviceList {
  912. service.UpdateAdviceList(item.ID, creater)
  913. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  914. redis := service.RedisClient()
  915. //清空key 值
  916. redis.Set(key, "", time.Second)
  917. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  918. redis.Set(keyTwo, "", time.Second)
  919. theTime := time.Now()
  920. recordDate := theTime.Format("2006-01-02")
  921. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  922. redis.Set(keyFour, "", time.Second)
  923. defer redis.Close()
  924. }
  925. }
  926. }
  927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  928. redis := service.RedisClient()
  929. //清空key 值
  930. redis.Set(key, "", time.Second)
  931. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  932. redis.Set(keyOne, "", time.Second)
  933. defer redis.Close()
  934. if err == nil {
  935. c.ServeSuccessJSON(map[string]interface{}{
  936. "doubleCheck": &doubleCheck,
  937. })
  938. }
  939. } else { //修改
  940. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  941. if infor.ID > 0 {
  942. var cha_time int64
  943. timeNowStr := time.Now().Format("2006-01-02")
  944. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  945. //今日的日期减去设置的日期
  946. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  947. if cha_time >= recordDate.Unix() {
  948. //查询审核是否允许
  949. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  950. //申请状态不允许的情况 拒绝修改
  951. if infor.ApplicationStatus != 1 {
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  953. return
  954. }
  955. }
  956. }
  957. doubleCheck.FirstCheckTime = firstCheckDate
  958. doubleCheck.CheckTime = checkDate
  959. doubleCheck.Creater = creater
  960. doubleCheck.Modifier = modifier
  961. doubleCheck.CreatedTime = check.CreatedTime
  962. doubleCheck.ID = check.ID
  963. doubleCheck.EmployeeNumber = employee_number
  964. doubleCheck.NeedleBatchNumber = needle_batch_number
  965. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  966. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  967. //查询未核对的医嘱
  968. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  969. for _, advice := range doctorList {
  970. if advice.ExecutionStaff == modifier {
  971. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  972. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  973. return
  974. }
  975. }
  976. }
  977. //针对溪康
  978. if adminUserInfo.Org.Id == 10721 {
  979. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  980. if len(adviceInfoList) > 0 {
  981. for _, item := range adviceInfoList {
  982. service.UpdateHisAdviceList(item.ID, creater)
  983. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  984. redis := service.RedisClient()
  985. //清空key 值
  986. redis.Set(key, "", time.Second)
  987. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  988. redis.Set(keyTwo, "", time.Second)
  989. theTime := time.Now()
  990. recordDate := theTime.Format("2006-01-02")
  991. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  992. redis.Set(keyFour, "", time.Second)
  993. defer redis.Close()
  994. }
  995. }
  996. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  997. if len(adviceList) > 0 {
  998. for _, item := range adviceList {
  999. service.UpdateAdviceList(item.ID, creater)
  1000. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1001. redis := service.RedisClient()
  1002. //清空key 值
  1003. redis.Set(key, "", time.Second)
  1004. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1005. redis.Set(keyTwo, "", time.Second)
  1006. theTime := time.Now()
  1007. recordDate := theTime.Format("2006-01-02")
  1008. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1009. redis.Set(keyFour, "", time.Second)
  1010. defer redis.Close()
  1011. }
  1012. }
  1013. }
  1014. err := service.UpdateDoubleCheck(&doubleCheck)
  1015. //针对长沙南雅
  1016. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  1017. //查询未核对的医嘱
  1018. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1019. if len(doctorList) > 0 && modifier > 0 {
  1020. for _, advice := range doctorList {
  1021. service.UpdateDoctorAdviceList(advice.ID, modifier)
  1022. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1023. redis := service.RedisClient()
  1024. //清空key 值
  1025. redis.Set(key, "", time.Second)
  1026. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1027. redis.Set(keyTwo, "", time.Second)
  1028. theTime := time.Now()
  1029. recordDate := theTime.Format("2006-01-02")
  1030. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1031. redis.Set(keyFour, "", time.Second)
  1032. defer redis.Close()
  1033. }
  1034. }
  1035. }
  1036. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1037. redis := service.RedisClient()
  1038. //清空key 值
  1039. redis.Set(key, "", time.Second)
  1040. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1041. redis.Set(keyOne, "", time.Second)
  1042. defer redis.Close()
  1043. if err == nil {
  1044. c.ServeSuccessJSON(map[string]interface{}{
  1045. "doubleCheck": &doubleCheck,
  1046. "msg": "1",
  1047. })
  1048. }
  1049. }
  1050. }
  1051. func (c *DialysisAPIController) PostAcceptsAssessment() {
  1052. id, _ := c.GetInt64("patient", 0)
  1053. recordDateStr := c.GetString("record_date")
  1054. way, _ := c.GetInt64("way", 0)
  1055. consciousness, _ := c.GetInt64("consciousness", 0)
  1056. appetite, _ := c.GetInt64("appetite", 0)
  1057. condition, _ := c.GetInt64("condition", 0)
  1058. posture, _ := c.GetInt64("posture")
  1059. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1060. danger_level, _ := c.GetInt64("danger_level", 0)
  1061. intake, _ := c.GetInt64("intake", 0)
  1062. nutrition, _ := c.GetInt64("nutrition", 0)
  1063. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1064. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1065. score := c.GetString("score")
  1066. sick_condition_other := c.GetString("sick_condition_other")
  1067. //precaution, _ := c.GetInt64("precaution", 0)
  1068. precaution := c.GetString("precaution")
  1069. precaution_other := c.GetString("precaution_other")
  1070. psychological_other := c.GetString("psychological_other")
  1071. admission_number := c.GetString("admission_number")
  1072. tumble, _ := c.GetInt64("tumble")
  1073. diacrisis := c.GetString("diacrisis")
  1074. his_department := c.GetString("his_department")
  1075. his_bed := c.GetString("his_bed")
  1076. if id <= 0 {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1078. return
  1079. }
  1080. adminUserInfo := c.GetMobileAdminUserInfo()
  1081. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1082. if patient.ID == 0 {
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1084. return
  1085. }
  1086. //now := time.Now()
  1087. //year, month, day := now.Date()
  1088. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1089. //todayTimeStamp := today_time.Unix()
  1090. if len(recordDateStr) == 0 {
  1091. recordDateStr = time.Now().Format("2006-01-02")
  1092. }
  1093. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1094. if parseDateErr != nil {
  1095. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. // 查询信息规挡的设置天数
  1100. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1101. if infor.ID > 0 && infor.WeekDay > 0 {
  1102. var cha_time int64
  1103. timeNowStr := time.Now().Format("2006-01-02")
  1104. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1105. //今日的日期减去设置的日期
  1106. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1107. if cha_time >= recordDate.Unix() {
  1108. //查询审核是否允许
  1109. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1110. //申请状态不允许的情况 拒绝修改
  1111. if infor.ApplicationStatus != 1 {
  1112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1113. return
  1114. }
  1115. }
  1116. }
  1117. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1118. if adminUserInfo.Org.Id == 10340 {
  1119. if condition == 1 {
  1120. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1121. if admission_number == "" {
  1122. admission_number = lastAcceptTreatment.AdmissionNumber
  1123. }
  1124. }
  1125. }
  1126. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1127. UserOrgId: adminUserInfo.Org.Id,
  1128. PatientId: id,
  1129. RecordDate: recordDate.Unix(),
  1130. Way: way,
  1131. Consciousness: consciousness,
  1132. Appetite: appetite,
  1133. Condition: condition,
  1134. SickCondition: sick_condition,
  1135. DangerLevel: danger_level,
  1136. Intake: intake,
  1137. Nutrition: nutrition,
  1138. PsychologicalAssessment: psychological_assessment,
  1139. PsychologicalAssessmentOther: psychological_assessment_other,
  1140. SickConditionOther: sick_condition_other,
  1141. Posture: posture,
  1142. CreatedTime: time.Now().Unix(),
  1143. UpdateTime: time.Now().Unix(),
  1144. Status: 1,
  1145. Score: score,
  1146. Precaution: precaution,
  1147. PrecautionOther: precaution_other,
  1148. PsychologicalOther: psychological_other,
  1149. AdmissionNumber: admission_number,
  1150. Tumble: tumble,
  1151. Diacrisis: diacrisis,
  1152. HisBed: his_bed,
  1153. HisDepartment: his_department,
  1154. }
  1155. if receiveTreatment.ID == 0 { //新增
  1156. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1157. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1158. finish := models.XtDialysisFinish{
  1159. IsFinish: 1,
  1160. UserOrgId: adminUserInfo.Org.Id,
  1161. Status: 1,
  1162. Ctime: time.Now().Unix(),
  1163. Mtime: 0,
  1164. Module: 2,
  1165. RecordDate: recordDate.Unix(),
  1166. Sourse: 1,
  1167. PatientId: id,
  1168. }
  1169. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1170. if dialysisFinish.ID == 0 {
  1171. service.CreateDialysisFinish(finish)
  1172. }
  1173. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1174. redis := service.RedisClient()
  1175. defer redis.Close()
  1176. //清空key 值
  1177. redis.Set(key, "", time.Second)
  1178. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1179. redis.Set(keyOne, "", time.Second)
  1180. if err == nil {
  1181. c.ServeSuccessJSON(map[string]interface{}{
  1182. "receiveTreatmentAsses": receiveTreatmentAsses,
  1183. })
  1184. }
  1185. } else { //修改
  1186. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1187. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1188. // if getPermissionErr != nil {
  1189. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1190. // return
  1191. // } else if headNursePermission == nil {
  1192. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1193. // return
  1194. // }
  1195. //}
  1196. // 查询信息规挡的设置天数
  1197. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1198. if infor.ID > 0 && infor.WeekDay > 0 {
  1199. var cha_time int64
  1200. timeNowStr := time.Now().Format("2006-01-02")
  1201. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1202. //今日的日期减去设置的日期
  1203. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1204. if cha_time >= recordDate.Unix() {
  1205. //查询审核是否允许
  1206. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1207. //申请状态不允许的情况 拒绝修改
  1208. if infor.ApplicationStatus != 1 {
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1210. return
  1211. }
  1212. }
  1213. }
  1214. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1215. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1216. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1217. receiveTreatmentAsses.ID = receiveTreatment.ID
  1218. if adminUserInfo.Org.Id == 10340 {
  1219. if condition == 1 {
  1220. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1221. if receiveTreatmentAsses.AdmissionNumber == "" {
  1222. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1223. }
  1224. }
  1225. }
  1226. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1227. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1228. redis := service.RedisClient()
  1229. defer redis.Close()
  1230. //清空key 值
  1231. redis.Set(key, "", time.Second)
  1232. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1233. redis.Set(keyOne, "", time.Second)
  1234. if err == nil {
  1235. c.ServeSuccessJSON(map[string]interface{}{
  1236. "receiveTreatmentAsses": receiveTreatmentAsses,
  1237. })
  1238. }
  1239. }
  1240. }
  1241. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1242. id, _ := c.GetInt64("patient", 0)
  1243. recordDateStr := c.GetString("record_date")
  1244. weightAfter, _ := c.GetFloat("weight_after", 0)
  1245. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1246. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1247. fmt.Println("weight_loss", weightReduce)
  1248. temperature, _ := c.GetFloat("temperature", 0)
  1249. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1250. breathing_rate := c.GetString("breathing_rate")
  1251. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1252. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1253. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1254. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1255. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1256. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1257. cruor := c.GetString("cruor")
  1258. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1259. internalFistula := c.GetString("internal_fistula")
  1260. catheter := c.GetString("catheter")
  1261. complications := c.GetString("complication")
  1262. remark := c.GetString("remark")
  1263. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1264. dialysis_intakes := c.GetString("dialysis_intakes")
  1265. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1266. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1267. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1268. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1269. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1270. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1271. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1272. patientGose, _ := c.GetInt64("patient_gose", 0)
  1273. inpatientDepartment := c.GetString("inpatient_department")
  1274. observationContent := c.GetString("observation_content")
  1275. observationContentOther := c.GetString("observation_content_other")
  1276. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1277. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1278. in_advance_reason := c.GetString("in_advance_reason")
  1279. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1280. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1281. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1282. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1283. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1284. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1285. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1286. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1287. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1288. is_eat, _ := c.GetInt64("is_eat", 0)
  1289. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1290. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1291. channels, _ := c.GetInt64("channel", 0)
  1292. return_blood, _ := c.GetInt64("return_blood", 0)
  1293. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1294. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1295. dialysis_during, _ := c.GetFloat("dialysis_during")
  1296. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1297. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1298. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1299. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1300. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1301. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1302. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1303. setting_pressure := c.GetString("setting_pressure")
  1304. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1305. diastolic_pressure := c.GetString("diastolic_pressure")
  1306. other_complication := c.GetString("other_complication")
  1307. ktv := c.GetString("ktv")
  1308. urr := c.GetString("urr")
  1309. hypertenison, _ := c.GetInt64("hypertenison")
  1310. hypopiesia, _ := c.GetInt64("hypopiesia")
  1311. leave_office_method, _ := c.GetInt64("leave_office_method")
  1312. lapse, _ := c.GetInt64("lapse")
  1313. consciousness, _ := c.GetInt64("consciousness")
  1314. fallrisk, _ := c.GetInt64("fallrisk")
  1315. machine_run := c.GetString("machine_run")
  1316. after_urea := c.GetString("after_urea")
  1317. pip_coagulation := c.GetString("pip_coagulation")
  1318. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1319. transfusion_volume := c.GetString("transfusion_volume")
  1320. last_after_weight := c.GetString("last_after_weight")
  1321. displace_liqui_value := c.GetString("displace_liqui_value")
  1322. start_time := c.GetString("start_time")
  1323. symptom_after_dialysis_remark := c.GetString("symptom_after_dialysis_remark")
  1324. if id <= 0 {
  1325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1326. return
  1327. }
  1328. adminUserInfo := c.GetMobileAdminUserInfo()
  1329. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1330. if patient.ID == 0 {
  1331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1332. return
  1333. }
  1334. if len(recordDateStr) == 0 {
  1335. recordDateStr = time.Now().Format("2006-01-02")
  1336. }
  1337. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1338. fmt.Println("parseDateErr", parseDateErr)
  1339. if parseDateErr != nil {
  1340. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1342. return
  1343. }
  1344. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1345. //now := time.Now()
  1346. //year, month, day := now.Date()
  1347. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1348. //todayTimeStamp := today_time.Unix()
  1349. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1350. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1351. UserOrgId: adminUserInfo.Org.Id,
  1352. PatientId: id,
  1353. AssessmentDate: recordDate.Unix(),
  1354. Temperature: temperature,
  1355. PulseFrequency: pulse_frequency,
  1356. BreathingRate: breathing_rate,
  1357. SystolicBloodPressure: systolic_blood_pressure,
  1358. DiastolicBloodPressure: diastolic_blood_pressure,
  1359. ActualUltrafiltration: actual_ultrafiltration,
  1360. ActualDisplacement: actual_displacement,
  1361. ActualTreatmentHour: actualtreatHour,
  1362. ActualTreatmentMinute: actualtreatmin,
  1363. WeightAfter: weightAfter,
  1364. AdditionalWeight: additionalWeight,
  1365. WeightLoss: weightReduce,
  1366. Cruor: cruor,
  1367. SymptomAfterDialysis: symptomsAfterDialysi,
  1368. InternalFistula: internalFistula,
  1369. Catheter: catheter,
  1370. Complication: complications,
  1371. DialysisIntakes: dialysateVolume,
  1372. CreatedTime: time.Now().Unix(),
  1373. UpdatedTime: time.Now().Unix(),
  1374. Status: 1,
  1375. Remark: remark,
  1376. BloodAccessPartId: blood_access_part_id,
  1377. BloodAccessPartOperaId: blood_access_part_opera_id,
  1378. DialysisIntakesUnit: dialysis_intakes_unit,
  1379. PuncturePointOozingBlood: puncturePointOozingBlood,
  1380. PuncturePointHaematoma: puncturePointHaematoma,
  1381. InternalFistulaTremorAc: internalFistulaTremorAc,
  1382. PatientGose: patientGose,
  1383. InpatientDepartment: inpatientDepartment,
  1384. ObservationContent: observationContent,
  1385. ObservationContentOther: observationContentOther,
  1386. DialysisProcess: dialysis_process,
  1387. InAdvanceMinute: in_advance_minute,
  1388. InAdvanceReason: in_advance_reason,
  1389. HemostasisMinute: hemostasis_minute,
  1390. HemostasisOpera: hemostasis_opera,
  1391. TremorNoise: tremor_noise,
  1392. DisequilibriumSyndrome: disequilibrium_syndrome,
  1393. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1394. ArterialTube: arterial_tube,
  1395. IntravenousTube: intravenous_tube,
  1396. Dialyzer: dialyzer,
  1397. InAdvanceReasonOther: in_advance_reason_other,
  1398. IsEat: is_eat,
  1399. CvcA: cvc_a,
  1400. CvcV: cvc_v,
  1401. Channel: channels,
  1402. ReturnBlood: return_blood,
  1403. RehydrationVolume: rehydration_volume,
  1404. DialysisDuring: dialysis_during,
  1405. StrokeVolume: stroke_volume,
  1406. BloodFlow: blood_flow,
  1407. SealingFluidDispose: sealing_fluid_dispose,
  1408. SealingFluidSpecial: sealing_fluid_special,
  1409. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1410. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1411. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1412. SettingPressure: setting_pressure,
  1413. DiastolicPressure: diastolic_pressure,
  1414. OtherComplication: other_complication,
  1415. Ktv: ktv,
  1416. Urr: urr,
  1417. Hypopiesia: hypopiesia,
  1418. Hypertenison: hypertenison,
  1419. Lapse: lapse,
  1420. LeaveOfficeMethod: leave_office_method,
  1421. Consciousness: consciousness,
  1422. Fallrisk: fallrisk,
  1423. MachineRun: machine_run,
  1424. AfterUrea: after_urea,
  1425. PipCoagulation: pip_coagulation,
  1426. AccumulatedBloodVolume: accumulated_blood_volume,
  1427. TransfusionVolume: transfusion_volume,
  1428. LastAfterWeight: last_after_weight,
  1429. DisplaceLiquiValue: displace_liqui_value,
  1430. RecordTime: startDate.Unix(),
  1431. SymptomAfterDialysisRemark: symptom_after_dialysis_remark,
  1432. }
  1433. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1434. // 查询信息规挡的设置天数
  1435. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1436. if infor.ID > 0 && infor.WeekDay > 0 {
  1437. var cha_time int64
  1438. timeNowStr := time.Now().Format("2006-01-02")
  1439. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1440. //今日的日期减去设置的日期
  1441. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1442. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1443. if cha_time >= recordDate.Unix() {
  1444. //查询审核是否允许
  1445. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1446. //申请状态不允许的情况 拒绝修改
  1447. if infor.ApplicationStatus != 1 {
  1448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1449. return
  1450. }
  1451. }
  1452. }
  1453. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1454. if assessmentAfter.ID == 0 { //新增
  1455. if appRole.UserType == 2 || appRole.UserType == 1 {
  1456. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1457. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1458. } else {
  1459. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1460. }
  1461. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1462. if assessmentAfterDislysis.UserOrgId != 10340 {
  1463. if assessmentAfterDislysis.WeightAfter == 0 {
  1464. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1465. }
  1466. }
  1467. if adminUserInfo.Org.Id == 10693 {
  1468. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1469. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1470. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1471. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1472. }
  1473. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1474. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1475. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1476. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1477. }
  1478. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1479. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1480. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1481. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1482. }
  1483. if assessmentAfterDislysis.PulseFrequency == 0 {
  1484. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1485. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1486. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1487. }
  1488. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1489. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1490. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1491. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1492. }
  1493. }
  1494. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1495. //记录日志
  1496. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1497. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1498. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1499. PatientId: assessmentAfterDislysis.PatientId,
  1500. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1501. Status: 1,
  1502. ErrLog: string(byterequest),
  1503. AdminUserId: adminUserInfo.AdminUser.Id,
  1504. Ctime: 0,
  1505. Mtime: 0,
  1506. Source: "手机端保存透后评估",
  1507. }
  1508. service.CreateAfterDialysisLog(afterDialysisLog)
  1509. finish := models.XtDialysisFinish{
  1510. IsFinish: 1,
  1511. UserOrgId: adminUserInfo.Org.Id,
  1512. Status: 1,
  1513. Ctime: time.Now().Unix(),
  1514. Mtime: 0,
  1515. Module: 9,
  1516. RecordDate: recordDate.Unix(),
  1517. Sourse: 1,
  1518. PatientId: id,
  1519. }
  1520. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1521. if dialysisFinish.ID == 0 {
  1522. service.CreateDialysisFinish(finish)
  1523. }
  1524. redis := service.RedisClient()
  1525. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1526. redis.Set(keyTwo, "", time.Second)
  1527. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1528. //清空key 值
  1529. redis.Set(key, "", time.Second)
  1530. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1531. redis.Set(keyOne, "", time.Second)
  1532. defer redis.Close()
  1533. if err == nil {
  1534. c.ServeSuccessJSON(map[string]interface{}{
  1535. "assessmentAfterDislysis": assessmentAfterDislysis,
  1536. })
  1537. }
  1538. return
  1539. } else { //修改
  1540. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1541. if infor.ID > 0 && infor.WeekDay > 0 {
  1542. var cha_time int64
  1543. timeNowStr := time.Now().Format("2006-01-02")
  1544. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1545. //今日的日期减去设置的日期
  1546. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1547. if cha_time >= recordDate.Unix() {
  1548. //查询审核是否允许
  1549. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1550. //申请状态不允许的情况 拒绝修改
  1551. if infor.ApplicationStatus != 1 {
  1552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1553. return
  1554. }
  1555. }
  1556. }
  1557. if appRole.UserType == 2 || appRole.UserType == 1 {
  1558. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1559. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1560. } else {
  1561. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1562. if assessmentAfterDislysis.Creater == 0 {
  1563. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1564. }
  1565. }
  1566. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1567. assessmentAfterDislysis.ID = assessmentAfter.ID
  1568. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1569. if assessmentAfterDislysis.UserOrgId != 10340 {
  1570. if assessmentAfterDislysis.WeightAfter == 0 {
  1571. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1572. }
  1573. }
  1574. if adminUserInfo.Org.Id == 10693 {
  1575. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1576. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1577. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1578. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1579. }
  1580. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1581. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1582. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1583. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1584. }
  1585. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1586. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1587. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1588. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1589. }
  1590. if assessmentAfterDislysis.PulseFrequency == 0 {
  1591. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1592. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1593. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1594. }
  1595. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1596. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1597. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1598. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1599. }
  1600. }
  1601. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1602. //记录日志
  1603. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1604. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1605. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1606. PatientId: assessmentAfterDislysis.PatientId,
  1607. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1608. Status: 1,
  1609. ErrLog: string(byterequest),
  1610. AdminUserId: adminUserInfo.AdminUser.Id,
  1611. Ctime: time.Now().Unix(),
  1612. Mtime: 0,
  1613. Source: "手机端修改保存透后评估",
  1614. }
  1615. service.CreateAfterDialysisLog(afterDialysisLog)
  1616. redis := service.RedisClient()
  1617. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1618. redis.Set(keyTwo, "", time.Second)
  1619. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1620. //清空key 值
  1621. redis.Set(key, "", time.Second)
  1622. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1623. redis.Set(keyOne, "", time.Second)
  1624. if err == nil {
  1625. c.ServeSuccessJSON(map[string]interface{}{
  1626. "assessmentAfterDislysis": assessmentAfterDislysis,
  1627. })
  1628. return
  1629. }
  1630. }
  1631. return
  1632. }
  1633. func (c *DialysisAPIController) PostDialysisPrescription() {
  1634. id, _ := c.GetInt64("patient", 0)
  1635. recordDateStr := c.GetString("record_date")
  1636. if id <= 0 {
  1637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1638. return
  1639. }
  1640. adminUserInfo := c.GetMobileAdminUserInfo()
  1641. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1642. if patient.ID == 0 {
  1643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1644. return
  1645. }
  1646. if len(recordDateStr) == 0 {
  1647. recordDateStr = time.Now().Format("2006-01-02")
  1648. }
  1649. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1650. if parseDateErr != nil {
  1651. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1653. return
  1654. }
  1655. mode_id, _ := c.GetInt64("mode_id", 0)
  1656. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1657. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1658. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1659. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1660. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1661. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1662. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1663. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1664. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1665. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1666. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1667. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1668. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1669. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1670. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1671. kalium, _ := c.GetFloat("kalium", 0)
  1672. sodium, _ := c.GetFloat("sodium", 0)
  1673. calcium, _ := c.GetFloat("calcium", 0)
  1674. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1675. glucose, _ := c.GetFloat("glucose", 0)
  1676. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1677. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1678. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1679. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1680. conductivity, _ := c.GetFloat("conductivity", 0)
  1681. remark := c.GetString("remark")
  1682. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1683. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1684. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1685. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1686. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1687. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1688. special_medicine_other := c.GetString("special_medicine_other")
  1689. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1690. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1691. blood_access, _ := c.GetInt64("blood_access", 0)
  1692. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1693. body_fluid_other := c.GetString("body_fluid_other")
  1694. niprocart, _ := c.GetInt64("niprocart", 0)
  1695. jms, _ := c.GetInt64("jms", 0)
  1696. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1697. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1698. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1699. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1700. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1701. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1702. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1703. injector, _ := c.GetInt64("injector", 0)
  1704. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1705. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1706. safe_package, _ := c.GetInt64("package", 0)
  1707. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1708. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1709. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1710. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1711. blood := c.GetString("blood")
  1712. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1713. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1714. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1715. displace_speed := c.GetString("displace_speed")
  1716. illness, _ := c.GetInt64("illness")
  1717. amylaceum := c.GetString("amylaceum")
  1718. single_time := c.GetString("single_time")
  1719. single_water := c.GetString("single_water")
  1720. replacement_flow := c.GetString("replacement_flow")
  1721. plasma_separator := c.GetString("plasma_separator")
  1722. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1723. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1724. oxygen_flow := c.GetString("oxygen_flow")
  1725. oxygen_time := c.GetString("oxygen_time")
  1726. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1727. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1728. puncture_needle := c.GetString("puncture_needle")
  1729. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1730. epo := c.GetString("epo")
  1731. epo_count, _ := c.GetFloat("epo_count", 0)
  1732. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1733. admin_user_id, _ := c.GetInt64("admin_user_id")
  1734. is_water := c.GetString("is_water")
  1735. var is_war int64
  1736. if is_water == "是" {
  1737. is_war = 1
  1738. }
  1739. if is_water == "否" {
  1740. is_war = 2
  1741. }
  1742. if is_water == "请选择" {
  1743. is_war = 0
  1744. }
  1745. drhy_water := c.GetString("drhy_water")
  1746. dry_water_hour := c.GetString("dry_water_hour")
  1747. water_machine := c.GetString("water_machine")
  1748. add_amount, _ := c.GetFloat("add_amount")
  1749. reduce_amount, _ := c.GetFloat("reduce_amount")
  1750. dialysis_remark := c.GetString("dialysis_remark")
  1751. prescribing_number, _ := c.GetFloat("prescribing_number")
  1752. prescription_sodium := c.GetString("prescription_sodium")
  1753. start_sodium := c.GetString("start_sodium")
  1754. sodium_curve := c.GetString("sodium_curve")
  1755. treatment_remark := c.GetString("treatment_remark")
  1756. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1757. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1758. prescription_water, _ := c.GetFloat("prescription_water")
  1759. dialysis_strainer := c.GetString("dialysis_strainer")
  1760. chaptalization := c.GetString("chaptalization")
  1761. washing_time := c.GetString("washing_time")
  1762. warsh_count := c.GetString("warsh_count")
  1763. blood_access_part_id := c.GetString("blood_access_part_id")
  1764. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1765. dialyzate := c.GetString("dialyzate")
  1766. first_super := c.GetString("first_super")
  1767. var first_sup int64
  1768. if first_super == "是" {
  1769. first_sup = 1
  1770. }
  1771. if first_super == "否" {
  1772. first_sup = 2
  1773. }
  1774. if first_super == "请选择" {
  1775. first_sup = 0
  1776. }
  1777. is_sequential := c.GetString("is_sequential")
  1778. var is_sequent int64
  1779. if is_sequential == "是" {
  1780. is_sequent = 1
  1781. }
  1782. if is_sequential == "否" {
  1783. is_sequent = 2
  1784. }
  1785. if is_sequential == "请选择" {
  1786. is_sequent = 0
  1787. }
  1788. conduct := c.GetString("conduct")
  1789. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1790. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1791. //
  1792. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1793. // if appRole.UserType == 3 {
  1794. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1795. // if getPermissionErr != nil {
  1796. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1797. // return
  1798. // } else if headNursePermission == nil {
  1799. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1800. // return
  1801. // }
  1802. // }
  1803. //}
  1804. // 查询信息规挡的设置天数
  1805. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1806. if infor.ID > 0 && infor.WeekDay > 0 {
  1807. var cha_time int64
  1808. timeNowStr := time.Now().Format("2006-01-02")
  1809. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1810. //今日的日期减去设置的日期
  1811. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1812. if cha_time >= recordDate.Unix() {
  1813. //查询审核是否允许
  1814. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1815. //申请状态不允许的情况 拒绝修改
  1816. if infor.ApplicationStatus != 1 {
  1817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1818. return
  1819. }
  1820. }
  1821. }
  1822. if mode_id > 0 {
  1823. var str string
  1824. //查找该机构用的是什么透析器
  1825. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1826. if filedConfig.ID > 0 {
  1827. str = dialyzerPerfusionApparatus
  1828. } else {
  1829. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1830. }
  1831. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1832. }
  1833. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1834. var dialysis_dialyszers_id int64
  1835. var dialysis_strainer_id int64
  1836. var dialysis_irrigation_id int64
  1837. if len(goodList) > 0 {
  1838. for _, item := range goodList {
  1839. if item.SpecificationName == dialysis_dialyszers {
  1840. dialysis_dialyszers_id = item.ID
  1841. }
  1842. if item.SpecificationName == dialysis_irrigation {
  1843. dialysis_irrigation_id = item.ID
  1844. }
  1845. if item.SpecificationName == dialysis_strainer {
  1846. dialysis_strainer_id = item.ID
  1847. }
  1848. }
  1849. }
  1850. //TODO 需要根据角色去判断
  1851. prescription := models.DialysisPrescription{
  1852. UserOrgId: adminUserInfo.Org.Id,
  1853. PatientId: id,
  1854. RecordDate: recordDate.Unix(),
  1855. ModeId: mode_id,
  1856. DialysisDuration: dialysis_duration,
  1857. Dialyzer: dialyzer,
  1858. PerfusionApparatus: perfusion_apparatus,
  1859. BloodFlowVolume: blood_flow_volume,
  1860. DewaterAmount: dewater_amount,
  1861. DisplaceLiqui: displace_liqui,
  1862. ReplacementWay: replacement_way,
  1863. Anticoagulant: anticoagulant,
  1864. AnticoagulantShouji: anticoagulant_shouji,
  1865. AnticoagulantWeichi: anticoagulant_weichi,
  1866. AnticoagulantZongliang: anticoagulant_zongliang,
  1867. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1868. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1869. Kalium: kalium,
  1870. Sodium: sodium,
  1871. Calcium: calcium,
  1872. Bicarbonate: bicarbonate,
  1873. Glucose: glucose,
  1874. // DryWeight: dry_weight,
  1875. DialysateFlow: dialysate_flow,
  1876. DialysateTemperature: dialysate_temperature,
  1877. // PrescriptionDoctor: prescription_doctor,
  1878. ReplacementTotal: replacement_total,
  1879. Conductivity: conductivity,
  1880. Remark: remark,
  1881. Status: 1,
  1882. CreatedTime: time.Now().Unix(),
  1883. UpdatedTime: time.Now().Unix(),
  1884. DialysisDurationMinute: dialysisDurationMinute,
  1885. DialysisDurationHour: dialysisDurationHour,
  1886. TargetUltrafiltration: targetUltrafiltration,
  1887. DialysateFormulation: dialysateFormulation,
  1888. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1889. BodyFluid: body_fluid,
  1890. SpecialMedicine: special_medicine,
  1891. SpecialMedicineOther: special_medicine_other,
  1892. DisplaceLiquiPart: displace_liqui_part,
  1893. DisplaceLiquiValue: displace_liqui_value,
  1894. BloodAccess: blood_access,
  1895. Ultrafiltration: ultrafiltration,
  1896. BodyFluidOther: body_fluid_other,
  1897. Niprocart: niprocart,
  1898. Jms: jms,
  1899. FistulaNeedleSet: fistula_needle_set,
  1900. FistulaNeedleSet16: fistula_needle_set_16,
  1901. Hemoperfusion: hemoperfusion,
  1902. DialyserSterilised: dialyser_sterilised,
  1903. Filtryzer: filtryzer,
  1904. Dialyzers: dialyzers,
  1905. Injector: injector,
  1906. Bloodlines: bloodlines,
  1907. TubingHemodialysis: tubing_hemodialysis,
  1908. Package: safe_package,
  1909. ALiquid: a_liquid,
  1910. TargetKtv: target_ktv,
  1911. PreImpulse: pre_impulse,
  1912. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1913. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1914. Blood: blood,
  1915. DialysisDialyszers: dialysis_dialyszers,
  1916. DialysisIrrigation: dialysis_irrigation,
  1917. AntioxidantCommodityName: antioxidant_commodity_name,
  1918. DisplaceSpeed: displace_speed,
  1919. Illness: illness,
  1920. Amylaceum: amylaceum,
  1921. SingleTime: single_time,
  1922. SingleWater: single_water,
  1923. ReplacementFlow: replacement_flow,
  1924. PlasmaSeparator: plasma_separator,
  1925. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1926. OxygenUptake: oxygen_uptake,
  1927. OxygenFlow: oxygen_flow,
  1928. OxygenTime: oxygen_time,
  1929. HemodialysisPipelines: hemodialysis_pipelines,
  1930. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1931. PunctureNeedle: puncture_needle,
  1932. PunctureNeedleCount: puncture_needle_count,
  1933. Epo: epo,
  1934. EpoCount: epo_count,
  1935. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1936. AdminUserId: admin_user_id,
  1937. IsWater: is_war,
  1938. DrhyWater: drhy_water,
  1939. DryWaterHour: dry_water_hour,
  1940. WaterMachine: water_machine,
  1941. AddAmount: add_amount,
  1942. ReduceAmount: reduce_amount,
  1943. DialysisRemark: dialysis_remark,
  1944. PrescribingNumber: prescribing_number,
  1945. StartSodium: start_sodium,
  1946. SodiumCurve: sodium_curve,
  1947. TreatmentRemark: treatment_remark,
  1948. PrescriptionSodium: prescription_sodium,
  1949. DialysisFluidFlow: dialysis_fluid_flow,
  1950. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1951. PrescriptionWater: prescription_water,
  1952. DialysisStrainer: dialysis_strainer,
  1953. Chaptalization: chaptalization,
  1954. WashingTime: washing_time,
  1955. WarshCount: warsh_count,
  1956. BloodAccessPartId: blood_access_part_id,
  1957. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1958. Dialyzate: dialyzate,
  1959. DialysisDialyszersId: dialysis_dialyszers_id,
  1960. DialysisIrrigationId: dialysis_irrigation_id,
  1961. DialysisStrainerId: dialysis_strainer_id,
  1962. FirstSuper: first_sup,
  1963. IsSequential: is_sequent,
  1964. Conduct: conduct,
  1965. }
  1966. if adminUserInfo.Org.Id == 10721 {
  1967. if prescription.ModeId == 2 {
  1968. if prescription.ReplacementTotal == 0 {
  1969. prescription.ReplacementTotal = 15
  1970. }
  1971. }
  1972. }
  1973. //查询最近透析准备表里是否存在 透析器 灌流器
  1974. //
  1975. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1976. //
  1977. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1978. //
  1979. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1980. //if len(mation)>0{
  1981. // for _, item := range splitStr {
  1982. // for _,it := range mation{
  1983. // if(item == it.SpecificationName){
  1984. //
  1985. // //查询最近一次的透析器
  1986. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1987. //
  1988. // if errcode == gorm.ErrRecordNotFound{
  1989. // //插入数据
  1990. // prepare := models.DialysisBeforePrepare{
  1991. // UserOrgId: adminUserInfo.Org.Id,
  1992. // PatientId: id,
  1993. // RecordDate: recordDate.Unix(),
  1994. // GoodTypeId: it.GoodTypeId,
  1995. // GoodId: it.ID,
  1996. // Count: 1,
  1997. // Ctime: time.Now().Unix(),
  1998. // Creater: adminUserInfo.AdminUser.Id,
  1999. // Status:1,
  2000. //
  2001. // }
  2002. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2003. // fmt.Println("",errcode)
  2004. // }
  2005. // }
  2006. // }
  2007. //
  2008. // }
  2009. //
  2010. // for _, item := range splitIrrigation {
  2011. // for _,it := range mation{
  2012. // if(item == it.SpecificationName){
  2013. // //查询最近一次的透析器
  2014. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2015. // if errcode == gorm.ErrRecordNotFound{
  2016. // //插入数据
  2017. // prepare := models.DialysisBeforePrepare{
  2018. // UserOrgId: adminUserInfo.Org.Id,
  2019. // PatientId: id,
  2020. // RecordDate: recordDate.Unix(),
  2021. // GoodTypeId: it.GoodTypeId,
  2022. // GoodId: it.ID,
  2023. // Count: 1,
  2024. // Ctime: time.Now().Unix(),
  2025. // Creater: adminUserInfo.AdminUser.Id,
  2026. // Status:1,
  2027. //
  2028. // }
  2029. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2030. // fmt.Println(errcode)
  2031. // }
  2032. // }
  2033. // }
  2034. // }
  2035. //}
  2036. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2037. if dialysisPrescription.ID == 0 { //新增
  2038. if appRole.UserType == 2 || appRole.UserType == 1 {
  2039. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2040. }
  2041. prescription.Creater = adminUserInfo.AdminUser.Id
  2042. //针对河间咸得
  2043. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2044. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2045. prescription.DisplaceLiquiPart = 0
  2046. prescription.DisplaceLiquiValue = 0
  2047. }
  2048. }
  2049. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2050. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2051. }
  2052. err := service.AddSigleRecord(&prescription)
  2053. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2054. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2055. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2056. if len(monitorList) > 0 {
  2057. var ultrafiltration_rate float64
  2058. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2059. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2060. var replacement_rate float64
  2061. //乘10 除10是为了保留一位小数
  2062. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2063. var firstOpeateTime = monitorList[0].OperateTime
  2064. for _, item := range monitorList {
  2065. //超滤率
  2066. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2067. //置换率
  2068. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2069. //超滤量
  2070. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2071. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2072. //置换量
  2073. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2074. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2075. }
  2076. }
  2077. }
  2078. //记录日志
  2079. byterequest, _ := json.Marshal(prescription)
  2080. prescriptionLog := models.XtDialysisPrescriptionLog{
  2081. UserOrgId: prescription.UserOrgId,
  2082. Ctime: time.Now().Unix(),
  2083. Mtime: 0,
  2084. ErrLog: string(byterequest),
  2085. AdminUserId: adminUserInfo.AdminUser.Id,
  2086. RecordDate: prescription.RecordDate,
  2087. PatientId: prescription.PatientId,
  2088. Source: "手机端新增保存处方",
  2089. Status: 1,
  2090. }
  2091. service.CreatePrescriptionLog(prescriptionLog)
  2092. finish := models.XtDialysisFinish{
  2093. IsFinish: 1,
  2094. UserOrgId: adminUserInfo.Org.Id,
  2095. Status: 1,
  2096. Ctime: time.Now().Unix(),
  2097. Mtime: 0,
  2098. Module: 1,
  2099. RecordDate: recordDate.Unix(),
  2100. Sourse: 1,
  2101. PatientId: id,
  2102. }
  2103. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2104. if dialysisFinish.ID == 0 {
  2105. service.CreateDialysisFinish(finish)
  2106. }
  2107. //长沙南雅医院,自动生成抗凝剂的临时处方
  2108. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2109. if prescribing_number == 0 {
  2110. prescribing_number = 1
  2111. }
  2112. if prescribing_number == 0 && id == 14682 {
  2113. prescribing_number = 2
  2114. }
  2115. if prescribing_number == 0 && id == 18560 {
  2116. prescribing_number = 2
  2117. }
  2118. advice := models.DoctorAdvice{
  2119. UserOrgId: adminUserInfo.Org.Id,
  2120. PatientId: id,
  2121. GroupNo: 0,
  2122. AdviceType: 2,
  2123. RecordDate: recordDate.Unix(),
  2124. AdviceDate: recordDate.Unix(),
  2125. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2126. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2127. AdviceDesc: "",
  2128. ReminderDate: 0,
  2129. SingleDose: anticoagulant_zongliang,
  2130. SingleDoseUnit: "iu",
  2131. DrugSpec: 0,
  2132. DrugSpecUnit: "",
  2133. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2134. PrescribingNumberUnit: "支",
  2135. DeliveryWay: "静脉注射",
  2136. ExecutionFrequency: "上机前",
  2137. AdviceDoctor: 0,
  2138. Status: 1,
  2139. CreatedTime: time.Now().Unix(),
  2140. UpdatedTime: time.Now().Unix(),
  2141. IsPrescription: 1,
  2142. ExecutionState: 2,
  2143. StopState: 2,
  2144. IsSettle: 2,
  2145. }
  2146. // 查询排班信息
  2147. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2148. if schedulePatient.ID > 0 {
  2149. if schedulePatient.ScheduleType == 1 {
  2150. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2151. }
  2152. if schedulePatient.ScheduleType == 2 {
  2153. advice.StartTime = recordDate.Unix() + 9*60*60
  2154. }
  2155. }
  2156. // 抗凝剂名称
  2157. switch anticoagulant {
  2158. case 1:
  2159. advice.AdviceName = "无肝素"
  2160. break
  2161. case 2:
  2162. advice.AdviceName = "普通肝素"
  2163. break
  2164. case 3:
  2165. advice.AdviceName = "低分子肝素"
  2166. break
  2167. case 4:
  2168. advice.AdviceName = "阿加曲班"
  2169. break
  2170. case 5:
  2171. advice.AdviceName = "枸橼酸钠"
  2172. break
  2173. case 6:
  2174. advice.AdviceName = "低分子肝素钙"
  2175. break
  2176. case 7:
  2177. advice.AdviceName = "低分子肝素钠"
  2178. break
  2179. case 8:
  2180. advice.AdviceName = "依诺肝素"
  2181. break
  2182. case 9:
  2183. advice.AdviceName = "达肝素"
  2184. break
  2185. case 10:
  2186. advice.AdviceName = "体外抗凝"
  2187. break
  2188. case 11:
  2189. advice.AdviceName = "那曲肝素"
  2190. break
  2191. case 12:
  2192. advice.AdviceName = "无抗凝剂"
  2193. break
  2194. }
  2195. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2196. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2197. advice.AdviceDoctor = appRole.AdminUserId
  2198. }
  2199. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2200. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2201. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2202. advice.AdviceName = "低分子肝素钠注射液"
  2203. // 修改患者临时医嘱里的抗凝剂医嘱
  2204. advice.ID = advicePrescription.ID
  2205. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2206. } else {
  2207. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2208. advice.AdviceName = "低分子肝素钠注射液"
  2209. // 新增患者临时医嘱里的抗凝剂医嘱
  2210. service.CreateDoctorAdvice(&advice)
  2211. }
  2212. }
  2213. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2214. redis := service.RedisClient()
  2215. defer redis.Close()
  2216. //清空key 值
  2217. redis.Set(key, "", time.Second)
  2218. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2219. redis.Set(keyOne, "", time.Second)
  2220. }
  2221. //获取key,清空redis
  2222. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2223. redis := service.RedisClient()
  2224. //清空key 值
  2225. redis.Set(key, "", time.Second)
  2226. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2227. //清空key 值
  2228. redis.Set(keyOne, "", time.Second)
  2229. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2230. //清空key 值
  2231. redis.Set(keyTwo, "", time.Second)
  2232. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2233. redis.Set(keySix, "", time.Second)
  2234. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2235. redis.Set(keySeven, "", time.Second)
  2236. if err == nil {
  2237. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2238. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2239. //清空key 值
  2240. redis.Set(keyThree, "", time.Second)
  2241. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2242. //清空key 值
  2243. redis.Set(keyFour, "", time.Second)
  2244. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2245. redis.Set(keyFive, "", time.Second)
  2246. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2247. redis.Set(keySix, "", time.Second)
  2248. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2249. redis.Set(keySeven, "", time.Second)
  2250. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2251. //清空key 值
  2252. redis.Set(keyOne, "", time.Second)
  2253. if updateErr != nil {
  2254. utils.ErrorLog("%v", updateErr)
  2255. }
  2256. defer redis.Close()
  2257. c.ServeSuccessJSON(map[string]interface{}{
  2258. "prescription": prescription,
  2259. })
  2260. }
  2261. } else { //修改
  2262. //if mode_id > 0 {
  2263. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2264. //}
  2265. //if template.TemplateId == 1 {
  2266. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2267. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2268. // if getPermissionErr != nil {
  2269. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2270. // return
  2271. // } else if headNursePermission == nil {
  2272. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2273. // return
  2274. // }
  2275. // }
  2276. //}
  2277. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2278. prescription.Modifier = adminUserInfo.AdminUser.Id
  2279. if appRole.UserType == 2 || appRole.UserType == 1 {
  2280. prescription_doctor := adminUserInfo.AdminUser.Id
  2281. prescription.PrescriptionDoctor = prescription_doctor
  2282. } else {
  2283. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2284. }
  2285. if dialysisPrescription.Creater == 0 { //体重称
  2286. prescription.Creater = adminUserInfo.AdminUser.Id
  2287. } else {
  2288. prescription.Creater = dialysisPrescription.Creater
  2289. if adminUserInfo.Org.Id == 9882 {
  2290. if appRole.UserType == 2 || appRole.UserType == 1 {
  2291. prescription_doctor := adminUserInfo.AdminUser.Id
  2292. prescription.PrescriptionDoctor = prescription_doctor
  2293. prescription.Creater = prescription_doctor
  2294. }
  2295. }
  2296. }
  2297. prescription.ID = dialysisPrescription.ID
  2298. if adminUserInfo.Org.Id == 10721 {
  2299. if prescription.ModeId == 2 {
  2300. if prescription.ReplacementTotal == 0 {
  2301. prescription.ReplacementTotal = 15
  2302. }
  2303. }
  2304. }
  2305. service.UpDateDialysisPrescription(&prescription)
  2306. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2307. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2308. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2309. if len(monitorList) > 0 {
  2310. var ultrafiltration_rate float64
  2311. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2312. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2313. var replacement_rate float64
  2314. //乘10 除10是为了保留一位小数
  2315. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2316. var firstOpeateTime = monitorList[0].OperateTime
  2317. for _, item := range monitorList {
  2318. //超滤率
  2319. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2320. //置换率
  2321. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2322. //超滤量
  2323. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2324. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2325. //置换量
  2326. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2327. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2328. }
  2329. }
  2330. }
  2331. //记录日志
  2332. byterequest, _ := json.Marshal(prescription)
  2333. prescriptionLog := models.XtDialysisPrescriptionLog{
  2334. UserOrgId: prescription.UserOrgId,
  2335. Ctime: time.Now().Unix(),
  2336. Mtime: 0,
  2337. ErrLog: string(byterequest),
  2338. AdminUserId: adminUserInfo.AdminUser.Id,
  2339. RecordDate: prescription.RecordDate,
  2340. PatientId: prescription.PatientId,
  2341. Source: "手机端修改处方",
  2342. Status: 1,
  2343. }
  2344. service.CreatePrescriptionLog(prescriptionLog)
  2345. finish := models.XtDialysisFinish{
  2346. IsFinish: 1,
  2347. UserOrgId: adminUserInfo.Org.Id,
  2348. Status: 1,
  2349. Ctime: time.Now().Unix(),
  2350. Mtime: 0,
  2351. Module: 1,
  2352. RecordDate: recordDate.Unix(),
  2353. Sourse: 1,
  2354. PatientId: id,
  2355. }
  2356. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2357. if dialysisFinish.ID == 0 {
  2358. service.CreateDialysisFinish(finish)
  2359. }
  2360. //修改处方
  2361. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2362. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2363. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2364. if advicePrescription.ID > 0 {
  2365. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2366. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2367. redis := service.RedisClient()
  2368. defer redis.Close()
  2369. //清空key 值
  2370. redis.Set(key, "", time.Second)
  2371. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2372. redis.Set(keyOne, "", time.Second)
  2373. }
  2374. }
  2375. //获取key,清空redis
  2376. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2377. redis := service.RedisClient()
  2378. //清空key 值
  2379. redis.Set(key, "", time.Second)
  2380. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2381. //清空key 值
  2382. redis.Set(keyOne, "", time.Second)
  2383. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2384. redis.Set(keySix, "", time.Second)
  2385. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2386. redis.Set(keySeven, "", time.Second)
  2387. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2388. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2389. //清空key 值
  2390. redis.Set(keyTwoOne, "", time.Second)
  2391. defer redis.Close()
  2392. if updateErr != nil {
  2393. utils.ErrorLog("%v", updateErr)
  2394. }
  2395. c.ServeSuccessJSON(map[string]interface{}{
  2396. "prescription": prescription,
  2397. })
  2398. }
  2399. }
  2400. func (c *DialysisAPIController) Finish() {
  2401. id, _ := c.GetInt64("patient", 0)
  2402. recordDateStr := c.GetString("record_date")
  2403. nurseID, _ := c.GetInt64("nurse")
  2404. end_time := c.GetString("end_time")
  2405. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2406. internal_fistula := c.GetString("blood_access_internal_fistula")
  2407. catheter := c.GetString("catheter")
  2408. cruor := c.GetString("cruor")
  2409. mission := c.GetString("mission")
  2410. condenser := c.GetString("condenser")
  2411. if id <= 0 || nurseID <= 0 {
  2412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2413. return
  2414. }
  2415. adminUserInfo := c.GetMobileAdminUserInfo()
  2416. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2417. if patient.ID == 0 {
  2418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2419. return
  2420. }
  2421. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2422. if getNurseErr != nil {
  2423. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2425. return
  2426. } else if nurse == nil {
  2427. c.ErrorLog("护士不存在")
  2428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2429. return
  2430. }
  2431. if len(recordDateStr) == 0 {
  2432. recordDateStr = time.Now().Format("2006-01-02")
  2433. }
  2434. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2435. if parseDateErr != nil {
  2436. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2438. return
  2439. }
  2440. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2441. if parseEndDateErr != nil {
  2442. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2444. return
  2445. }
  2446. // 查询信息规挡的设置天数
  2447. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2448. if infor.ID > 0 && infor.WeekDay > 0 {
  2449. var cha_time int64
  2450. timeNowStr := time.Now().Format("2006-01-02")
  2451. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2452. //今日的日期减去设置的日期
  2453. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2454. if cha_time >= recordDate.Unix() {
  2455. //查询审核是否允许
  2456. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2457. //申请状态不允许的情况 拒绝修改
  2458. if infor.ApplicationStatus != 1 {
  2459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2460. return
  2461. }
  2462. }
  2463. }
  2464. //now := time.Now()
  2465. //year, month, day := now.Date()
  2466. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2467. //todayTimeStamp := today_time.Unix()
  2468. // 获取当天的第一条透析纪录
  2469. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2470. if getMonitorRecordsErr != nil {
  2471. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2473. return
  2474. }
  2475. // 获取当前的最后一条透析纪录
  2476. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2477. if getMonitorRecordsErr != nil {
  2478. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2480. return
  2481. }
  2482. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2483. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2484. if getAADErr != nil {
  2485. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2487. return
  2488. }
  2489. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2490. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2491. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2492. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2493. if assessmentAfterDislysis != nil {
  2494. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2495. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2496. } else {
  2497. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2498. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2499. tempassessmentAfterDislysis.Status = 1
  2500. tempassessmentAfterDislysis.PatientId = id
  2501. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2502. }
  2503. //长沙南雅
  2504. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2505. //获取最后一条透析处方数据
  2506. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2507. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2508. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2509. }
  2510. if dialysisOrder.Stage == 1 {
  2511. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2512. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2513. fmt.Println(value)
  2514. a, b := math.Modf(value)
  2515. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2516. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2517. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2518. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2519. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2520. }
  2521. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2522. //var num1 int64
  2523. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2524. //fmt.Println(num1)
  2525. //sub := float64(num1 / 3600)
  2526. //fmt.Println(sub)
  2527. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2528. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2529. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2530. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2531. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2532. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2533. if adminUserInfo.Org.Id != 10375 {
  2534. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2535. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2536. }
  2537. if adminUserInfo.Org.Id != 10445 {
  2538. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2539. }
  2540. //北方营口医院
  2541. if adminUserInfo.Org.Id == 10445 {
  2542. //获取最后一条透析处方数据
  2543. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2544. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2545. } else {
  2546. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2547. }
  2548. //新化博翔
  2549. if adminUserInfo.Org.Id == 10447 {
  2550. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2551. }
  2552. //阳春
  2553. if adminUserInfo.Org.Id == 10485 {
  2554. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2555. }
  2556. if adminUserInfo.Org.Id == 10551 {
  2557. //获取最后一条透析处方数据
  2558. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2559. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2560. }
  2561. if adminUserInfo.Org.Id == 10580 {
  2562. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2563. }
  2564. if adminUserInfo.Org.Id == 10612 {
  2565. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2566. }
  2567. //孝康
  2568. if adminUserInfo.Org.Id == 10693 {
  2569. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2570. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2571. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2572. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2573. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2574. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2575. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2576. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2577. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2578. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2579. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2580. }
  2581. if adminUserInfo.Org.Id == 10721 {
  2582. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2583. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2584. }
  2585. if adminUserInfo.Org.Id == 10697 {
  2586. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2587. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2588. lastWeightAfter.LastAfterWeight = floatAfeter
  2589. }
  2590. if adminUserInfo.Org.Id == 10624 {
  2591. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2592. }
  2593. }
  2594. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10693 || adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10735 || adminUserInfo.Org.Id == 10742 {
  2595. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2596. if adminUserInfo.Org.Id != 10702 {
  2597. if evaluation.SystolicBloodPressure == 0 {
  2598. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2599. if adminUserInfo.Org.Id == 10693 {
  2600. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2601. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2602. }
  2603. pre := models.PredialysisEvaluation{
  2604. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2605. }
  2606. fmt.Println("prew", pre)
  2607. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2608. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2609. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2610. redis := service.RedisClient()
  2611. redis.Set(key, "", time.Second)
  2612. redis.Set(keyOne, "", time.Second)
  2613. defer redis.Close()
  2614. fmt.Println(getNurseErr)
  2615. }
  2616. }
  2617. if adminUserInfo.Org.Id != 10702 {
  2618. if evaluation.DiastolicBloodPressure == 0 {
  2619. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2620. if adminUserInfo.Org.Id == 10693 {
  2621. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2622. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2623. }
  2624. pres := models.PredialysisEvaluation{
  2625. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2626. }
  2627. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2628. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2629. redis := service.RedisClient()
  2630. redis.Set(key, "", time.Second)
  2631. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2632. redis.Set(keyOne, "", time.Second)
  2633. defer redis.Close()
  2634. fmt.Println(getNurseErr)
  2635. }
  2636. }
  2637. if adminUserInfo.Org.Id != 10702 {
  2638. if evaluation.PulseFrequency == 0 {
  2639. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2640. if adminUserInfo.Org.Id == 10693 {
  2641. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2642. evaluation.PulseFrequency = pulseFrequency
  2643. }
  2644. press := models.PredialysisEvaluation{
  2645. PulseFrequency: evaluation.PulseFrequency,
  2646. }
  2647. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2648. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2649. redis := service.RedisClient()
  2650. redis.Set(key, "", time.Second)
  2651. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2652. redis.Set(keyOne, "", time.Second)
  2653. defer redis.Close()
  2654. fmt.Println(getNurseErr)
  2655. }
  2656. }
  2657. if evaluation.Temperature == 0 {
  2658. evaluation.Temperature = fmonitorRecords.Temperature
  2659. press := models.PredialysisEvaluation{
  2660. Temperature: evaluation.Temperature,
  2661. }
  2662. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2663. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2664. redis := service.RedisClient()
  2665. redis.Set(key, "", time.Second)
  2666. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2667. redis.Set(keyOne, "", time.Second)
  2668. defer redis.Close()
  2669. fmt.Println(getNurseErr)
  2670. }
  2671. }
  2672. if adminUserInfo.Org.Id == 9583 {
  2673. //获取透析处方的最后一条数据
  2674. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2675. if diaerr != nil {
  2676. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2678. return
  2679. }
  2680. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2681. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2682. }
  2683. }
  2684. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2685. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2686. }
  2687. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2688. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2689. }
  2690. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2691. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2692. }
  2693. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2694. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2695. }
  2696. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2697. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2698. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2699. }
  2700. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2701. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2702. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2703. }
  2704. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2705. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2706. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2707. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2708. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2709. }
  2710. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10735 {
  2711. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2712. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2713. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2714. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2715. }
  2716. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2717. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2718. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2719. }
  2720. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2721. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2722. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2723. }
  2724. if lastAssessmentAfterDislysis != nil {
  2725. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2726. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2727. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2728. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2729. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2730. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2731. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2732. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2733. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2734. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2735. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2736. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2737. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2738. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2739. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2740. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2741. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2742. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2743. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2744. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2745. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2746. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2747. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2748. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2749. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2750. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2751. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2752. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2753. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2754. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2755. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2756. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2757. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2758. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2759. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2760. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2761. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2762. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2763. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2764. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2765. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2766. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2767. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2768. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2769. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2770. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2771. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2772. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2773. if tempassessmentAfterDislysis.PatientId == 18695 {
  2774. tempassessmentAfterDislysis.ActualDisplacement = 0
  2775. }
  2776. if adminUserInfo.Org.Id != 10375 {
  2777. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2778. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2779. }
  2780. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2781. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2782. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2783. }
  2784. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2785. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2786. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2787. }
  2788. }
  2789. finish := models.XtDialysisFinish{
  2790. IsFinish: 1,
  2791. UserOrgId: adminUserInfo.Org.Id,
  2792. Status: 1,
  2793. Ctime: time.Now().Unix(),
  2794. Mtime: 0,
  2795. Module: 9,
  2796. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2797. Sourse: 1,
  2798. PatientId: tempassessmentAfterDislysis.PatientId,
  2799. }
  2800. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2801. if dialysisFinish.ID == 0 {
  2802. service.CreateDialysisFinish(finish)
  2803. }
  2804. //孝康
  2805. if adminUserInfo.Org.Id == 10693 {
  2806. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2807. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2808. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2809. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2810. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2811. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2812. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2813. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2814. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2815. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2816. }
  2817. if adminUserInfo.Org.Id == 10697 {
  2818. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2819. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2820. lastWeightAfter.LastAfterWeight = floatAfeter
  2821. }
  2822. if adminUserInfo.Org.Id == 10721 {
  2823. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2824. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2825. }
  2826. tempassessmentAfterDislysis.RecordTime = dialysisOrder.EndTime
  2827. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2828. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2829. redis := service.RedisClient()
  2830. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2831. redis.Set(keyOne, "", time.Second)
  2832. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2833. redis.Set(keyTwo, "", time.Second)
  2834. defer redis.Close()
  2835. //清空key 值
  2836. redis.Set(key, "", time.Second)
  2837. if err != nil {
  2838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2839. return
  2840. }
  2841. if dialysisOrder == nil {
  2842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2843. return
  2844. }
  2845. if dialysisOrder.Stage == 2 {
  2846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2847. return
  2848. }
  2849. if dialysisOrder.Stage == 1 {
  2850. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2851. finish := models.XtDialysisFinish{
  2852. IsFinish: 1,
  2853. UserOrgId: adminUserInfo.Org.Id,
  2854. Status: 1,
  2855. Ctime: time.Now().Unix(),
  2856. Mtime: 0,
  2857. Module: 8,
  2858. RecordDate: recordDate.Unix(),
  2859. Sourse: 1,
  2860. PatientId: id,
  2861. }
  2862. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2863. if dialysisFinish.ID == 0 {
  2864. service.CreateDialysisFinish(finish)
  2865. }
  2866. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2867. redis := service.RedisClient()
  2868. defer redis.Close()
  2869. //清空key 值
  2870. redis.Set(key, "", time.Second)
  2871. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2872. redis.Set(keyOne, "", time.Second)
  2873. //结束时候透析次数加1
  2874. service.UpdateSolutionByPatientId(id)
  2875. //下机完自动消毒,针对长沙南雅
  2876. if dialysisOrder.Stage == 1 {
  2877. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 || adminUserInfo.Org.Id == 10612 {
  2878. //根据床位号获取设备型号
  2879. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2880. //查询使用消毒最后一条消毒记录
  2881. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2882. fmt.Println("err", err)
  2883. if err == gorm.ErrRecordNotFound {
  2884. //查找排班
  2885. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2886. //查询改设备是否有消毒计划
  2887. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2888. //根据床位号获取设备id
  2889. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2890. //查询病人信息
  2891. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2892. var con = ""
  2893. if patients.IsInfectious == 0 {
  2894. con = ""
  2895. }
  2896. if patients.IsInfectious == 1 {
  2897. con = "无"
  2898. }
  2899. if patients.IsInfectious == 2 {
  2900. con = "有"
  2901. }
  2902. if errcode == nil {
  2903. var end_time int64
  2904. end_time = endDate.Unix() + plan.DisinfecTime*60
  2905. //新增消毒
  2906. information := models.DeviceInformation{
  2907. Date: dialysisOrder.DialysisDate,
  2908. Zone: dialysisOrder.ZoneId,
  2909. Class: dialysisOrder.SchedualType,
  2910. BedNumber: dialysisOrder.BedID,
  2911. PatientId: dialysisOrder.PatientId,
  2912. DialysisMode: scheduleByPatient.ModeId,
  2913. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2914. Disinfection: 1,
  2915. DialysisConcentration: 1,
  2916. DisinfectionStatus: 1,
  2917. Move: 1,
  2918. UserOrgId: dialysisOrder.UserOrgId,
  2919. DisinfectType: plan.Way,
  2920. DisinfectantType: plan.MachineDisinfectant,
  2921. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2922. Disinfectant: plan.Disinfectant,
  2923. Ctime: time.Now().Unix(),
  2924. Status: 1,
  2925. SignName: nurseID,
  2926. EquimentId: addmacher.ID,
  2927. DisinfectionResidue: 2,
  2928. Bed: addmacher.BedNumber,
  2929. StartTime: dialysisOrder.StartTime,
  2930. EndTime: dialysisOrder.EndTime,
  2931. Contagion: con,
  2932. WeightLoss: 0,
  2933. Hyperfiltratio: 0,
  2934. DialysisHour: "",
  2935. MachineRun: 1,
  2936. DisinfecStartime: endDate.Unix(),
  2937. DisinfecEndtime: end_time,
  2938. }
  2939. err := service.CreateInformationTwo(&information)
  2940. fmt.Println("报错", err)
  2941. }
  2942. }
  2943. }
  2944. }
  2945. dialysisOrder.Stage = 2
  2946. dialysisOrder.FinishNurse = nurseID
  2947. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2948. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2949. dialysisOrder.EndTime = endDate.Unix()
  2950. // 长沙南雅需求
  2951. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2952. //获取最后1条监测的数据
  2953. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2954. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2955. var accumulatedBloodVolume float64
  2956. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2957. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2958. fmt.Println(err)
  2959. // 查询未执行的医嘱
  2960. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2961. for _, item := range doctorAdvice {
  2962. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2963. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2964. redis := service.RedisClient()
  2965. //清空key 值
  2966. redis.Set(key, "", time.Second)
  2967. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2968. redis.Set(keyTwo, "", time.Second)
  2969. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2970. redis.Set(keyThree, "", time.Second)
  2971. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2972. theTime := toTime.Format("2006-01-02")
  2973. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2974. redis.Set(keyFour, "", time.Second)
  2975. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2976. redis.Set(keyFive, "", time.Second)
  2977. defer redis.Close()
  2978. }
  2979. }
  2980. go func() {
  2981. ssoDomain := beego.AppConfig.String("call_domain")
  2982. api := ssoDomain + "/index/downpatient"
  2983. values := make(url.Values)
  2984. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2985. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2986. values.Set("patient_id", strconv.FormatInt(id, 10))
  2987. http.PostForm(api, values)
  2988. }()
  2989. if err == nil {
  2990. c.ServeSuccessJSON(map[string]interface{}{
  2991. "dialysisOrder": dialysisOrder,
  2992. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2993. })
  2994. } else {
  2995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2996. }
  2997. }
  2998. }
  2999. func (c *DialysisAPIController) GetAllZone() {
  3000. adminUserInfo := c.GetMobileAdminUserInfo()
  3001. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  3002. if err == nil {
  3003. c.ServeSuccessJSON(map[string]interface{}{
  3004. "zone": zone,
  3005. })
  3006. }
  3007. }
  3008. func (c *DialysisAPIController) GetSchedualPatientsList() {
  3009. adminUserInfo := c.GetMobileAdminUserInfo()
  3010. page, _ := c.GetInt64("page", 1)
  3011. limit, _ := c.GetInt64("limit", 10)
  3012. schedulType, _ := c.GetInt64("schedul_type", 0)
  3013. startTime, _ := c.GetInt64("schedul_time", 0)
  3014. partitionType, _ := c.GetInt64("partition_type", 0)
  3015. keywords := c.GetString("keywords")
  3016. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  3017. if err == nil {
  3018. c.ServeSuccessJSON(map[string]interface{}{
  3019. "schedule": dialysisSchedule,
  3020. })
  3021. }
  3022. return
  3023. }
  3024. // /m/api/dialysis/start [post]
  3025. // @param patient_id:int
  3026. // @param record_date:string 排班时间 (yyyy-mm-dd)
  3027. // @param nurse:int 上机护士
  3028. // @param bed:int 床位号
  3029. func (this *DialysisAPIController) StartDialysis() {
  3030. patientID, _ := this.GetInt64("patient_id")
  3031. recordDateStr := this.GetString("record_date")
  3032. nurseID, _ := this.GetInt64("start_nurse")
  3033. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3034. blood_drawing, _ := this.GetInt64("blood_drawing")
  3035. schedual_type, _ := this.GetInt64("schedual_type")
  3036. bedID, _ := this.GetInt64("bed")
  3037. start_time := this.GetString("start_time")
  3038. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3039. change_nurse, _ := this.GetInt64("change_nurse")
  3040. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3041. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3042. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3043. puncture_needle := this.GetString("puncture_needle")
  3044. puncture_way := this.GetString("puncture_way")
  3045. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3046. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3047. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3048. zone_id, _ := this.GetInt64("zone_id")
  3049. elecsign := this.GetString("url")
  3050. nuclein_date_str := this.GetString("nuclein_date_str")
  3051. schedule_remark := this.GetString("schedule_remark")
  3052. order_remark := this.GetString("order_remark")
  3053. catheter_operation := this.GetString("catheter_operation")
  3054. blood_flow_volume := this.GetString("blood_flow_volume")
  3055. dialysis_strainer := this.GetString("dialysis_strainer")
  3056. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3057. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3058. return
  3059. }
  3060. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3061. if parseStartDateErr != nil {
  3062. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3063. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3064. return
  3065. }
  3066. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3067. if parseErr != nil {
  3068. this.ErrorLog("时间解析失败:%v", parseErr)
  3069. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3070. return
  3071. }
  3072. adminUserInfo := this.GetMobileAdminUserInfo()
  3073. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3074. if getPatientErr != nil {
  3075. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3077. return
  3078. } else if patient == nil {
  3079. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3080. return
  3081. }
  3082. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3083. if getNurseErr != nil {
  3084. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3085. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3086. return
  3087. } else if nurse == nil {
  3088. this.ErrorLog("护士不存在")
  3089. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3090. return
  3091. }
  3092. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3093. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3094. if getDeviceNumberErr != nil {
  3095. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3096. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3097. return
  3098. } else if deviceNumber == nil {
  3099. this.ErrorLog("床位号不存在")
  3100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3101. return
  3102. }
  3103. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3104. if getRecordErr != nil {
  3105. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3106. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3107. return
  3108. } else if dialysisRecord != nil {
  3109. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3110. return
  3111. }
  3112. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3113. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3114. timeLayout := "2006-01-02 15:04:05"
  3115. loc, _ := time.LoadLocation("Local")
  3116. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3117. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3118. schedulestartTime := theStartTime.Unix()
  3119. scheduleendTime := theEndTime.Unix()
  3120. var theNucleinDate int64
  3121. timeLayoutOne := "2006-01-02"
  3122. if len(nuclein_date_str) > 0 {
  3123. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3124. if err != nil {
  3125. utils.ErrorLog(err.Error())
  3126. }
  3127. theNucleinDate = theTime.Unix()
  3128. }
  3129. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3130. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3131. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3132. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3133. if adminUserInfo.Org.Id == 10679 || adminUserInfo.Org.Id == 10164 {
  3134. record, _ := service.GetDialysisPrescriptionByRecord(adminUserInfo.Org.Id, patientID, schedulestartTime)
  3135. if record.ID == 0 {
  3136. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescription)
  3137. return
  3138. }
  3139. }
  3140. //查询该床位是否有人用了
  3141. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3142. if err == gorm.ErrRecordNotFound { //空床位
  3143. // 修改了床位逻辑
  3144. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3145. if daySchedule.ID > 0 {
  3146. daySchedule.PartitionId = deviceNumber.ZoneID
  3147. daySchedule.BedId = bedID
  3148. daySchedule.ScheduleType = schedual_type
  3149. daySchedule.UpdatedTime = time.Now().Unix()
  3150. xtSchedule := models.Schedule{
  3151. PartitionId: deviceNumber.ZoneID,
  3152. BedId: bedID,
  3153. ScheduleType: schedual_type,
  3154. UpdatedTime: time.Now().Unix(),
  3155. }
  3156. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3157. if err != nil {
  3158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3159. return
  3160. }
  3161. }
  3162. } else if err == nil {
  3163. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3164. if order.ID > 0 { //该机位被其他人占用了
  3165. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3166. return
  3167. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3168. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3169. if daySchedule.ID > 0 {
  3170. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3171. if err != nil {
  3172. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3173. return
  3174. }
  3175. }
  3176. }
  3177. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3178. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3179. return
  3180. }
  3181. //else if order.ID == 0 { //该床位没被占用
  3182. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3183. // if daySchedule.ID > 0 {
  3184. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3185. // //daySchedule.BedId = bedID
  3186. // //daySchedule.ScheduleType = schedual_type
  3187. // //daySchedule.UpdatedTime = time.Now().Unix()
  3188. // //err := service.UpdateSchedule(&daySchedule)
  3189. // xtSchedule := models.Schedule{
  3190. // PartitionId: deviceNumber.ZoneID,
  3191. // BedId: bedID,
  3192. // ScheduleType: schedual_type,
  3193. // UpdatedTime: time.Now().Unix(),
  3194. // }
  3195. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3196. // if err != nil {
  3197. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3198. // return
  3199. // }
  3200. // }
  3201. //}
  3202. //}
  3203. } else if err != nil {
  3204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3205. return
  3206. }
  3207. // 查询信息规挡的设置天数
  3208. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3209. if infor.ID > 0 && infor.WeekDay > 0 {
  3210. var cha_time int64
  3211. timeNowStr := time.Now().Format("2006-01-02")
  3212. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3213. //今日的日期减去设置的日期
  3214. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3215. if cha_time >= recordDate.Unix() {
  3216. //查询审核是否允许
  3217. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3218. //申请状态不允许的情况 拒绝修改
  3219. if infor.ApplicationStatus != 1 {
  3220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3221. return
  3222. }
  3223. }
  3224. }
  3225. dialysisRecord = &models.DialysisOrder{
  3226. DialysisDate: recordDate.Unix(),
  3227. UserOrgId: adminUserInfo.Org.Id,
  3228. PatientId: patientID,
  3229. Stage: 1,
  3230. BedID: bedID,
  3231. StartNurse: nurseID,
  3232. Status: 1,
  3233. StartTime: startDate.Unix(),
  3234. CreatedTime: time.Now().Unix(),
  3235. UpdatedTime: time.Now().Unix(),
  3236. PunctureNurse: puncture_nurse,
  3237. Creator: adminUserInfo.AdminUser.Id,
  3238. Modifier: adminUserInfo.AdminUser.Id,
  3239. SchedualType: schedual_type,
  3240. WashpipeNurse: washpipe_nurse,
  3241. ChangeNurse: change_nurse,
  3242. DifficultPunctureNurse: difficult_puncture_nurse,
  3243. NewFistulaNurse: new_fistula_nurse,
  3244. ZoneId: zone_id,
  3245. QualityNurseId: quality_nurse_id,
  3246. PunctureNeedle: puncture_needle,
  3247. PunctureWay: puncture_way,
  3248. DialysisIrrigation: dialysis_irrigation,
  3249. DialysisDialyszers: dialysis_dialyszers,
  3250. BloodAccessId: blood_access_id,
  3251. Url: elecsign,
  3252. NucleinDate: theNucleinDate,
  3253. ScheduleRemark: schedule_remark,
  3254. OrderRemark: order_remark,
  3255. CatheterOperation: catheter_operation,
  3256. BloodFlowVolume: blood_flow_volume,
  3257. BloodDrawing: blood_drawing,
  3258. DialysisStrainer: dialysis_strainer,
  3259. }
  3260. //查询该床位是否有人用了
  3261. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3262. if errorscode == gorm.ErrRecordNotFound {
  3263. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3264. finish := models.XtDialysisFinish{
  3265. IsFinish: 1,
  3266. UserOrgId: adminUserInfo.Org.Id,
  3267. Status: 1,
  3268. Ctime: time.Now().Unix(),
  3269. Mtime: 0,
  3270. Module: 6,
  3271. RecordDate: schedulestartTime,
  3272. Sourse: 1,
  3273. PatientId: patientID,
  3274. }
  3275. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3276. if dialysisFinish.ID == 0 {
  3277. service.CreateDialysisFinish(finish)
  3278. }
  3279. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3280. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3281. //统计该患者总次数
  3282. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3283. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3284. }
  3285. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3286. //统计该患者总次数
  3287. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3288. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3289. }
  3290. redis := service.RedisClient()
  3291. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3292. redis.Set(key, "", time.Second)
  3293. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3294. //清空key 值
  3295. redis.Set(keyOne, "", time.Second)
  3296. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3297. //清空key 值
  3298. redis.Set(keyTwo, "", time.Second)
  3299. if createErr != nil {
  3300. this.ErrorLog("上机失败:%v", createErr)
  3301. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3302. return
  3303. }
  3304. }
  3305. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3306. var tempdispose string
  3307. // 只针对中能建
  3308. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3309. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3310. }
  3311. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3312. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3313. }
  3314. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3315. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3316. //}
  3317. var ultrafiltration_rate float64
  3318. var ultrafiltration_rate_one string
  3319. var replacement_rate float64
  3320. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3321. //后期预增脱水量
  3322. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3323. if prescription.ID > 0 {
  3324. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3325. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3326. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375 || adminUserInfo.Org.Id == 10599) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  3327. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3328. }
  3329. if adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10740 || adminUserInfo.Org.Id == 10745 {
  3330. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3331. }
  3332. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3333. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3334. }
  3335. //针对医师汇
  3336. if adminUserInfo.Org.Id == 10121 {
  3337. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3338. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3339. }
  3340. //针对通道
  3341. if adminUserInfo.Org.Id == 10234 {
  3342. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3343. }
  3344. //针对监利大垸医院
  3345. if template.TemplateId == 41 {
  3346. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3347. }
  3348. //针对肇庆三鹤血液透析中心
  3349. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3350. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3351. }
  3352. if adminUserInfo.Org.Id == 10469 {
  3353. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3354. }
  3355. if adminUserInfo.Org.Id == 10667 {
  3356. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3357. }
  3358. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3359. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3360. }
  3361. // 只针对方济医院
  3362. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3363. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3364. ultrafiltration_rate = value
  3365. }
  3366. //针对
  3367. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3368. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3369. ultrafiltration_rate = ultrafiltration_rate / 1000
  3370. }
  3371. if adminUserInfo.Org.Id == 10551 {
  3372. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3373. ultrafiltration_rate = ultrafiltration_rate / 1000
  3374. }
  3375. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3376. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3377. ultrafiltration_rate = ultrafiltration_rate / 1000
  3378. }
  3379. if adminUserInfo.Org.Id == 10580 {
  3380. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3381. ultrafiltration_rate = ultrafiltration_rate / 1000
  3382. }
  3383. if adminUserInfo.Org.Id == 10629 {
  3384. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3385. ultrafiltration_rate = ultrafiltration_rate / 1000
  3386. }
  3387. if adminUserInfo.Org.Id == 10644 || adminUserInfo.Org.Id == 10751 {
  3388. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3389. ultrafiltration_rate = ultrafiltration_rate / 1000
  3390. }
  3391. if adminUserInfo.Org.Id == 10751 {
  3392. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3393. ultrafiltration_rate = ultrafiltration_rate / 1000
  3394. }
  3395. if adminUserInfo.Org.Id == 10667 {
  3396. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3397. ultrafiltration_rate = ultrafiltration_rate / 1000
  3398. }
  3399. if adminUserInfo.Org.Id == 10693 {
  3400. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3401. ultrafiltration_rate = ultrafiltration_rate
  3402. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3403. }
  3404. if adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10731 {
  3405. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3406. ultrafiltration_rate = ultrafiltration_rate
  3407. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3408. }
  3409. if adminUserInfo.Org.Id == 10206 {
  3410. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60)
  3411. ultrafiltration_rate = ultrafiltration_rate
  3412. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3413. }
  3414. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3415. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3416. ultrafiltration_rate = ultrafiltration_rate
  3417. }
  3418. if adminUserInfo.Org.Id == 10702 {
  3419. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3420. ultrafiltration_rate = ultrafiltration_rate / 1000
  3421. }
  3422. if adminUserInfo.Org.Id == 10723 {
  3423. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3424. ultrafiltration_rate = ultrafiltration_rate / 1000
  3425. }
  3426. if adminUserInfo.Org.Id == 10721 {
  3427. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3428. ultrafiltration_rate = ultrafiltration_rate / 1000
  3429. }
  3430. if adminUserInfo.Org.Id == 10721 {
  3431. if prescription.ModeId == 2 {
  3432. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3433. if totalMin == 0 {
  3434. totalMin = 240
  3435. }
  3436. if prescription.ReplacementTotal == 0 {
  3437. prescription.ReplacementTotal = 15
  3438. }
  3439. //乘10 除10是为了保留一位小数
  3440. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3441. }
  3442. }
  3443. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10731 || adminUserInfo.Org.Id == 10727 {
  3444. if prescription.ModeId == 2 {
  3445. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3446. if totalMin == 0 {
  3447. totalMin = 240
  3448. }
  3449. if prescription.DisplaceLiquiValue == 0 {
  3450. prescription.ReplacementTotal = 32
  3451. }
  3452. //乘10 除10是为了保留一位小数
  3453. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3454. }
  3455. }
  3456. }
  3457. }
  3458. if adminUserInfo.Org.Id == 10172 {
  3459. if prescription.ID == 0 {
  3460. if prescription.ModeId == 2 {
  3461. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3462. if totalMin == 0 {
  3463. totalMin = 240
  3464. }
  3465. if prescription.ReplacementTotal == 0 {
  3466. prescription.ReplacementTotal = 15
  3467. }
  3468. //乘10 除10是为了保留一位小数
  3469. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3470. }
  3471. }
  3472. }
  3473. record := models.MonitoringRecord{
  3474. UserOrgId: adminUserInfo.Org.Id,
  3475. PatientId: patientID,
  3476. DialysisOrderId: dialysisRecord.ID,
  3477. MonitoringDate: schedulestartTime,
  3478. OperateTime: startDate.Unix(),
  3479. // MonitoringTime: recordTime,
  3480. MonitoringNurse: nurseID,
  3481. Dispose: tempdispose,
  3482. UltrafiltrationRate: ultrafiltration_rate,
  3483. UltrafiltrationVolume: 0,
  3484. Status: 1,
  3485. CreatedTime: time.Now().Unix(),
  3486. UpdatedTime: time.Now().Unix(),
  3487. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3488. ReplacementRate: replacement_rate,
  3489. }
  3490. //只针对广慈医院
  3491. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10517 || adminUserInfo.Org.Id == 10679 || adminUserInfo.Org.Id == 10742 {
  3492. // 查询病人是否有透前评估数据
  3493. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3494. //如果有数据就插入
  3495. if errcode == nil {
  3496. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3497. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3498. record.BreathingRate = befor.BreathingRate
  3499. record.PulseFrequency = befor.PulseFrequency
  3500. record.Temperature = befor.Temperature
  3501. }
  3502. }
  3503. //孝昌
  3504. if adminUserInfo.Org.Id == 10693 {
  3505. // 查询病人是否有透前评估数据
  3506. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3507. //如果有数据就插入
  3508. if errcode == nil {
  3509. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3510. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3511. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3512. record.BreathingRate = befor.BreathingRate
  3513. }
  3514. }
  3515. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3516. if newdialysisRecord.ID > 0 {
  3517. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3518. record.Temperature = 36.5
  3519. record.ArterialPressure = -100
  3520. record.DialysateTemperature = 36.5
  3521. record.Conductivity = 14
  3522. record.BreathingRate = "20"
  3523. record.VenousPressure = 80
  3524. record.TransmembranePressure = 60
  3525. record.Dispose = catheter_operation
  3526. }
  3527. //针对新化博翔
  3528. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3529. record.BloodOxygenSaturation = "99"
  3530. record.Conductivity = 14
  3531. record.DialysateTemperature = 36.5
  3532. record.BreathingRate = "20"
  3533. }
  3534. //针对兰溪人民医院的需求
  3535. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3536. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3537. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3538. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3539. record.Temperature = befor.Temperature
  3540. record.PulseFrequency = befor.PulseFrequency
  3541. record.BreathingRate = befor.BreathingRate
  3542. }
  3543. //针对乐山友谊医院的需求
  3544. if adminUserInfo.Org.Id == 10677 {
  3545. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3546. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3547. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3548. record.Temperature = befor.Temperature
  3549. record.PulseFrequency = befor.PulseFrequency
  3550. record.BreathingRate = befor.BreathingRate
  3551. }
  3552. //新化博翔
  3553. if adminUserInfo.Org.Id == 10447 {
  3554. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3555. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3556. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3557. record.BreathingRate = befor.BreathingRate
  3558. }
  3559. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3560. record.PulseFrequency = 80
  3561. record.Temperature = 36.5
  3562. }
  3563. //诊断灵山圣康
  3564. if adminUserInfo.Org.Id == 10375 {
  3565. record.Conductivity = 13.8
  3566. record.DialysateTemperature = 37
  3567. record.DialysateFlow = 500
  3568. record.BloodFlowVolume = 200
  3569. record.BreathingRate = "18"
  3570. record.SodiumConcentration = 140
  3571. }
  3572. //江成肾病医院
  3573. if adminUserInfo.Org.Id == 10517 {
  3574. record.SodiumConcentration = 138
  3575. record.DialysateTemperature = 36.5
  3576. }
  3577. //濉溪杏康血液透析中心
  3578. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3579. record.BloodFlowVolume = prescription.BloodFlowVolume
  3580. }
  3581. //胶州少海医院
  3582. if adminUserInfo.Org.Id == 10735 {
  3583. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3584. dialysisPrescription, _ := service.GetDialysisPrescription(patientID, adminUserInfo.Org.Id, recordDate.Unix())
  3585. record.BreathingRate = befor.BreathingRate
  3586. record.BloodFlowVolume = dialysisPrescription.BloodFlowVolume
  3587. record.Temperature = befor.Temperature
  3588. record.PulseFrequency = befor.PulseFrequency
  3589. }
  3590. if adminUserInfo.Org.Id != 10683 {
  3591. err = service.CreateMonitor(&record)
  3592. }
  3593. //记录日志
  3594. byterequest, _ := json.Marshal(record)
  3595. monitorRecordLog := models.XtMonitorRecordLog{
  3596. RecordDate: record.MonitoringDate,
  3597. PatientId: record.PatientId,
  3598. Module: 1,
  3599. AdminUserId: adminUserInfo.AdminUser.Id,
  3600. Ctime: time.Now().Unix(),
  3601. Mtime: 0,
  3602. Status: 1,
  3603. UserOrgId: record.UserOrgId,
  3604. ErrLog: string(byterequest),
  3605. Source: "执行上机时新增监测",
  3606. }
  3607. service.CreateMonitorRecordLog(monitorRecordLog)
  3608. finish := models.XtDialysisFinish{
  3609. IsFinish: 1,
  3610. UserOrgId: adminUserInfo.Org.Id,
  3611. Status: 1,
  3612. Ctime: time.Now().Unix(),
  3613. Mtime: 0,
  3614. Module: 7,
  3615. RecordDate: schedulestartTime,
  3616. Sourse: 1,
  3617. PatientId: patientID,
  3618. }
  3619. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3620. if dialysisFinish.ID == 0 {
  3621. service.CreateDialysisFinish(finish)
  3622. }
  3623. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3624. redis := service.RedisClient()
  3625. //清空key 值
  3626. redis.Set(key, "", time.Second)
  3627. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3628. redis.Set(keyOne, "", time.Second)
  3629. defer redis.Close()
  3630. if err != nil {
  3631. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3632. return
  3633. }
  3634. }
  3635. go func() {
  3636. ssoDomain := beego.AppConfig.String("call_domain")
  3637. api := ssoDomain + "/index/uppatient"
  3638. values := make(url.Values)
  3639. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3640. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3641. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3642. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3643. http.PostForm(api, values)
  3644. }()
  3645. this.ServeSuccessJSON(map[string]interface{}{
  3646. "dialysis_order": newdialysisRecord,
  3647. "monitor": record,
  3648. })
  3649. return
  3650. }
  3651. func (c *DialysisAPIController) PostSolution() {
  3652. id, _ := c.GetInt64("patient", 0)
  3653. recordDateStr := c.GetString("record_date")
  3654. if id <= 0 {
  3655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3656. return
  3657. }
  3658. adminUserInfo := c.GetMobileAdminUserInfo()
  3659. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3660. if patient.ID == 0 {
  3661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3662. return
  3663. }
  3664. if len(recordDateStr) == 0 {
  3665. recordDateStr = time.Now().Format("2006-01-02")
  3666. }
  3667. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3668. if parseDateErr != nil {
  3669. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3671. return
  3672. }
  3673. mode_id, _ := c.GetInt64("mode_id", 0)
  3674. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3675. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3676. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3677. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3678. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3679. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3680. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3681. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3682. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3683. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3684. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3685. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3686. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3687. kalium, _ := c.GetFloat("kalium", 0)
  3688. sodium, _ := c.GetFloat("sodium", 0)
  3689. calcium, _ := c.GetFloat("calcium", 0)
  3690. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3691. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3692. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3693. glucose, _ := c.GetFloat("glucose", 0)
  3694. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3695. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3696. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3697. conductivity, _ := c.GetFloat("conductivity", 0)
  3698. remark := c.GetString("remark")
  3699. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3700. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3701. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3702. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3703. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3704. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3705. special_medicine_other := c.GetString("special_medicine_other")
  3706. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3707. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3708. blood_access, _ := c.GetInt64("blood_access", 0)
  3709. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3710. body_fluid_other := c.GetString("body_fluid_other")
  3711. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3712. niprocart, _ := c.GetInt64("niprocart", 0)
  3713. jms, _ := c.GetInt64("jms", 0)
  3714. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3715. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3716. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3717. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3718. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3719. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3720. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3721. injector, _ := c.GetInt64("injector", 0)
  3722. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3723. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3724. safe_package, _ := c.GetInt64("package", 0)
  3725. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3726. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3727. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3728. blood := c.GetString("blood")
  3729. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3730. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3731. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3732. displace_speed := c.GetString("displace_speed")
  3733. illness, _ := c.GetInt64("illness")
  3734. amylaceum := c.GetString("amylaceum")
  3735. single_time := c.GetString("single_time")
  3736. single_water := c.GetString("single_water")
  3737. replacement_flow := c.GetString("replacement_flow")
  3738. plasma_separator := c.GetString("plasma_separator")
  3739. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3740. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3741. oxygen_flow := c.GetString("oxygen_flow")
  3742. oxygen_time := c.GetString("oxygen_time")
  3743. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3744. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3745. puncture_needle := c.GetString("puncture_needle")
  3746. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3747. epo := c.GetString("epo")
  3748. epo_count, _ := c.GetFloat("epo_count", 0)
  3749. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3750. pre_impulse := c.GetString("pre_impulse")
  3751. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3752. admin_user_id, _ := c.GetInt64("admin_user_id")
  3753. is_water := c.GetString("is_water")
  3754. add_amount, _ := c.GetFloat("add_amount")
  3755. reduce_amount, _ := c.GetFloat("reduce_amount")
  3756. prescribing_number, _ := c.GetFloat("prescribing_number")
  3757. treatment_remark := c.GetString("treatment_remark")
  3758. prescription_sodium := c.GetString("prescription_sodium")
  3759. start_sodium := c.GetString("start_sodium")
  3760. sodium_curve := c.GetString("sodium_curve")
  3761. var is_war int64
  3762. if is_water == "是" {
  3763. is_war = 1
  3764. }
  3765. if is_water == "否" {
  3766. is_war = 2
  3767. }
  3768. if is_water == "请选择" {
  3769. is_war = 0
  3770. }
  3771. drhy_water := c.GetString("drhy_water")
  3772. dry_water_hour := c.GetString("dry_water_hour")
  3773. water_machine := c.GetString("water_machine")
  3774. dialysis_remark := c.GetString("dialysis_remark")
  3775. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3776. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3777. prescription_water, _ := c.GetFloat("prescription_water")
  3778. dialysis_strainer := c.GetString("dialysis_strainer")
  3779. chaptalization := c.GetString("chaptalization")
  3780. washing_time := c.GetString("washing_time")
  3781. warsh_count := c.GetString("warsh_count")
  3782. blood_access_part_id := c.GetString("blood_access_part_id")
  3783. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3784. dialyzate := c.GetString("dialyzate")
  3785. first_super := c.GetString("first_super")
  3786. is_sequential := c.GetString("is_sequential")
  3787. var fisrt_sup int64
  3788. if first_super == "是" {
  3789. fisrt_sup = 1
  3790. }
  3791. if first_super == "否" {
  3792. fisrt_sup = 2
  3793. }
  3794. if first_super == "请选择" {
  3795. fisrt_sup = 0
  3796. }
  3797. var is_sequen int64
  3798. if is_sequential == "是" {
  3799. is_sequen = 1
  3800. }
  3801. if is_sequential == "否" {
  3802. is_sequen = 2
  3803. }
  3804. if is_sequential == "请选择" {
  3805. is_sequen = 0
  3806. }
  3807. conduct := c.GetString("conduct")
  3808. if mode_id > 0 {
  3809. var str string
  3810. //查找该机构用的是什么透析器
  3811. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3812. if filedConfig.ID > 0 {
  3813. str = dialyzerPerfusionApparatus
  3814. } else {
  3815. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3816. }
  3817. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3818. }
  3819. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3820. //
  3821. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3822. // if appRole.UserType == 3 {
  3823. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3824. // if getPermissionErr != nil {
  3825. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3826. // return
  3827. // } else if headNursePermission == nil {
  3828. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3829. // return
  3830. // }
  3831. // }
  3832. //}
  3833. // 查询信息规挡的设置天数
  3834. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3835. if infor.ID > 0 && infor.WeekDay > 0 {
  3836. var cha_time int64
  3837. timeNowStr := time.Now().Format("2006-01-02")
  3838. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3839. //今日的日期减去设置的日期
  3840. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3841. if cha_time >= recordDate.Unix() {
  3842. //查询审核是否允许
  3843. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3844. //申请状态不允许的情况 拒绝修改
  3845. if infor.ApplicationStatus != 1 {
  3846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3847. return
  3848. }
  3849. }
  3850. }
  3851. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  3852. var dialysis_dialyszers_id int64
  3853. var dialysis_strainer_id int64
  3854. var dialysis_irrigation_id int64
  3855. if len(goodList) > 0 {
  3856. for _, item := range goodList {
  3857. if item.SpecificationName == dialysis_dialyszers {
  3858. dialysis_dialyszers_id = item.ID
  3859. }
  3860. if item.SpecificationName == dialysis_irrigation {
  3861. dialysis_irrigation_id = item.ID
  3862. }
  3863. if item.SpecificationName == dialysis_strainer {
  3864. dialysis_strainer_id = item.ID
  3865. }
  3866. }
  3867. }
  3868. prescription := models.DialysisPrescription{
  3869. UserOrgId: adminUserInfo.Org.Id,
  3870. PatientId: id,
  3871. RecordDate: recordDate.Unix(),
  3872. ModeId: mode_id,
  3873. DialysisDuration: dialysis_duration,
  3874. Dialyzer: dialyzer,
  3875. PerfusionApparatus: perfusion_apparatus,
  3876. BloodFlowVolume: blood_flow_volume,
  3877. DewaterAmount: dewater_amount,
  3878. DisplaceLiqui: displace_liqui,
  3879. ReplacementWay: replacement_way,
  3880. Anticoagulant: anticoagulant,
  3881. AnticoagulantShouji: anticoagulant_shouji,
  3882. AnticoagulantWeichi: anticoagulant_weichi,
  3883. AnticoagulantZongliang: anticoagulant_zongliang,
  3884. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3885. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3886. Kalium: kalium,
  3887. Sodium: sodium,
  3888. Calcium: calcium,
  3889. Bicarbonate: bicarbonate,
  3890. Glucose: glucose,
  3891. // DryWeight: dry_weight,
  3892. DialysateFlow: dialysate_flow,
  3893. DialysateTemperature: dialysate_temperature,
  3894. Conductivity: conductivity,
  3895. Remark: remark,
  3896. Status: 1,
  3897. CreatedTime: time.Now().Unix(),
  3898. UpdatedTime: time.Now().Unix(),
  3899. DialysisDurationMinute: dialysisDurationMinute,
  3900. DialysisDurationHour: dialysisDurationHour,
  3901. TargetUltrafiltration: targetUltrafiltration,
  3902. DialysateFormulation: dialysateFormulation,
  3903. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3904. BodyFluid: body_fluid,
  3905. SpecialMedicine: special_medicine,
  3906. SpecialMedicineOther: special_medicine_other,
  3907. DisplaceLiquiPart: displace_liqui_part,
  3908. DisplaceLiquiValue: displace_liqui_value,
  3909. BloodAccess: blood_access,
  3910. Ultrafiltration: ultrafiltration,
  3911. BodyFluidOther: body_fluid_other,
  3912. ReplacementTotal: replacement_total,
  3913. Niprocart: niprocart,
  3914. Jms: jms,
  3915. FistulaNeedleSet: fistula_needle_set,
  3916. FistulaNeedleSet16: fistula_needle_set_16,
  3917. Hemoperfusion: hemoperfusion,
  3918. DialyserSterilised: dialyser_sterilised,
  3919. Filtryzer: filtryzer,
  3920. TargetKtv: target_ktv,
  3921. Dialyzers: dialyzers,
  3922. Injector: injector,
  3923. Bloodlines: bloodlines,
  3924. TubingHemodialysis: tubing_hemodialysis,
  3925. Package: safe_package,
  3926. ALiquid: a_liquid,
  3927. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3928. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3929. Blood: blood,
  3930. DialysisDialyszers: dialysis_dialyszers,
  3931. DialysisIrrigation: dialysis_irrigation,
  3932. AntioxidantCommodityName: antioxidant_commodity_name,
  3933. DisplaceSpeed: displace_speed,
  3934. Illness: illness,
  3935. Amylaceum: amylaceum,
  3936. SingleWater: single_water,
  3937. SingleTime: single_time,
  3938. ReplacementFlow: replacement_flow,
  3939. PlasmaSeparator: plasma_separator,
  3940. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3941. OxygenUptake: oxygen_uptake,
  3942. OxygenTime: oxygen_time,
  3943. OxygenFlow: oxygen_flow,
  3944. HemodialysisPipelines: hemodialysis_pipelines,
  3945. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3946. PunctureNeedle: puncture_needle,
  3947. PunctureNeedleCount: puncture_needle_count,
  3948. Epo: epo,
  3949. EpoCount: epo_count,
  3950. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3951. PreImpulse: impulse,
  3952. AdminUserId: admin_user_id,
  3953. IsWater: is_war,
  3954. DrhyWater: drhy_water,
  3955. DryWaterHour: dry_water_hour,
  3956. WaterMachine: water_machine,
  3957. AddAmount: add_amount,
  3958. ReduceAmount: reduce_amount,
  3959. DialysisRemark: dialysis_remark,
  3960. PrescribingNumber: prescribing_number,
  3961. PrescriptionSodium: prescription_sodium,
  3962. StartSodium: start_sodium,
  3963. SodiumCurve: sodium_curve,
  3964. TreatmentRemark: treatment_remark,
  3965. DialysisFluidFlow: dialysis_fluid_flow,
  3966. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3967. PrescriptionWater: prescription_water,
  3968. DialysisStrainer: dialysis_strainer,
  3969. Chaptalization: chaptalization,
  3970. WashingTime: washing_time,
  3971. WarshCount: warsh_count,
  3972. BloodAccessPartId: blood_access_part_id,
  3973. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3974. Dialyzate: dialyzate,
  3975. DialysisDialyszersId: dialysis_dialyszers_id,
  3976. DialysisIrrigationId: dialysis_irrigation_id,
  3977. DialysisStrainerId: dialysis_strainer_id,
  3978. FirstSuper: fisrt_sup,
  3979. IsSequential: is_sequen,
  3980. Conduct: conduct,
  3981. }
  3982. if adminUserInfo.Org.Id == 10721 {
  3983. if prescription.ModeId == 2 {
  3984. if prescription.ReplacementTotal == 0 {
  3985. prescription.ReplacementTotal = 15
  3986. }
  3987. }
  3988. }
  3989. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3990. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3991. //
  3992. if appRole.UserType == 2 || appRole.UserType == 1 {
  3993. prescription_doctor = adminUserInfo.AdminUser.Id
  3994. prescription.PrescriptionDoctor = prescription_doctor
  3995. }
  3996. if dialysisPrescription.ID == 0 { //新增
  3997. prescription.Creater = adminUserInfo.AdminUser.Id
  3998. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3999. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4000. }
  4001. } else { //修改
  4002. if dialysisPrescription.Creater == 0 {
  4003. prescription.Creater = adminUserInfo.AdminUser.Id
  4004. } else {
  4005. prescription.Creater = dialysisPrescription.Creater
  4006. if adminUserInfo.Org.Id == 9882 {
  4007. if appRole.UserType == 2 || appRole.UserType == 1 {
  4008. prescription.Creater = adminUserInfo.AdminUser.Id
  4009. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  4010. }
  4011. }
  4012. }
  4013. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4014. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4015. }
  4016. //if/**/
  4017. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4018. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  4019. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4020. // if getPermissionErr != nil {
  4021. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4022. // return
  4023. // } else if headNursePermission == nil {
  4024. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4025. // return
  4026. // }
  4027. //}
  4028. //prescription.Creater = dialysisPrescription.Creater
  4029. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4030. prescription.Modifier = adminUserInfo.AdminUser.Id
  4031. prescription.ID = dialysisPrescription.ID
  4032. }
  4033. solution := models.DialysisSolution{
  4034. RegistrarsId: adminUserInfo.AdminUser.Id,
  4035. UserOrgId: adminUserInfo.Org.Id,
  4036. Doctor: prescription_doctor,
  4037. PatientId: id,
  4038. ModeId: mode_id,
  4039. DialysisDuration: dialysis_duration,
  4040. PerfusionApparatus: perfusion_apparatus,
  4041. BloodFlowVolume: blood_flow_volume,
  4042. Dewater: dewater_amount,
  4043. DisplaceLiqui: displace_liqui,
  4044. ReplacementWay: replacement_way,
  4045. Anticoagulant: anticoagulant,
  4046. AnticoagulantShouji: anticoagulant_shouji,
  4047. AnticoagulantWeichi: anticoagulant_weichi,
  4048. AnticoagulantZongliang: anticoagulant_zongliang,
  4049. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4050. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4051. Kalium: kalium,
  4052. Sodium: sodium,
  4053. Calcium: calcium,
  4054. Bicarbonate: bicarbonate,
  4055. Glucose: glucose,
  4056. // DryWeight: dry_weight,
  4057. DialysateFlow: dialysate_flow,
  4058. DialysateTemperature: dialysate_temperature,
  4059. Conductivity: conductivity,
  4060. Remark: remark,
  4061. Status: 1,
  4062. CreatedTime: time.Now().Unix(),
  4063. UpdatedTime: time.Now().Unix(),
  4064. DialysisDurationMinute: dialysisDurationMinute,
  4065. DialysisDurationHour: dialysisDurationHour,
  4066. TargetUltrafiltration: targetUltrafiltration,
  4067. DialysateFormulation: dialysateFormulation,
  4068. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4069. BodyFluid: body_fluid,
  4070. SpecialMedicine: special_medicine,
  4071. SpecialMedicineOther: special_medicine_other,
  4072. DisplaceLiquiPart: displace_liqui_part,
  4073. DisplaceLiquiValue: displace_liqui_value,
  4074. BloodAccess: blood_access,
  4075. Ultrafiltration: ultrafiltration,
  4076. BodyFluidOther: body_fluid_other,
  4077. ReplacementTotal: replacement_total,
  4078. TargetKtv: target_ktv,
  4079. DialysisDialyszers: dialysis_dialyszers,
  4080. DialysisIrrigation: dialysis_irrigation,
  4081. HemodialysisPipelines: hemodialysis_pipelines,
  4082. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4083. PunctureNeedle: puncture_needle,
  4084. PunctureNeedleCount: puncture_needle_count,
  4085. Epo: epo,
  4086. EpoCount: epo_count,
  4087. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4088. PreImpulse: impulse,
  4089. SolutionStatus: 1,
  4090. DialysisRemark: dialysis_remark,
  4091. PrescribingNumber: prescribing_number,
  4092. PrescriptionSodium: prescription_sodium,
  4093. StartSodium: start_sodium,
  4094. SodiumCurve: sodium_curve,
  4095. TreatmentRemark: treatment_remark,
  4096. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4097. DialysisFluidFlow: dialysis_fluid_flow,
  4098. PrescriptionWater: prescription_water,
  4099. DialysisStrainer: dialysis_strainer,
  4100. Chaptalization: chaptalization,
  4101. WashingTime: washing_time,
  4102. WarshCount: warsh_count,
  4103. BloodAccessPartId: blood_access_part_id,
  4104. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4105. Dialyzate: dialyzate,
  4106. DialysisDialyszersId: dialysis_dialyszers_id,
  4107. DialysisIrrigationId: dialysis_irrigation_id,
  4108. DialysisStrainerId: dialysis_strainer_id,
  4109. FirstSuper: fisrt_sup,
  4110. IsSequential: is_sequen,
  4111. Conduct: conduct,
  4112. }
  4113. //针对河间咸的
  4114. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4115. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4116. solution.DisplaceLiquiPart = 0
  4117. solution.DisplaceLiquiValue = 0
  4118. }
  4119. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4120. prescription.DisplaceLiquiPart = 0
  4121. prescription.DisplaceLiquiValue = 0
  4122. }
  4123. }
  4124. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4125. if solution.PrescribingNumber == 0 {
  4126. solution.PrescribingNumber = 1
  4127. }
  4128. if prescription.PrescribingNumber == 0 {
  4129. prescription.PrescribingNumber = 1
  4130. }
  4131. if solution.PrescribingNumber == 0 && id == 14682 {
  4132. solution.PrescribingNumber = 2
  4133. }
  4134. if solution.PrescribingNumber == 0 && id == 18560 {
  4135. solution.PrescribingNumber = 2
  4136. }
  4137. if prescription.PrescribingNumber == 0 && id == 14682 {
  4138. prescription.PrescribingNumber = 2
  4139. }
  4140. if prescription.PrescribingNumber == 0 && id == 18560 {
  4141. prescription.PrescribingNumber = 2
  4142. }
  4143. }
  4144. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4145. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  4146. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4147. if len(monitorList) > 0 {
  4148. var ultrafiltration_rate float64
  4149. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4150. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4151. var replacement_rate float64
  4152. //乘10 除10是为了保留一位小数
  4153. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4154. var firstOpeateTime = monitorList[0].OperateTime
  4155. for _, item := range monitorList {
  4156. //超滤率
  4157. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4158. //置换率
  4159. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4160. //超滤量
  4161. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4162. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4163. //置换量
  4164. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4165. fmt.Println("displacement_quantity----------------------", displacement_quantity)
  4166. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4167. }
  4168. }
  4169. }
  4170. //记录日志
  4171. byterequest, _ := json.Marshal(prescription)
  4172. prescriptionLog := models.XtDialysisPrescriptionLog{
  4173. UserOrgId: prescription.UserOrgId,
  4174. Ctime: time.Now().Unix(),
  4175. Mtime: 0,
  4176. ErrLog: string(byterequest),
  4177. AdminUserId: adminUserInfo.AdminUser.Id,
  4178. RecordDate: prescription.RecordDate,
  4179. PatientId: prescription.PatientId,
  4180. Source: "手机端新增长期处方",
  4181. Status: 1,
  4182. }
  4183. service.CreatePrescriptionLog(prescriptionLog)
  4184. finish := models.XtDialysisFinish{
  4185. IsFinish: 1,
  4186. UserOrgId: adminUserInfo.Org.Id,
  4187. Status: 1,
  4188. Ctime: time.Now().Unix(),
  4189. Mtime: 0,
  4190. Module: 1,
  4191. RecordDate: recordDate.Unix(),
  4192. Sourse: 1,
  4193. PatientId: id,
  4194. }
  4195. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4196. if dialysisFinish.ID == 0 {
  4197. service.CreateDialysisFinish(finish)
  4198. }
  4199. //获取最新1条
  4200. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4201. //更新状态
  4202. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4203. //长沙南雅医院,自动生成抗凝剂的临时处方
  4204. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4205. if prescribing_number == 0 {
  4206. prescribing_number = 1
  4207. }
  4208. advice := models.DoctorAdvice{
  4209. UserOrgId: adminUserInfo.Org.Id,
  4210. PatientId: id,
  4211. GroupNo: 0,
  4212. AdviceType: 2,
  4213. RecordDate: recordDate.Unix(),
  4214. AdviceDate: recordDate.Unix(),
  4215. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4216. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4217. AdviceDesc: "",
  4218. ReminderDate: 0,
  4219. SingleDose: prescription.AnticoagulantZongliang,
  4220. SingleDoseUnit: "iu",
  4221. DrugSpec: 0,
  4222. DrugSpecUnit: "",
  4223. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4224. PrescribingNumberUnit: "支",
  4225. DeliveryWay: "静脉注射",
  4226. ExecutionFrequency: "上机前",
  4227. AdviceDoctor: 0,
  4228. Status: 1,
  4229. CreatedTime: time.Now().Unix(),
  4230. UpdatedTime: time.Now().Unix(),
  4231. IsPrescription: 1,
  4232. ExecutionState: 2,
  4233. StopState: 2,
  4234. IsSettle: 2,
  4235. }
  4236. // 查询排班信息
  4237. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4238. if schedulePatient.ID > 0 {
  4239. if schedulePatient.ScheduleType == 1 {
  4240. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4241. }
  4242. if schedulePatient.ScheduleType == 2 {
  4243. advice.StartTime = recordDate.Unix() + 9*60*60
  4244. }
  4245. }
  4246. // 抗凝剂名称
  4247. switch anticoagulant {
  4248. case 1:
  4249. advice.AdviceName = "无肝素"
  4250. break
  4251. case 2:
  4252. advice.AdviceName = "普通肝素"
  4253. break
  4254. case 3:
  4255. advice.AdviceName = "低分子肝素"
  4256. break
  4257. case 4:
  4258. advice.AdviceName = "阿加曲班"
  4259. break
  4260. case 5:
  4261. advice.AdviceName = "枸橼酸钠"
  4262. break
  4263. case 6:
  4264. advice.AdviceName = "低分子肝素钙"
  4265. break
  4266. case 7:
  4267. advice.AdviceName = "低分子肝素钠"
  4268. break
  4269. case 8:
  4270. advice.AdviceName = "依诺肝素"
  4271. break
  4272. case 9:
  4273. advice.AdviceName = "达肝素"
  4274. break
  4275. case 10:
  4276. advice.AdviceName = "体外抗凝"
  4277. break
  4278. case 11:
  4279. advice.AdviceName = "那曲肝素"
  4280. break
  4281. case 12:
  4282. advice.AdviceName = "无抗凝剂"
  4283. break
  4284. }
  4285. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4286. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4287. advice.AdviceDoctor = appRole.AdminUserId
  4288. }
  4289. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4290. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4291. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4292. advice.AdviceName = "低分子肝素钠注射液"
  4293. // 修改患者临时医嘱里的抗凝剂医嘱
  4294. advice.ID = advicePrescription.ID
  4295. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4296. } else {
  4297. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4298. advice.AdviceName = "低分子肝素钠注射液"
  4299. service.CreateDoctorAdvice(&advice)
  4300. }
  4301. }
  4302. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4303. redis := service.RedisClient()
  4304. defer redis.Close()
  4305. //清空key 值
  4306. redis.Set(key, "", time.Second)
  4307. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4308. redis.Set(keyOne, "", time.Second)
  4309. }
  4310. //获取key,清空redis
  4311. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4312. redis := service.RedisClient()
  4313. defer redis.Close()
  4314. //清空key 值
  4315. redis.Set(key, "", time.Second)
  4316. //清空长期医嘱的key
  4317. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4318. redis.Set(soulution_key, "", time.Second)
  4319. //查询最近透析准备表里是否存在 透析器 灌流器
  4320. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4321. redis.Set(keyOne, "", time.Second)
  4322. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4323. redis.Set(keyTwo, "", time.Second)
  4324. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4325. redis.Set(keyThree, "", time.Second)
  4326. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4327. redis.Set(keyFour, "", time.Second)
  4328. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4329. //
  4330. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4331. //
  4332. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4333. //if len(mation)>0{
  4334. // for _, item := range splitStr {
  4335. // for _,it := range mation{
  4336. // if(item == it.SpecificationName){
  4337. //
  4338. // //查询最近一次的透析器
  4339. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4340. //
  4341. // if errcode == gorm.ErrRecordNotFound{
  4342. // //插入数据
  4343. // prepare := models.DialysisBeforePrepare{
  4344. // UserOrgId: adminUserInfo.Org.Id,
  4345. // PatientId: id,
  4346. // RecordDate: recordDate.Unix(),
  4347. // GoodTypeId: it.GoodTypeId,
  4348. // GoodId: it.ID,
  4349. // Count: 1,
  4350. // Ctime: time.Now().Unix(),
  4351. // Creater: adminUserInfo.AdminUser.Id,
  4352. // Status:1,
  4353. //
  4354. // }
  4355. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4356. // fmt.Println("",errcode)
  4357. // }
  4358. // }
  4359. // }
  4360. //
  4361. // }
  4362. //
  4363. // for _, item := range splitIrrigation {
  4364. // for _,it := range mation{
  4365. // if(item == it.SpecificationName){
  4366. // //查询最近一次的透析器
  4367. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4368. // if errcode == gorm.ErrRecordNotFound{
  4369. // //插入数据
  4370. // prepare := models.DialysisBeforePrepare{
  4371. // UserOrgId: adminUserInfo.Org.Id,
  4372. // PatientId: id,
  4373. // RecordDate: recordDate.Unix(),
  4374. // GoodTypeId: it.GoodTypeId,
  4375. // GoodId: it.ID,
  4376. // Count: 1,
  4377. // Ctime: time.Now().Unix(),
  4378. // Creater: adminUserInfo.AdminUser.Id,
  4379. // Status:1,
  4380. //
  4381. // }
  4382. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4383. // fmt.Println(errcode)
  4384. // }
  4385. // }
  4386. // }
  4387. // }
  4388. //}
  4389. c.ServeSuccessJSON(map[string]interface{}{
  4390. "solution": &solution,
  4391. "prescription": &prescription,
  4392. })
  4393. }
  4394. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4395. patient, _ := c.GetInt64("patient", 0)
  4396. adminUserInfo := c.GetMobileAdminUserInfo()
  4397. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4398. c.ServeSuccessJSON(map[string]interface{}{
  4399. "receiveTreatmentAsses": receiveTreatmentAsses,
  4400. })
  4401. }
  4402. func (this *DialysisAPIController) PostSignInfo() {
  4403. patientID, _ := this.GetInt64("patient_id")
  4404. recordDateStr := this.GetString("date")
  4405. if patientID <= 0 {
  4406. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4407. return
  4408. }
  4409. if len(recordDateStr) == 0 {
  4410. recordDateStr = time.Now().Format("2006-01-02")
  4411. }
  4412. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4413. if parseDateErr != nil {
  4414. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4415. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4416. return
  4417. }
  4418. adminInfo := this.GetMobileAdminUserInfo()
  4419. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4420. if err != nil {
  4421. this.ErrorLog("签名失败:%v", err)
  4422. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4423. return
  4424. }
  4425. this.ServeSuccessJSON(map[string]interface{}{
  4426. "doctor_id": adminInfo.AdminUser.Id,
  4427. })
  4428. }
  4429. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4430. patientID, _ := this.GetInt64("patient_id")
  4431. adminInfo := this.GetMobileAdminUserInfo()
  4432. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4433. this.ServeSuccessJSON(map[string]interface{}{
  4434. "monitor": record,
  4435. })
  4436. }
  4437. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4438. thisTime := time.Now()
  4439. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4440. timeLayout := "2006-01-02 15:04:05"
  4441. loc, _ := time.LoadLocation("Local")
  4442. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4443. theAssessmentDateTime := theStartTime.Unix()
  4444. patientID, _ := this.GetInt64("patient_id")
  4445. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4446. adminInfo := this.GetMobileAdminUserInfo()
  4447. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4448. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4449. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4450. var ultrafiltration_rate float64
  4451. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4452. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4453. fmt.Println(evaluation)
  4454. fmt.Println("prescription.ID", prescription.ID)
  4455. if prescription.ID > 0 {
  4456. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4457. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4458. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4459. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4460. record.UltrafiltrationRate = ultrafiltration_rate
  4461. }
  4462. //重庆塘坝卫生院
  4463. if adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10745 {
  4464. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4465. record.UltrafiltrationRate = ultrafiltration_rate
  4466. }
  4467. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4468. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4469. record.UltrafiltrationRate = ultrafiltration_rate
  4470. }
  4471. if adminInfo.Org.Id == 10510 {
  4472. record.UltrafiltrationRate = 0
  4473. }
  4474. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4475. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4476. record.UltrafiltrationRate = ultrafiltration_rate
  4477. }
  4478. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4479. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4480. record.UltrafiltrationRate = ultrafiltration_rate
  4481. }
  4482. // 只针对方济医院
  4483. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4484. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4485. ultrafiltration_rate = value
  4486. record.UltrafiltrationRate = ultrafiltration_rate
  4487. }
  4488. if template.TemplateId == 41 || template.TemplateId == 47 {
  4489. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4490. record.UltrafiltrationRate = ultrafiltration_rate
  4491. }
  4492. if template.TemplateId == 43 {
  4493. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4494. record.UltrafiltrationRate = ultrafiltration_rate
  4495. }
  4496. if template.TemplateId == 46 || template.TemplateId == 54 {
  4497. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4498. record.UltrafiltrationRate = ultrafiltration_rate
  4499. }
  4500. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 {
  4501. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4502. record.UltrafiltrationRate = ultrafiltration_rate
  4503. }
  4504. if adminInfo.Org.Id == 10469 {
  4505. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4506. record.UltrafiltrationRate = ultrafiltration_rate
  4507. }
  4508. if adminInfo.Org.Id == 10667 {
  4509. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4510. record.UltrafiltrationRate = ultrafiltration_rate
  4511. }
  4512. if adminInfo.Org.Id == 10471 {
  4513. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4514. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4515. }
  4516. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4517. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4518. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4519. }
  4520. if adminInfo.Org.Id == 10751 {
  4521. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4522. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4523. }
  4524. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4525. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4526. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4527. }
  4528. if adminInfo.Org.Id == 10721 {
  4529. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4530. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4531. }
  4532. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4533. record.UltrafiltrationRate = 0
  4534. }
  4535. if adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10731 {
  4536. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4537. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4538. }
  4539. if adminInfo.Org.Id == 10206 {
  4540. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4541. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4542. }
  4543. //if template.TemplateId == 47 {
  4544. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4545. // record.UltrafiltrationRate = ultrafiltration_rate
  4546. //}
  4547. }
  4548. }
  4549. // record.UltrafiltrationRate = ultrafiltration_rate
  4550. record.UltrafiltrationVolume = 0
  4551. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 { //adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535
  4552. if ultrafiltration_rate > 0 {
  4553. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4554. record.UltrafiltrationVolume = value
  4555. }
  4556. }
  4557. if template.TemplateId == 6 || template.TemplateId == 65 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 || adminInfo.Org.Id == 10599 { //adminInfo.Org.Id == 9538
  4558. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4559. if adminInfo.Org.Id != 10735 {
  4560. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4561. record.UltrafiltrationVolume = ultrafiltration_volume
  4562. }
  4563. //胶州少海医院
  4564. if adminInfo.Org.Id == 10735 {
  4565. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4566. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4567. var ultrafiltration_rate_one = math.Floor(prescription.TargetUltrafiltration*1000/float64(totalMin)*60*1000) / 1000
  4568. if lastMonitorRecordList.ID > 0 {
  4569. record.UltrafiltrationRate = ultrafiltration_rate_one
  4570. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4571. record.UltrafiltrationVolume = ultrafiltration_volume
  4572. } else {
  4573. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4574. record.UltrafiltrationVolume = ultrafiltration_volume
  4575. }
  4576. }
  4577. }
  4578. }
  4579. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4580. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4581. record.UltrafiltrationVolume = ultrafiltration_volume
  4582. }
  4583. //长沙南雅
  4584. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 || adminInfo.Org.Id == 10667 {
  4585. if ultrafiltration_rate > 0 {
  4586. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4587. record.UltrafiltrationVolume = ultrafiltration_volume
  4588. }
  4589. }
  4590. if adminInfo.Org.Id == 10471 {
  4591. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4592. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4593. }
  4594. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4595. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4596. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4597. }
  4598. if adminInfo.Org.Id == 10751 {
  4599. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4600. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4601. }
  4602. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4603. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4604. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4605. }
  4606. //长沙南雅累计血容量自动计算
  4607. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4608. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4609. //}
  4610. if template.TemplateId == 47 || template.TemplateId == 54 {
  4611. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4612. }
  4613. if adminInfo.Org.Id == 10510 {
  4614. record.UltrafiltrationVolume = 0
  4615. }
  4616. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10731 {
  4617. if ultrafiltration_rate > 0 {
  4618. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4619. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4620. }
  4621. }
  4622. //古镇乐生
  4623. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4624. if ultrafiltration_rate > 0 {
  4625. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4626. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4627. }
  4628. }
  4629. if adminInfo.Org.Id == 10206 {
  4630. if ultrafiltration_rate > 0 {
  4631. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4632. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4633. }
  4634. }
  4635. if adminInfo.Org.Id == 10721 {
  4636. var replacement_rate float64
  4637. var displacement_quantity float64
  4638. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4639. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  4640. record.ReplacementRate = replacement_rate
  4641. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4642. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4643. record.DisplacementQuantity = displacement_quantity
  4644. }
  4645. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 {
  4646. var replacement_rate float64
  4647. var displacement_quantity float64
  4648. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4649. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  4650. record.ReplacementRate = replacement_rate
  4651. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4652. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4653. record.DisplacementQuantity = displacement_quantity
  4654. }
  4655. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 {
  4656. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4657. record.UltrafiltrationVolume = ultrafiltration_volume
  4658. }
  4659. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4660. var replacement_rate float64
  4661. var displacement_quantity float64
  4662. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4663. if totalMin == 0 {
  4664. totalMin = 240
  4665. }
  4666. if prescription.DisplaceLiquiValue == 0 {
  4667. prescription.ReplacementTotal = 32
  4668. }
  4669. //乘10 除10是为了保留一位小数
  4670. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4671. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4672. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4673. record.DisplacementQuantity = displacement_quantity
  4674. }
  4675. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4676. this.ServeSuccessJSON(map[string]interface{}{
  4677. "monitor": record,
  4678. "lastMonitorRecordList": lastMonitorRecordList,
  4679. })
  4680. }
  4681. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4682. record_id, _ := this.GetInt64("id")
  4683. nurseID, _ := this.GetInt64("start_nurse")
  4684. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4685. bedID, _ := this.GetInt64("bed")
  4686. start_time := this.GetString("start_time")
  4687. schedual_type, _ := this.GetInt64("schedual_type")
  4688. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4689. change_nurse, _ := this.GetInt64("change_nurse")
  4690. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4691. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4692. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4693. patient_id, _ := this.GetInt64("patient_id")
  4694. record_date, _ := this.GetInt64("record_date")
  4695. puncture_needle := this.GetString("puncture_needle")
  4696. puncture_way := this.GetString("puncture_way")
  4697. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4698. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4699. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4700. nuclein_date_str := this.GetString("nuclein_date_str")
  4701. order_remark := this.GetString("order_remark")
  4702. schedule_remark := this.GetString("schedule_remark")
  4703. catheter_operation := this.GetString("catheter_operation")
  4704. blood_flow_volume := this.GetString("blood_flow_volume")
  4705. blood_drawing, _ := this.GetInt64("blood_drawing")
  4706. dialysis_strainer := this.GetString("dialysis_strainer")
  4707. if record_id == 0 {
  4708. this.ErrorLog("id:%v", record_id)
  4709. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4710. return
  4711. }
  4712. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4713. if parseStartDateErr != nil {
  4714. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4715. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4716. return
  4717. }
  4718. adminUserInfo := this.GetMobileAdminUserInfo()
  4719. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4720. if getNurseErr != nil {
  4721. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4722. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4723. return
  4724. } else if nurse == nil {
  4725. this.ErrorLog("护士不存在")
  4726. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4727. return
  4728. }
  4729. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4730. //if getNurseErr != nil {
  4731. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4732. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4733. // return
  4734. //} else if nurse == nil {
  4735. // this.ErrorLog("护士不存在")
  4736. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4737. // return
  4738. //}
  4739. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4740. if getDeviceNumberErr != nil {
  4741. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4742. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4743. return
  4744. } else if deviceNumber == nil {
  4745. this.ErrorLog("床位号不存在")
  4746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4747. return
  4748. }
  4749. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4750. //
  4751. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4752. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4753. // if getPermissionErr != nil {
  4754. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4755. // return
  4756. // } else if headNursePermission == nil {
  4757. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4758. // return
  4759. // }
  4760. //}
  4761. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4762. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4763. timeLayout := "2006-01-02 15:04:05"
  4764. loc, _ := time.LoadLocation("Local")
  4765. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4766. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4767. schedulestartTime := theStartTime.Unix()
  4768. scheduleendTime := theEndTime.Unix()
  4769. var theNucleinDate int64
  4770. timeLayoutOne := "2006-01-02"
  4771. if len(nuclein_date_str) > 0 {
  4772. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4773. if err != nil {
  4774. utils.ErrorLog(err.Error())
  4775. }
  4776. theNucleinDate = theTime.Unix()
  4777. }
  4778. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4779. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4780. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4781. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4782. if err == gorm.ErrRecordNotFound { //空床位
  4783. // 修改了床位逻辑
  4784. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4785. if daySchedule.ID > 0 {
  4786. //daySchedule.BedId = bedID
  4787. //daySchedule.PartitionId = deviceNumber.ZoneID
  4788. //daySchedule.ScheduleType = schedual_type
  4789. //daySchedule.UpdatedTime = time.Now().Unix()
  4790. //err := service.UpdateSchedule(&daySchedule)
  4791. xtSchedule := models.Schedule{
  4792. PartitionId: deviceNumber.ZoneID,
  4793. BedId: bedID,
  4794. ScheduleType: schedual_type,
  4795. UpdatedTime: time.Now().Unix(),
  4796. }
  4797. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4798. if err != nil {
  4799. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4800. return
  4801. }
  4802. }
  4803. } else if err == nil {
  4804. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4805. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4806. if daySchedule.ID > 0 {
  4807. //daySchedule.BedId = bedID
  4808. //daySchedule.PartitionId = deviceNumber.ZoneID
  4809. //
  4810. //daySchedule.ScheduleType = schedual_type
  4811. //daySchedule.UpdatedTime = time.Now().Unix()
  4812. //err := service.UpdateSchedule(&daySchedule)
  4813. xtSchedule := models.Schedule{
  4814. PartitionId: deviceNumber.ZoneID,
  4815. BedId: bedID,
  4816. ScheduleType: schedual_type,
  4817. UpdatedTime: time.Now().Unix(),
  4818. }
  4819. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4820. if err != nil {
  4821. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4822. return
  4823. }
  4824. }
  4825. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4826. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4827. return
  4828. }
  4829. } else if err != nil {
  4830. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4831. return
  4832. }
  4833. }
  4834. dialysisRecord := &models.DialysisOrder{
  4835. ID: record_id,
  4836. UserOrgId: adminUserInfo.Org.Id,
  4837. BedID: bedID,
  4838. StartNurse: nurseID,
  4839. StartTime: startDate.Unix(),
  4840. PunctureNurse: puncture_nurse,
  4841. Creator: adminUserInfo.AdminUser.Id,
  4842. Modifier: adminUserInfo.AdminUser.Id,
  4843. WashpipeNurse: washpipe_nurse,
  4844. SchedualType: schedual_type,
  4845. ChangeNurse: change_nurse,
  4846. DifficultPunctureNurse: difficult_puncture_nurse,
  4847. NewFistulaNurse: new_fistula_nurse,
  4848. QualityNurseId: quality_nurse_id,
  4849. PunctureNeedle: puncture_needle,
  4850. PunctureWay: puncture_way,
  4851. DialysisDialyszers: dialysis_dialyszers,
  4852. DialysisIrrigation: dialysis_irrigation,
  4853. BloodAccessId: blood_access_id,
  4854. NucleinDate: theNucleinDate,
  4855. OrderRemark: order_remark,
  4856. ScheduleRemark: schedule_remark,
  4857. CatheterOperation: catheter_operation,
  4858. BloodFlowVolume: blood_flow_volume,
  4859. BloodDrawing: blood_drawing,
  4860. DialysisStrainer: dialysis_strainer,
  4861. }
  4862. //修改床位号需要重新消毒
  4863. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4864. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4865. //查询第一条监测
  4866. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4867. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4868. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4869. redis := service.RedisClient()
  4870. //清空key 值
  4871. redis.Set(key, "", time.Second)
  4872. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4873. redis.Set(keyOne, "", time.Second)
  4874. defer redis.Close()
  4875. }
  4876. // 查询信息规挡的设置天数
  4877. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4878. if infor.ID > 0 && infor.WeekDay > 0 {
  4879. var cha_time int64
  4880. timeNowStr := time.Now().Format("2006-01-02")
  4881. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4882. //今日的日期减去设置的日期
  4883. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4884. if cha_time >= record_date {
  4885. //查询审核是否允许
  4886. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4887. //申请状态不允许的情况 拒绝修改
  4888. if infor.ApplicationStatus != 1 {
  4889. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4890. return
  4891. }
  4892. }
  4893. }
  4894. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4895. //修改床位后重新生成消毒计划
  4896. if adminUserInfo.Org.Id == 10340 {
  4897. //根据床位号获取设备型号
  4898. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4899. //查询使用消毒最后一条消毒记录
  4900. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4901. fmt.Println("err", err)
  4902. if err == gorm.ErrRecordNotFound {
  4903. //查找排班
  4904. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4905. //查询改设备是否有消毒计划
  4906. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4907. //根据床位号获取设备id
  4908. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4909. //查询病人信息
  4910. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4911. var con = ""
  4912. if patients.IsInfectious == 0 {
  4913. con = ""
  4914. }
  4915. if patients.IsInfectious == 1 {
  4916. con = "无"
  4917. }
  4918. if patients.IsInfectious == 2 {
  4919. con = "有"
  4920. }
  4921. if errcode == nil {
  4922. var end_time int64
  4923. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4924. //新增消毒
  4925. information := models.DeviceInformation{
  4926. Date: dialysisRecord.DialysisDate,
  4927. Zone: dialysisRecord.ZoneId,
  4928. Class: dialysisRecord.SchedualType,
  4929. BedNumber: dialysisRecord.BedID,
  4930. PatientId: dialysisRecord.PatientId,
  4931. DialysisMode: scheduleByPatient.ModeId,
  4932. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4933. Disinfection: 1,
  4934. DialysisConcentration: 1,
  4935. DisinfectionStatus: 1,
  4936. Move: 1,
  4937. UserOrgId: dialysisRecord.UserOrgId,
  4938. DisinfectType: plan.Way,
  4939. DisinfectantType: plan.MachineDisinfectant,
  4940. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4941. Disinfectant: plan.Disinfectant,
  4942. Ctime: time.Now().Unix(),
  4943. Status: 1,
  4944. SignName: nurseID,
  4945. EquimentId: addmacher.ID,
  4946. DisinfectionResidue: 2,
  4947. Bed: addmacher.BedNumber,
  4948. StartTime: dialysisRecord.StartTime,
  4949. EndTime: dialysisRecord.EndTime,
  4950. Contagion: con,
  4951. WeightLoss: 0,
  4952. Hyperfiltratio: 0,
  4953. DialysisHour: "",
  4954. MachineRun: 1,
  4955. DisinfecStartime: dialysisRecord.EndTime,
  4956. DisinfecEndtime: end_time,
  4957. }
  4958. err := service.CreateInformationTwo(&information)
  4959. fmt.Println("报错", err)
  4960. }
  4961. }
  4962. }
  4963. order, _ := service.GetLastPatientOrder(record_id)
  4964. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4965. redis := service.RedisClient()
  4966. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4967. redis.Set(key, "", time.Second)
  4968. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4969. //清空key 值
  4970. redis.Set(keyOne, "", time.Second)
  4971. scheduleDateStartOne := startDate.Format("2006-01-02")
  4972. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4973. redis.Set(keyTwo, "", time.Second)
  4974. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4975. redis.Set(keyThree, "", time.Second)
  4976. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4977. redis.Set(keyFour, "", time.Second)
  4978. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4979. redis.Set(keyFive, "", time.Second)
  4980. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4981. redis.Set(keySix, "", time.Second)
  4982. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4983. redis.Set(keySeven, "", time.Second)
  4984. if updateErr != nil {
  4985. this.ErrorLog("修改上机失败:%v", updateErr)
  4986. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4987. return
  4988. }
  4989. if updateErr == nil {
  4990. if tempDialysisRecord.Stage == 2 {
  4991. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4992. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4993. fmt.Println(value)
  4994. a, b := math.Modf(value)
  4995. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4996. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4997. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4998. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4999. redis := service.RedisClient()
  5000. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  5001. redis.Set(key, "", time.Second)
  5002. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  5003. redis.Set(keyOne, "", time.Second)
  5004. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5005. //清空key 值
  5006. redis.Set(keySix, "", time.Second)
  5007. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5008. redis.Set(keySeven, "", time.Second)
  5009. redis.Close()
  5010. if updateAssessmentErr != nil {
  5011. utils.ErrorLog("%v", updateAssessmentErr)
  5012. }
  5013. }
  5014. }
  5015. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5016. this.ServeSuccessJSON(map[string]interface{}{
  5017. "dialysis_order": dialysisRecords,
  5018. })
  5019. }
  5020. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  5021. record_id, _ := c.GetInt64("id")
  5022. nurseID, _ := c.GetInt64("nurse")
  5023. end_time := c.GetString("end_time")
  5024. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  5025. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  5026. catheter := c.GetString("catheter")
  5027. cruor := c.GetString("cruor")
  5028. mission := c.GetString("mission")
  5029. condenser := c.GetString("condenser")
  5030. if record_id <= 0 || nurseID <= 0 {
  5031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5032. return
  5033. }
  5034. adminUserInfo := c.GetMobileAdminUserInfo()
  5035. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5036. if getNurseErr != nil {
  5037. c.ErrorLog("获取护士失败:%v", getNurseErr)
  5038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5039. return
  5040. } else if nurse == nil {
  5041. c.ErrorLog("护士不存在")
  5042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5043. return
  5044. }
  5045. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5046. if parseEndDateErr != nil {
  5047. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5049. return
  5050. }
  5051. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5052. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5053. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5054. // if getPermissionErr != nil {
  5055. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5056. // return
  5057. // } else if headNursePermission == nil {
  5058. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5059. // return
  5060. // }
  5061. //}
  5062. // 查询信息规挡的设置天数
  5063. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5064. if infor.ID > 0 {
  5065. var cha_time int64
  5066. timeNowStr := time.Now().Format("2006-01-02")
  5067. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5068. //今日的日期减去设置的日期
  5069. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5070. if cha_time >= tempDialysisRecords.DialysisDate {
  5071. //查询审核是否允许
  5072. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  5073. //申请状态不允许的情况 拒绝修改
  5074. if infor.ApplicationStatus != 1 {
  5075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5076. return
  5077. }
  5078. }
  5079. }
  5080. dialysisRecord := &models.DialysisOrder{
  5081. ID: record_id,
  5082. UserOrgId: adminUserInfo.Org.Id,
  5083. EndTime: endDate.Unix(),
  5084. FinishNurse: nurseID,
  5085. FinishModifier: adminUserInfo.AdminUser.Id,
  5086. PuncturePointHaematoma: puncture_point_haematoma,
  5087. BloodAccessInternalFistula: blood_access_internal_fistula,
  5088. Catheter: catheter,
  5089. Cruor: cruor,
  5090. Mission: mission,
  5091. Condenser: condenser,
  5092. }
  5093. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5094. redis := service.RedisClient()
  5095. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  5096. //清空key 值
  5097. redis.Set(key, "", time.Second)
  5098. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5099. //清空key 值
  5100. redis.Set(keyOne, "", time.Second)
  5101. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5102. redis.Set(keySeven, "", time.Second)
  5103. redis.Close()
  5104. if updateErr != nil {
  5105. c.ErrorLog("修改下机失败:%v", updateErr)
  5106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5107. return
  5108. }
  5109. if updateErr == nil {
  5110. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5111. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5112. a, b := math.Modf(value)
  5113. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5114. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5115. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5116. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5117. redis := service.RedisClient()
  5118. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  5119. redis.Set(keyTen, "", time.Second)
  5120. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  5121. redis.Set(keyTwo, "", time.Second)
  5122. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  5123. redis.Set(key, "", time.Second)
  5124. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5125. redis.Set(keyThree, "", time.Second)
  5126. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5127. redis.Set(keySeven, "", time.Second)
  5128. defer redis.Close()
  5129. if updateAssessmentErr != nil {
  5130. utils.ErrorLog("%v", updateAssessmentErr)
  5131. }
  5132. }
  5133. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5134. c.ServeSuccessJSON(map[string]interface{}{
  5135. "dialysis_order": dialysisRecords,
  5136. })
  5137. }
  5138. func (c *DialysisAPIController) GetLongAdvice() {
  5139. patient_id, _ := c.GetInt64("id")
  5140. adminUserInfo := c.GetMobileAdminUserInfo()
  5141. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5142. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5143. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5144. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5145. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5146. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5147. c.ServeSuccessJSON(map[string]interface{}{
  5148. "status": "1",
  5149. })
  5150. return
  5151. } else { //开启推送提醒
  5152. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5153. var advice_three []*models.DoctorAdvice
  5154. recordDateStr := time.Now().Format("2006-01-02")
  5155. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5156. nowtime := recordDate.Unix()
  5157. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5158. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5159. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5160. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5161. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5162. for _, advice := range advices {
  5163. if advice.FrequencyType == 3 {
  5164. t := time.Now()
  5165. week := int(t.Weekday())
  5166. fmt.Println(t.Weekday())
  5167. fmt.Println(week)
  5168. switch week {
  5169. case 1:
  5170. if strings.Index(advice.WeekDay, "周一") == -1 {
  5171. advice_three = append(advice_three, advice)
  5172. }
  5173. break
  5174. case 2:
  5175. if strings.Index(advice.WeekDay, "周二") == -1 {
  5176. advice_three = append(advice_three, advice)
  5177. }
  5178. break
  5179. case 3:
  5180. if strings.Index(advice.WeekDay, "周三") == -1 {
  5181. advice_three = append(advice_three, advice)
  5182. }
  5183. break
  5184. case 4:
  5185. if strings.Index(advice.WeekDay, "周四") == -1 {
  5186. advice_three = append(advice_three, advice)
  5187. }
  5188. break
  5189. case 5:
  5190. if strings.Index(advice.WeekDay, "周五") == -1 {
  5191. advice_three = append(advice_three, advice)
  5192. }
  5193. break
  5194. case 6:
  5195. if strings.Index(advice.WeekDay, "周六") == -1 {
  5196. advice_three = append(advice_three, advice)
  5197. }
  5198. break
  5199. case 0:
  5200. if strings.Index(advice.WeekDay, "周日") == -1 {
  5201. advice_three = append(advice_three, advice)
  5202. }
  5203. break
  5204. }
  5205. }
  5206. }
  5207. for _, advice := range advices_two {
  5208. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5209. now := p.Unix()
  5210. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5211. dayStr2 := "-" + dayStr
  5212. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5213. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5214. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5215. for _, ad := range advices {
  5216. advice_three = append(advice_three, ad)
  5217. }
  5218. }
  5219. if err == nil {
  5220. c.ServeSuccessJSON(map[string]interface{}{
  5221. "status": "2",
  5222. "advices": advices,
  5223. "advices_two": RemoveRepeatedElement(advice_three),
  5224. "is_open_remind": config.IsOpenRemind,
  5225. "his_config_open": hisConfig.IsOpen,
  5226. "is_advice_open": is_advice_open.IsAdviceOpen,
  5227. "prescription_open": prescription_open.IsOpen,
  5228. })
  5229. }
  5230. }
  5231. }
  5232. func (c *DialysisAPIController) GetLongAdviceOne() {
  5233. patient_id, _ := c.GetInt64("id")
  5234. startTime := c.GetString("schedule_date")
  5235. timeLayout := "2006-01-02"
  5236. loc, _ := time.LoadLocation("Local")
  5237. var theStartTime int64
  5238. if len(startTime) > 0 {
  5239. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5240. if err != nil {
  5241. utils.ErrorLog(err.Error())
  5242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5243. return
  5244. }
  5245. theStartTime = theTime.Unix()
  5246. }
  5247. adminUserInfo := c.GetMobileAdminUserInfo()
  5248. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5249. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5250. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5251. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5252. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5253. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5254. c.ServeSuccessJSON(map[string]interface{}{
  5255. "status": "1",
  5256. })
  5257. return
  5258. } else { //开启推送提醒
  5259. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5260. var advice_three []*models.DoctorAdvice
  5261. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5262. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5263. for _, advice := range advices {
  5264. if advice.FrequencyType == 3 {
  5265. t := time.Now()
  5266. week := int(t.Weekday())
  5267. fmt.Println(t.Weekday())
  5268. fmt.Println(week)
  5269. switch week {
  5270. case 1:
  5271. if strings.Index(advice.WeekDay, "周一") == -1 {
  5272. advice_three = append(advice_three, advice)
  5273. }
  5274. break
  5275. case 2:
  5276. if strings.Index(advice.WeekDay, "周二") == -1 {
  5277. advice_three = append(advice_three, advice)
  5278. }
  5279. break
  5280. case 3:
  5281. if strings.Index(advice.WeekDay, "周三") == -1 {
  5282. advice_three = append(advice_three, advice)
  5283. }
  5284. break
  5285. case 4:
  5286. if strings.Index(advice.WeekDay, "周四") == -1 {
  5287. advice_three = append(advice_three, advice)
  5288. }
  5289. break
  5290. case 5:
  5291. if strings.Index(advice.WeekDay, "周五") == -1 {
  5292. advice_three = append(advice_three, advice)
  5293. }
  5294. break
  5295. case 6:
  5296. if strings.Index(advice.WeekDay, "周六") == -1 {
  5297. advice_three = append(advice_three, advice)
  5298. }
  5299. break
  5300. case 0:
  5301. if strings.Index(advice.WeekDay, "周日") == -1 {
  5302. advice_three = append(advice_three, advice)
  5303. }
  5304. break
  5305. }
  5306. }
  5307. }
  5308. for _, advice := range advices_two {
  5309. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5310. now := p.Unix()
  5311. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5312. dayStr2 := "-" + dayStr
  5313. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5314. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5315. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5316. for _, ad := range advices {
  5317. advice_three = append(advice_three, ad)
  5318. }
  5319. }
  5320. if err == nil {
  5321. c.ServeSuccessJSON(map[string]interface{}{
  5322. "status": "2",
  5323. "advices": advices,
  5324. "advices_two": RemoveRepeatedElement(advice_three),
  5325. "is_open_remind": config.IsOpenRemind,
  5326. "his_config_open": hisConfig.IsOpen,
  5327. "is_advice_open": is_advice_open.IsAdviceOpen,
  5328. "prescription_open": prescription_open.IsOpen,
  5329. })
  5330. }
  5331. }
  5332. }
  5333. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5334. newArr = make([]*models.DoctorAdvice, 0)
  5335. for i := 0; i < len(arr); i++ {
  5336. repeat := false
  5337. for j := i + 1; j < len(arr); j++ {
  5338. if arr[i].ID == arr[j].ID {
  5339. repeat = true
  5340. break
  5341. }
  5342. }
  5343. if !repeat {
  5344. newArr = append(newArr, arr[i])
  5345. }
  5346. }
  5347. return
  5348. }
  5349. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5350. patient, _ := c.GetInt64("id", 0)
  5351. groupNo, _ := c.GetInt64("groupno", 0)
  5352. if patient <= 0 {
  5353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5354. return
  5355. }
  5356. adminUserInfo := c.GetMobileAdminUserInfo()
  5357. dataBody := make(map[string]interface{}, 0)
  5358. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5359. if err != nil {
  5360. utils.ErrorLog(err.Error())
  5361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5362. return
  5363. }
  5364. utils.ErrorLog("%v", dataBody)
  5365. timeLayout := "2006-01-02 15:04"
  5366. loc, _ := time.LoadLocation("Local")
  5367. timeLayout2 := "2006-01-02"
  5368. loc2, _ := time.LoadLocation("Local")
  5369. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5370. utils.ErrorLog("advice_type")
  5371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5372. return
  5373. }
  5374. adviceType := int64(2)
  5375. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5376. utils.ErrorLog("advice_date")
  5377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5378. return
  5379. }
  5380. adviceDate, _ := dataBody["advice_date"].(string)
  5381. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5382. AdviceDate := theTime.Unix()
  5383. RecordDate := theTime.Unix()
  5384. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5385. utils.ErrorLog("start_time")
  5386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5387. return
  5388. }
  5389. startTime, _ := dataBody["start_time"].(string)
  5390. if len(startTime) == 0 {
  5391. utils.ErrorLog("len(start_time) == 0")
  5392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5393. return
  5394. }
  5395. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5396. if err != nil {
  5397. utils.ErrorLog(err.Error())
  5398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5399. return
  5400. }
  5401. StartTime := theTime.Unix()
  5402. Remark := ""
  5403. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5404. remark, _ := dataBody["remark"].(string)
  5405. Remark = remark
  5406. }
  5407. var advices []*models.GroupAdvice
  5408. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5409. utils.ErrorLog("advices")
  5410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5411. return
  5412. }
  5413. adviceNames := dataBody["advices"].([]interface{})
  5414. for _, adviceNameMap := range adviceNames {
  5415. adviceNameM := adviceNameMap.(map[string]interface{})
  5416. var advice models.GroupAdvice
  5417. advice.Remark = Remark
  5418. advice.AdviceType = adviceType
  5419. advice.StartTime = StartTime
  5420. advice.AdviceDate = AdviceDate
  5421. advice.RecordDate = RecordDate
  5422. advice.Status = 1
  5423. advice.CreatedTime = time.Now().Unix()
  5424. advice.UpdatedTime = time.Now().Unix()
  5425. advice.StopState = 2
  5426. advice.ExecutionState = 2
  5427. advice.UserOrgId = adminUserInfo.Org.Id
  5428. advice.PatientId = patient
  5429. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5430. advice.IsSettle = 2
  5431. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5432. utils.ErrorLog("advice_name")
  5433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5434. return
  5435. }
  5436. adviceName, _ := adviceNameM["advice_name"].(string)
  5437. if len(adviceName) == 0 {
  5438. utils.ErrorLog("len(advice_name) == 0")
  5439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5440. return
  5441. }
  5442. advice.AdviceName = adviceName
  5443. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5444. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5445. advice.DrugSpec = drugSpec
  5446. }
  5447. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5448. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5449. advice.AdviceDesc = adviceDesc
  5450. }
  5451. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5452. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5453. advice.DrugSpecUnit = drugSpecUnit
  5454. }
  5455. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5456. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5457. // advice.SingleDose = singleDose
  5458. //}
  5459. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5460. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5461. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5462. }
  5463. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5464. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5465. advice.SingleDoseUnit = singleDoseUnit
  5466. }
  5467. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5468. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5469. // advice.PrescribingNumber = prescribingNumber
  5470. //}
  5471. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5472. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5473. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5474. }
  5475. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5476. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5477. advice.PrescribingNumberUnit = prescribingNumberUnit
  5478. }
  5479. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5480. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5481. advice.DeliveryWay = deliveryWay
  5482. }
  5483. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5484. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5485. advice.ExecutionFrequency = executionFrequency
  5486. }
  5487. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5488. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5489. advice.FrequencyType = frequency_type
  5490. }
  5491. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5492. day_count := int64(adviceNameM["day_count"].(float64))
  5493. advice.DayCount = day_count
  5494. }
  5495. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5496. week_day, _ := adviceNameM["week_day"].(string)
  5497. advice.WeekDay = week_day
  5498. }
  5499. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5500. way := int64(adviceNameM["way"].(float64))
  5501. advice.Way = way
  5502. }
  5503. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5504. drug_id := int64(adviceNameM["drug_id"].(float64))
  5505. advice.DrugId = drug_id
  5506. }
  5507. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5508. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5509. advice.DrugNameId = drug_name_id
  5510. }
  5511. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5512. remark, _ := adviceNameM["remark"].(string)
  5513. advice.Remark = remark
  5514. }
  5515. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5516. groupno := int64(adviceNameM["groupno"].(float64))
  5517. advice.GroupNo = groupno
  5518. }
  5519. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5520. template_id, _ := adviceNameM["template_id"].(string)
  5521. advice.TemplateId = template_id
  5522. }
  5523. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5524. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5525. advice.ExecutionFrequency = executionFrequency
  5526. }
  5527. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5528. children := adviceNameM["child"].([]interface{})
  5529. if len(children) > 0 {
  5530. for _, childrenMap := range children {
  5531. childMap := childrenMap.(map[string]interface{})
  5532. var child models.GroupAdvice
  5533. child.Remark = Remark
  5534. child.AdviceType = adviceType
  5535. child.StartTime = StartTime
  5536. child.AdviceDate = AdviceDate
  5537. child.RecordDate = RecordDate
  5538. child.Status = 1
  5539. child.CreatedTime = time.Now().Unix()
  5540. child.UpdatedTime = time.Now().Unix()
  5541. child.StopState = 2
  5542. child.ExecutionState = 2
  5543. child.UserOrgId = adminUserInfo.Org.Id
  5544. child.PatientId = patient
  5545. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5546. child.IsSettle = 1
  5547. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5548. utils.ErrorLog("child advice_name")
  5549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5550. return
  5551. }
  5552. childAdviceName, _ := childMap["advice_name"].(string)
  5553. if len(childAdviceName) == 0 {
  5554. utils.ErrorLog("len(child advice_name) == 0")
  5555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5556. return
  5557. }
  5558. child.AdviceName = childAdviceName
  5559. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5560. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5561. child.AdviceDesc = childAdviceDesc
  5562. }
  5563. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5564. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5565. child.DrugSpec = childDrugSpec
  5566. }
  5567. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5568. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5569. child.DrugSpecUnit = childDrugSpecUnit
  5570. }
  5571. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5572. child.SingleDose = childMap["single_dose"].(float64)
  5573. }
  5574. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5575. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5576. child.SingleDoseUnit = childSingleDoseUnit
  5577. }
  5578. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5579. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5580. }
  5581. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5582. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5583. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5584. }
  5585. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5586. groupno := int64(childMap["groupno"].(float64))
  5587. advice.GroupNo = groupno
  5588. }
  5589. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5590. remark, _ := childMap["remark"].(string)
  5591. child.Remark = remark
  5592. }
  5593. child.DeliveryWay = advice.DeliveryWay
  5594. child.ExecutionFrequency = advice.ExecutionFrequency
  5595. advice.Children = append(advice.Children, &child)
  5596. }
  5597. }
  5598. }
  5599. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5600. if temp_advice.ID == 0 {
  5601. advices = append(advices, &advice)
  5602. }
  5603. }
  5604. if len(advices) > 0 {
  5605. finish := models.XtDialysisFinish{
  5606. IsFinish: 1,
  5607. UserOrgId: adminUserInfo.Org.Id,
  5608. Status: 1,
  5609. Ctime: time.Now().Unix(),
  5610. Mtime: 0,
  5611. Module: 4,
  5612. RecordDate: AdviceDate,
  5613. Sourse: 1,
  5614. PatientId: patient,
  5615. }
  5616. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5617. if dialysisFinish.ID == 0 {
  5618. service.CreateDialysisFinish(finish)
  5619. }
  5620. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5621. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5622. for _, item := range advices {
  5623. byterequest, _ := json.Marshal(item)
  5624. adviceLog := models.XtDoctorAdviceLog{
  5625. UserOrgId: adminUserInfo.Org.Id,
  5626. PatientId: patient,
  5627. AdminUserId: adminUserInfo.AdminUser.Id,
  5628. Module: 1,
  5629. ErrLog: string(byterequest),
  5630. Status: 1,
  5631. Ctime: time.Now().Unix(),
  5632. Mtime: 0,
  5633. Source: "手机端医嘱推送",
  5634. RecordDate: item.AdviceDate,
  5635. }
  5636. service.CreateDoctorAdviceLog(adviceLog)
  5637. }
  5638. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5639. redis := service.RedisClient()
  5640. //清空key 值
  5641. redis.Set(key, "", time.Second)
  5642. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5643. redis.Set(keyOne, "", time.Second)
  5644. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5645. defer redis.Close()
  5646. redis.Set(keyThree, "", time.Second)
  5647. if err != nil {
  5648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5649. return
  5650. }
  5651. c.ServeSuccessJSON(map[string]interface{}{
  5652. "msg": "ok",
  5653. "advices": list,
  5654. })
  5655. } else {
  5656. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5657. for _, item := range advices {
  5658. byterequest, _ := json.Marshal(item)
  5659. adviceLog := models.XtDoctorAdviceLog{
  5660. UserOrgId: adminUserInfo.Org.Id,
  5661. PatientId: patient,
  5662. AdminUserId: adminUserInfo.AdminUser.Id,
  5663. Module: 1,
  5664. ErrLog: string(byterequest),
  5665. Status: 1,
  5666. Ctime: time.Now().Unix(),
  5667. Mtime: 0,
  5668. Source: "手机端医嘱推送",
  5669. RecordDate: item.AdviceDate,
  5670. }
  5671. service.CreateDoctorAdviceLog(adviceLog)
  5672. }
  5673. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5674. redis := service.RedisClient()
  5675. //清空key 值
  5676. redis.Set(key, "", time.Second)
  5677. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5678. redis.Set(keyOne, "", time.Second)
  5679. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5680. defer redis.Close()
  5681. redis.Set(keyThree, "", time.Second)
  5682. if err != nil {
  5683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5684. return
  5685. }
  5686. c.ServeSuccessJSON(map[string]interface{}{
  5687. "msg": "ok",
  5688. "advices": list,
  5689. })
  5690. }
  5691. } else {
  5692. c.ServeSuccessJSON(map[string]interface{}{
  5693. "msg": "ok",
  5694. })
  5695. }
  5696. return
  5697. }
  5698. func (c *DialysisAPIController) UploadDryWeight() {
  5699. patient_id, _ := c.GetInt64("id")
  5700. dry_weight, _ := c.GetFloat("dry_weight")
  5701. doctor_id, _ := c.GetInt64("doctor_id")
  5702. remark := c.GetString("remark")
  5703. adminUserInfo := c.GetMobileAdminUserInfo()
  5704. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5705. if err == gorm.ErrRecordNotFound {
  5706. dryWeight := &models.SgjPatientDryweight{
  5707. PatientId: patient_id,
  5708. DryWeight: dry_weight,
  5709. Remakes: remark,
  5710. Ctime: time.Now().Unix(),
  5711. Mtime: time.Now().Unix(),
  5712. Creator: doctor_id,
  5713. Status: 1,
  5714. UserOrgId: adminUserInfo.Org.Id,
  5715. AdjustedValue: "/",
  5716. UserId: adminUserInfo.AdminUser.Id,
  5717. }
  5718. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5719. redis := service.RedisClient()
  5720. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5721. redis.Set(keyOne, "", time.Second)
  5722. loc, _ := time.LoadLocation("Local")
  5723. nowTime := time.Now()
  5724. nowDay := nowTime.Format("2006-01-02")
  5725. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5726. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5727. redis.Set(key, "", time.Second)
  5728. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5729. redis.Set(keyTwo, "", time.Second)
  5730. redis.Close()
  5731. if createErr == nil {
  5732. c.ServeSuccessJSON(map[string]interface{}{
  5733. "msg": "提交成功",
  5734. "weight": dryWeight,
  5735. })
  5736. }
  5737. } else {
  5738. dryWeight := &models.SgjPatientDryweight{
  5739. PatientId: patient_id,
  5740. DryWeight: dry_weight,
  5741. Remakes: remark,
  5742. Ctime: time.Now().Unix(),
  5743. Mtime: time.Now().Unix(),
  5744. Creator: doctor_id,
  5745. Status: 1,
  5746. UserOrgId: adminUserInfo.Org.Id,
  5747. AdjustedValue: "/",
  5748. UserId: adminUserInfo.AdminUser.Id,
  5749. }
  5750. var value float64
  5751. value = dry_weight - weightAdjust.DryWeight
  5752. if value < 0 {
  5753. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5754. } else if value == 0 {
  5755. dryWeight.AdjustedValue = "/"
  5756. } else if value > 0 {
  5757. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5758. }
  5759. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5760. //康桥
  5761. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  5762. timeNowStr := time.Now().Format("2006-01-02")
  5763. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5764. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5765. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5766. if beforAssesment.ID > 0 {
  5767. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5768. var dewater_amount float64
  5769. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5770. if adminUserInfo.Org.Id != 10702 {
  5771. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5772. }
  5773. if adminUserInfo.Org.Id == 10702 {
  5774. service.UpdatePatientDialysisPrscriptionOne(dialysisPrescription.ID, dewater_amount)
  5775. }
  5776. //获取key,清空redis
  5777. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5778. redis := service.RedisClient()
  5779. //清空key 值
  5780. redis.Set(key, "", time.Second)
  5781. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5782. //清空key 值
  5783. redis.Set(keyOne, "", time.Second)
  5784. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5785. //清空key 值
  5786. redis.Set(keyTwo, "", time.Second)
  5787. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5788. redis.Set(keySix, "", time.Second)
  5789. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5790. redis.Set(keySeven, "", time.Second)
  5791. }
  5792. }
  5793. redis := service.RedisClient()
  5794. loc, _ := time.LoadLocation("Local")
  5795. nowTime := time.Now()
  5796. nowDay := nowTime.Format("2006-01-02")
  5797. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5798. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5799. redis.Set(keyOne, "", time.Second)
  5800. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5801. redis.Set(key, "", time.Second)
  5802. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5803. redis.Set(keyTwo, "", time.Second)
  5804. redis.Close()
  5805. if createErr == nil {
  5806. c.ServeSuccessJSON(map[string]interface{}{
  5807. "msg": "提交成功",
  5808. "weight": dryWeight,
  5809. })
  5810. }
  5811. }
  5812. }
  5813. func (c *DialysisAPIController) GetSolution() {
  5814. patient_id, _ := c.GetInt64("patient_id")
  5815. mode_id, _ := c.GetInt64("mode_id")
  5816. adminUserInfo := c.GetMobileAdminUserInfo()
  5817. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5818. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5819. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5820. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5821. if err != nil {
  5822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5823. return
  5824. }
  5825. c.ServeSuccessJSON(map[string]interface{}{
  5826. "solution": solution,
  5827. "prescription": prescription,
  5828. "system_prescription": system_prescription,
  5829. "dialysisPrescription": dialysisPrescription,
  5830. })
  5831. }
  5832. func (c *DialysisAPIController) GetSchedule() {
  5833. schedual_type, _ := c.GetInt64("schedual_type")
  5834. adminUserInfo := c.GetMobileAdminUserInfo()
  5835. scheduleTime, _ := c.GetInt64("record_date")
  5836. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5837. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5838. c.ServeSuccessJSON(map[string]interface{}{
  5839. "number": deviceNumber,
  5840. "list": list,
  5841. })
  5842. }
  5843. func (c *DialysisAPIController) GetPatientId() {
  5844. id, _ := c.GetInt64("id")
  5845. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5846. patientId, _ := service.GetPatientId(id)
  5847. //获取该患者的所有传染病
  5848. list, _ := service.GetPatientInfectious(id)
  5849. c.ServeSuccessJSON(map[string]interface{}{
  5850. "patient": patientId,
  5851. "infectioulist": list,
  5852. })
  5853. }
  5854. func (this *DialysisAPIController) GetDialysisSchedule() {
  5855. schedualDate := this.GetString("date")
  5856. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5857. if parseDateErr != nil {
  5858. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5859. return
  5860. }
  5861. adminInfo := this.GetMobileAdminUserInfo()
  5862. orgID := adminInfo.Org.Id
  5863. redis := service.RedisClient()
  5864. defer redis.Close()
  5865. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5866. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5867. if len(scheduals) > 0 {
  5868. //缓存数据
  5869. scheduals_json, err := json.Marshal(scheduals)
  5870. if err == nil {
  5871. redis.Set(key, scheduals_json, time.Second*30)
  5872. }
  5873. }
  5874. this.ServeSuccessJSON(map[string]interface{}{
  5875. "scheduals": scheduals,
  5876. })
  5877. }
  5878. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5879. change_type, _ := this.GetInt64("type", 0)
  5880. record_date := this.GetString("record_time")
  5881. patient_id, _ := this.GetInt64("patient_id", 0)
  5882. timeLayout := "2006-01-02"
  5883. loc, _ := time.LoadLocation("Local")
  5884. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5885. record_time := theAdviceRecordTime.Unix()
  5886. adminUserInfo := this.GetMobileAdminUserInfo()
  5887. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5888. if err == nil {
  5889. if len(advices) == 0 {
  5890. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5891. return
  5892. } else {
  5893. this.ServeSuccessJSON(map[string]interface{}{
  5894. "advices": advices,
  5895. "schedule": sch,
  5896. })
  5897. return
  5898. }
  5899. } else {
  5900. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5901. return
  5902. }
  5903. }
  5904. func (c *DialysisAPIController) CreateConsumables() {
  5905. record_date := c.GetString("record_time")
  5906. patient_id, _ := c.GetInt64("patient_id", 0)
  5907. active, _ := c.GetInt64("active")
  5908. adminUser := c.GetMobileAdminUserInfo()
  5909. timeLayout := "2006-01-02"
  5910. loc, _ := time.LoadLocation("Local")
  5911. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5912. record_time := theRecordTime.Unix()
  5913. // 查询信息规挡的设置天数
  5914. orgid := c.GetMobileAdminUserInfo().Org.Id
  5915. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5916. if infor.ID > 0 {
  5917. var cha_time int64
  5918. timeNowStr := time.Now().Format("2006-01-02")
  5919. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5920. //今日的日期减去设置的日期
  5921. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5922. if cha_time >= record_time {
  5923. //查询审核是否允许
  5924. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5925. //申请状态不允许的情况 拒绝修改
  5926. if infor.ApplicationStatus != 1 {
  5927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5928. return
  5929. }
  5930. }
  5931. }
  5932. dataBody := make(map[string]interface{}, 0)
  5933. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5934. if err != nil {
  5935. utils.ErrorLog(err.Error())
  5936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5937. return
  5938. }
  5939. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5940. var beforePrepares []*models.DialysisBeforePrepareGoods
  5941. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5942. var dialysisBefor []*models.DialysisBeforePrepare
  5943. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5944. goods, _ := dataBody["goods"].([]interface{})
  5945. if len(goods) > 0 {
  5946. for _, item := range goods {
  5947. items := item.(map[string]interface{})
  5948. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5949. utils.ErrorLog("good_id")
  5950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5951. return
  5952. }
  5953. good_id := int64(items["good_id"].(float64))
  5954. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5955. utils.ErrorLog("good_type_id")
  5956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5957. return
  5958. }
  5959. good_type_id := int64(items["good_type_id"].(float64))
  5960. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5961. utils.ErrorLog("count")
  5962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5963. return
  5964. }
  5965. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5966. commdity_code := items["commdity_code"].(string)
  5967. fmt.Println("commdity", commdity_code)
  5968. prepareGoods := &models.DialysisBeforePrepareGoods{
  5969. GoodTypeId: good_type_id,
  5970. GoodId: good_id,
  5971. Count: count,
  5972. StorehouseId: houseConfig.StorehouseOutInfo,
  5973. }
  5974. beforePrepares = append(beforePrepares, prepareGoods)
  5975. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5976. GoodTypeId: good_type_id,
  5977. GoodId: good_id,
  5978. Count: count,
  5979. StorehouseId: houseConfig.StorehouseOutInfo,
  5980. }
  5981. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5982. prepare := &models.DialysisBeforePrepare{
  5983. GoodTypeId: good_type_id,
  5984. GoodId: good_id,
  5985. Count: count,
  5986. PatientId: patient_id,
  5987. RecordDate: record_time,
  5988. UserOrgId: adminUser.Org.Id,
  5989. Status: 1,
  5990. Ctime: time.Now().Unix(),
  5991. Creater: adminUser.AdminUser.Id,
  5992. CommdityCode: commdity_code,
  5993. StorehouseId: houseConfig.StorehouseOutInfo,
  5994. }
  5995. dialysisBefor = append(dialysisBefor, prepare)
  5996. }
  5997. }
  5998. //查询是否有库存
  5999. for _, item := range dialysisBefor {
  6000. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6001. if err == gorm.ErrRecordNotFound {
  6002. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6003. c.ServeSuccessJSON(map[string]interface{}{
  6004. "message": "1",
  6005. "good_name": goodObj.GoodName,
  6006. "specification_name": goodObj.SpecificationName,
  6007. })
  6008. return
  6009. }
  6010. if err != nil {
  6011. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6012. c.ServeSuccessJSON(map[string]interface{}{
  6013. "message": "1",
  6014. "good_name": goodObj.GoodName,
  6015. "specification_name": goodObj.SpecificationName,
  6016. })
  6017. return
  6018. }
  6019. }
  6020. fmt.Println("active-----------------------", active)
  6021. fmt.Println("len(goods)-----------------------", len(goods))
  6022. //新增
  6023. if active == 1 && len(goods) > 0 {
  6024. for _, item := range dialysisBefor {
  6025. dialyPrepareOne := models.DialysisBeforePrepare{
  6026. GoodTypeId: item.GoodTypeId,
  6027. GoodId: item.GoodId,
  6028. PatientId: item.PatientId,
  6029. RecordDate: item.RecordDate,
  6030. UserOrgId: item.UserOrgId,
  6031. Count: item.Count,
  6032. Ctime: time.Now().Unix(),
  6033. Creater: item.Creater,
  6034. CommdityCode: item.CommdityCode,
  6035. Status: 1,
  6036. StorehouseId: houseConfig.StorehouseOutInfo,
  6037. }
  6038. //先清除再插入
  6039. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6040. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  6041. //查询默认仓库
  6042. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6043. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6044. var total_count int64
  6045. for _, it := range stockList {
  6046. total_count += it.StockCount
  6047. }
  6048. //基础库插入数据
  6049. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6050. //更新库存
  6051. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6052. var flush_count int64
  6053. for _, it := range goodList {
  6054. flush_count += it.StockCount
  6055. }
  6056. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6057. }
  6058. if err == nil {
  6059. c.ServeSuccessJSON(map[string]interface{}{
  6060. "msg": "保存成功",
  6061. "message": "2",
  6062. })
  6063. return
  6064. } else {
  6065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6066. return
  6067. }
  6068. }
  6069. if len(beforePrepares) > 0 && active == 2 {
  6070. for _, item := range beforePrepares {
  6071. //1.查看该患者该耗材型号最后一次出库数量
  6072. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6073. //判断当前出库数量和最后一次出库数量的大小
  6074. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  6075. if item.Count <= goodInfo.Count {
  6076. //退库
  6077. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  6078. //查询今日出库数据
  6079. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6080. for _, it := range list {
  6081. prepare := models.DialysisBeforePrepare{
  6082. UserOrgId: it.OrgId,
  6083. PatientId: patient_id,
  6084. RecordDate: it.RecordTime,
  6085. GoodId: it.GoodId,
  6086. GoodTypeId: it.GoodTypeId,
  6087. Count: it.Count,
  6088. Ctime: time.Now().Unix(),
  6089. Creater: adminUser.AdminUser.Id,
  6090. Status: 1,
  6091. StorehouseId: houseConfig.StorehouseOutInfo,
  6092. }
  6093. //删除准备表数据
  6094. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6095. service.CreateDialysisBeforePrepareOne(&prepare)
  6096. }
  6097. }
  6098. var last_total int64
  6099. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6100. if item.Count >= goodInfo.Count {
  6101. //查询当前批次当前耗材最后一条出库数据
  6102. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6103. //计算当前出库和最后一次出库数据相差数据
  6104. last_total = item.Count - lastOutInfo.Count
  6105. //查询该批次剩余库存
  6106. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  6107. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  6108. if lastInfo.StockCount >= last_total {
  6109. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6110. //查询今日出库数据
  6111. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6112. for _, it := range list {
  6113. prepare := models.DialysisBeforePrepare{
  6114. UserOrgId: it.OrgId,
  6115. PatientId: patient_id,
  6116. RecordDate: it.RecordTime,
  6117. GoodId: it.GoodId,
  6118. GoodTypeId: it.GoodTypeId,
  6119. Count: it.Count,
  6120. Ctime: time.Now().Unix(),
  6121. Creater: adminUser.AdminUser.Id,
  6122. Status: 1,
  6123. StorehouseId: houseConfig.StorehouseOutInfo,
  6124. }
  6125. //删除准备表数据
  6126. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6127. service.CreateDialysisBeforePrepareOne(&prepare)
  6128. //查询默认仓库
  6129. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6130. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6131. var total_count int64
  6132. for _, it := range stockList {
  6133. total_count += it.StockCount
  6134. }
  6135. //基础库插入数据
  6136. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6137. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6138. var flush_count int64
  6139. for _, it := range goodList {
  6140. flush_count += it.StockCount
  6141. }
  6142. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6143. }
  6144. }
  6145. //如果库存不够,则出库到下一个批次
  6146. if lastInfo.StockCount < last_total {
  6147. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6148. //查询今日出库数据
  6149. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6150. for _, it := range list {
  6151. prepare := models.DialysisBeforePrepare{
  6152. UserOrgId: it.OrgId,
  6153. PatientId: patient_id,
  6154. RecordDate: it.RecordTime,
  6155. GoodId: it.GoodId,
  6156. GoodTypeId: it.GoodTypeId,
  6157. Count: it.Count,
  6158. Ctime: time.Now().Unix(),
  6159. Creater: adminUser.AdminUser.Id,
  6160. Status: 1,
  6161. StorehouseId: houseConfig.StorehouseOutInfo,
  6162. }
  6163. //删除准备表数据
  6164. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6165. service.CreateDialysisBeforePrepareOne(&prepare)
  6166. //查询默认仓库
  6167. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6168. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6169. var total_count int64
  6170. for _, it := range stockList {
  6171. total_count += it.StockCount
  6172. }
  6173. //基础库插入数据
  6174. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6175. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6176. var flush_count int64
  6177. for _, it := range goodList {
  6178. flush_count += it.StockCount
  6179. }
  6180. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6181. }
  6182. if err != nil {
  6183. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6184. c.ServeSuccessJSON(map[string]interface{}{
  6185. "message": "1",
  6186. "good_name": goodObj.GoodName,
  6187. "specification_name": goodObj.SpecificationName,
  6188. })
  6189. return
  6190. }
  6191. }
  6192. }
  6193. if err != nil {
  6194. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6195. c.ServeSuccessJSON(map[string]interface{}{
  6196. "message": "1",
  6197. "good_name": goodObj.GoodName,
  6198. "specification_name": goodObj.SpecificationName,
  6199. })
  6200. return
  6201. }
  6202. }
  6203. }
  6204. }
  6205. var errs error
  6206. if errs == nil {
  6207. c.ServeSuccessJSON(map[string]interface{}{
  6208. "msg": "提交成功",
  6209. "message": "2",
  6210. "good_name": "",
  6211. "specification_name": "",
  6212. })
  6213. return
  6214. } else {
  6215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6216. return
  6217. }
  6218. }
  6219. func (c *DialysisAPIController) CreateStockOutInfo() {
  6220. patient_id, _ := c.GetInt64("patient_id", 0)
  6221. record_date := c.GetString("record_time")
  6222. if patient_id <= 0 {
  6223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6224. return
  6225. }
  6226. adminInfo := c.GetMobileAdminUserInfo()
  6227. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6228. timeLayout := "2006-01-02"
  6229. loc, _ := time.LoadLocation("Local")
  6230. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6231. record_time := theRecordTime.Unix()
  6232. // 查询信息规挡的设置天数
  6233. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6234. if infor.ID > 0 && infor.WeekDay > 0 {
  6235. var cha_time int64
  6236. timeNowStr := time.Now().Format("2006-01-02")
  6237. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6238. //今日的日期减去设置的日期
  6239. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6240. if cha_time >= record_time {
  6241. //查询审核是否允许
  6242. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6243. //申请状态不允许的情况 拒绝修改
  6244. if infor.ApplicationStatus != 1 {
  6245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6246. return
  6247. }
  6248. }
  6249. }
  6250. //创建步骤表
  6251. finish := models.XtDialysisFinish{
  6252. IsFinish: 1,
  6253. UserOrgId: adminInfo.Org.Id,
  6254. Status: 1,
  6255. Ctime: time.Now().Unix(),
  6256. Mtime: 0,
  6257. Module: 11,
  6258. RecordDate: record_time,
  6259. Sourse: 1,
  6260. PatientId: patient_id,
  6261. }
  6262. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6263. if dialysisFinish.ID == 0 {
  6264. service.CreateDialysisFinish(finish)
  6265. }
  6266. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6267. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6268. //去重
  6269. consumables = RemoveRepeatedGood(consumables)
  6270. if adminInfo.Org.Id == 9919 {
  6271. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6272. //查询是否有库存
  6273. for _, item := range consumables {
  6274. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6275. if item.Count > warehouse.Count {
  6276. goodErrcode := models.XtGoodErrcode{
  6277. UserOrgId: item.UserOrgId,
  6278. Errcode: "自动出库库存不足",
  6279. GoodId: item.GoodId,
  6280. Status: 1,
  6281. Ctime: time.Now().Unix(),
  6282. Mtime: 0,
  6283. Count: 0,
  6284. StockCount: 0,
  6285. Creater: creator,
  6286. BatchNumberId: warehouse.ID,
  6287. WarehouseOutId: 0,
  6288. }
  6289. service.CreateGoodErrcode(goodErrcode)
  6290. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6291. c.ServeSuccessJSON(map[string]interface{}{
  6292. "message": "1",
  6293. "good_name": goodObj.GoodName,
  6294. "specification_name": goodObj.SpecificationName,
  6295. })
  6296. return
  6297. }
  6298. }
  6299. //查询是否有出库单
  6300. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6301. if err == gorm.ErrRecordNotFound {
  6302. //没有记录,则创建出库单
  6303. timeStr := time.Now().Format("2006-01-02")
  6304. timeArr := strings.Split(timeStr, "-")
  6305. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6306. total = total + 1
  6307. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6308. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6309. number = number + total
  6310. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6311. creater := adminInfo.AdminUser.Id
  6312. warehouseOut := models.WarehouseOut{
  6313. WarehouseOutOrderNumber: warehousing_out_order,
  6314. OperationTime: time.Now().Unix(),
  6315. OrgId: adminInfo.Org.Id,
  6316. Creater: creater,
  6317. Ctime: time.Now().Unix(),
  6318. Status: 1,
  6319. WarehouseOutTime: record_time,
  6320. Dealer: 0,
  6321. Manufacturer: 0,
  6322. Type: 1,
  6323. IsSys: 1,
  6324. StorehouseId: houseConfig.StorehouseOutInfo,
  6325. IsCheck: 1,
  6326. }
  6327. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6328. if err != nil {
  6329. goodErrcode := models.XtGoodErrcode{
  6330. UserOrgId: adminInfo.Org.Id,
  6331. Errcode: "创建出库单失败",
  6332. GoodId: 0,
  6333. Status: 1,
  6334. Ctime: time.Now().Unix(),
  6335. Mtime: 0,
  6336. Count: 0,
  6337. StockCount: 0,
  6338. Creater: creator,
  6339. BatchNumberId: 0,
  6340. WarehouseOutId: 0,
  6341. }
  6342. service.CreateGoodErrcode(goodErrcode)
  6343. utils.TraceLog("创建出库单失败 err = %v", err)
  6344. } else {
  6345. for _, item := range consumables {
  6346. //出库
  6347. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6348. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6349. if err == nil {
  6350. goodErrcode := models.XtGoodErrcode{
  6351. UserOrgId: adminInfo.Org.Id,
  6352. Errcode: "自动出库接口报错",
  6353. GoodId: 0,
  6354. Status: 1,
  6355. Ctime: time.Now().Unix(),
  6356. Mtime: 0,
  6357. Count: 0,
  6358. StockCount: 0,
  6359. Creater: creator,
  6360. BatchNumberId: 0,
  6361. WarehouseOutId: 0,
  6362. }
  6363. service.CreateGoodErrcode(goodErrcode)
  6364. utils.TraceLog("创建出库单失败 err = %v", err)
  6365. }
  6366. //查询
  6367. //出库数量相加
  6368. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6369. if errs != nil {
  6370. goodErrcode := models.XtGoodErrcode{
  6371. UserOrgId: item.UserOrgId,
  6372. Errcode: "创建剩余库存字段报错",
  6373. GoodId: item.GoodId,
  6374. Status: 1,
  6375. Ctime: time.Now().Unix(),
  6376. Mtime: 0,
  6377. Count: 0,
  6378. StockCount: 0,
  6379. Creater: creater,
  6380. BatchNumberId: 0,
  6381. WarehouseOutId: 0,
  6382. }
  6383. service.CreateGoodErrcode(goodErrcode)
  6384. }
  6385. }
  6386. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6387. if len(list) == 0 {
  6388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6389. return
  6390. }
  6391. for _, item := range list {
  6392. prepare := models.DialysisBeforePrepare{
  6393. UserOrgId: adminInfo.Org.Id,
  6394. PatientId: patient_id,
  6395. RecordDate: record_time,
  6396. GoodId: item.GoodId,
  6397. GoodTypeId: item.GoodTypeId,
  6398. Count: item.Count,
  6399. Creater: adminInfo.AdminUser.Id,
  6400. Status: 1,
  6401. Ctime: time.Now().Unix(),
  6402. StorehouseId: houseConfig.StorehouseOutInfo,
  6403. }
  6404. //清空准备表数据
  6405. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6406. if err != nil {
  6407. goodErrcode := models.XtGoodErrcode{
  6408. UserOrgId: item.OrgId,
  6409. Errcode: "自动出库清空准备表数据报错",
  6410. GoodId: item.GoodId,
  6411. Status: 1,
  6412. Ctime: time.Now().Unix(),
  6413. Mtime: 0,
  6414. Count: 0,
  6415. StockCount: 0,
  6416. Creater: creater,
  6417. BatchNumberId: 0,
  6418. WarehouseOutId: 0,
  6419. }
  6420. service.CreateGoodErrcode(goodErrcode)
  6421. }
  6422. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6423. if errs != nil {
  6424. goodErrcode := models.XtGoodErrcode{
  6425. UserOrgId: item.OrgId,
  6426. Errcode: "自动出库创建准备表数据报错",
  6427. GoodId: item.GoodId,
  6428. Status: 1,
  6429. Ctime: time.Now().Unix(),
  6430. Mtime: 0,
  6431. Count: 0,
  6432. StockCount: 0,
  6433. Creater: creater,
  6434. BatchNumberId: 0,
  6435. WarehouseOutId: 0,
  6436. }
  6437. service.CreateGoodErrcode(goodErrcode)
  6438. }
  6439. //查询默认仓库
  6440. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6441. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6442. var total_count int64
  6443. for _, it := range stockList {
  6444. total_count += it.StockCount
  6445. }
  6446. //基础库插入数据
  6447. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6448. if errcodes != nil {
  6449. goodErrcode := models.XtGoodErrcode{
  6450. UserOrgId: item.OrgId,
  6451. Errcode: "自动出库基础库插入数据",
  6452. GoodId: item.GoodId,
  6453. Status: 1,
  6454. Ctime: time.Now().Unix(),
  6455. Mtime: 0,
  6456. Count: 0,
  6457. StockCount: 0,
  6458. Creater: creater,
  6459. BatchNumberId: 0,
  6460. WarehouseOutId: 0,
  6461. }
  6462. service.CreateGoodErrcode(goodErrcode)
  6463. }
  6464. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6465. var flush_count int64
  6466. for _, it := range goodList {
  6467. flush_count += it.StockCount
  6468. }
  6469. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6470. if errsss != nil {
  6471. goodErrcode := models.XtGoodErrcode{
  6472. UserOrgId: item.OrgId,
  6473. Errcode: "自动出库剩余库存更新数据",
  6474. GoodId: item.GoodId,
  6475. Status: 1,
  6476. Ctime: time.Now().Unix(),
  6477. Mtime: 0,
  6478. Count: 0,
  6479. StockCount: 0,
  6480. Creater: creater,
  6481. BatchNumberId: 0,
  6482. WarehouseOutId: 0,
  6483. }
  6484. service.CreateGoodErrcode(goodErrcode)
  6485. }
  6486. }
  6487. }
  6488. //
  6489. } else if err == nil {
  6490. for _, item := range consumables {
  6491. //出库
  6492. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6493. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6494. if err != nil {
  6495. goodErrcode := models.XtGoodErrcode{
  6496. UserOrgId: adminInfo.Org.Id,
  6497. Errcode: "自动出库接口报错",
  6498. GoodId: 0,
  6499. Status: 1,
  6500. Ctime: time.Now().Unix(),
  6501. Mtime: 0,
  6502. Count: 0,
  6503. StockCount: 0,
  6504. Creater: creator,
  6505. BatchNumberId: 0,
  6506. WarehouseOutId: 0,
  6507. }
  6508. service.CreateGoodErrcode(goodErrcode)
  6509. }
  6510. //出库数量相加
  6511. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6512. if errss != nil {
  6513. goodErrcode := models.XtGoodErrcode{
  6514. UserOrgId: item.UserOrgId,
  6515. Errcode: "创建剩余库存字段报错",
  6516. GoodId: item.GoodId,
  6517. Status: 1,
  6518. Ctime: time.Now().Unix(),
  6519. Mtime: time.Now().Unix(),
  6520. Count: 0,
  6521. StockCount: 0,
  6522. Creater: item.Creater,
  6523. BatchNumberId: 0,
  6524. WarehouseOutId: 0,
  6525. }
  6526. service.CreateGoodErrcode(goodErrcode)
  6527. }
  6528. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6529. if len(list) == 0 {
  6530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6531. return
  6532. }
  6533. for _, item := range list {
  6534. prepare := models.DialysisBeforePrepare{
  6535. UserOrgId: adminInfo.Org.Id,
  6536. PatientId: patient_id,
  6537. RecordDate: record_time,
  6538. GoodId: item.GoodId,
  6539. GoodTypeId: item.GoodTypeId,
  6540. Count: item.Count,
  6541. Creater: adminInfo.AdminUser.Id,
  6542. Status: 1,
  6543. Ctime: time.Now().Unix(),
  6544. StorehouseId: houseConfig.StorehouseOutInfo,
  6545. }
  6546. //清空准备表数据
  6547. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6548. if errs != nil {
  6549. goodErrcode := models.XtGoodErrcode{
  6550. UserOrgId: adminInfo.Org.Id,
  6551. Errcode: "自动出库清空准备表数据报错",
  6552. GoodId: 0,
  6553. Status: 1,
  6554. Ctime: time.Now().Unix(),
  6555. Mtime: 0,
  6556. Count: 0,
  6557. StockCount: 0,
  6558. Creater: creator,
  6559. BatchNumberId: 0,
  6560. WarehouseOutId: 0,
  6561. }
  6562. service.CreateGoodErrcode(goodErrcode)
  6563. }
  6564. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6565. if errcodes != nil {
  6566. goodErrcode := models.XtGoodErrcode{
  6567. UserOrgId: adminInfo.Org.Id,
  6568. Errcode: "自动出库创建准备表数据报错",
  6569. GoodId: 0,
  6570. Status: 1,
  6571. Ctime: time.Now().Unix(),
  6572. Mtime: 0,
  6573. Count: 0,
  6574. StockCount: 0,
  6575. Creater: creator,
  6576. BatchNumberId: 0,
  6577. WarehouseOutId: 0,
  6578. }
  6579. service.CreateGoodErrcode(goodErrcode)
  6580. }
  6581. //查询默认仓库
  6582. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6583. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6584. var total_count int64
  6585. for _, it := range stockList {
  6586. total_count += it.StockCount
  6587. }
  6588. //基础库插入数据
  6589. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6590. if errcodes != nil {
  6591. goodErrcode := models.XtGoodErrcode{
  6592. UserOrgId: adminInfo.Org.Id,
  6593. Errcode: "自动出库基础库插入数据报错",
  6594. GoodId: 0,
  6595. Status: 1,
  6596. Ctime: time.Now().Unix(),
  6597. Mtime: 0,
  6598. Count: 0,
  6599. StockCount: 0,
  6600. Creater: creator,
  6601. BatchNumberId: 0,
  6602. WarehouseOutId: 0,
  6603. }
  6604. service.CreateGoodErrcode(goodErrcode)
  6605. }
  6606. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6607. var flush_count int64
  6608. for _, it := range goodList {
  6609. flush_count += it.StockCount
  6610. }
  6611. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6612. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6613. if errss != nil {
  6614. goodErrcode := models.XtGoodErrcode{
  6615. UserOrgId: item.OrgId,
  6616. Errcode: "自动出库剩余库存更新数据",
  6617. GoodId: item.GoodId,
  6618. Status: 1,
  6619. Ctime: time.Now().Unix(),
  6620. Mtime: 0,
  6621. Count: 0,
  6622. StockCount: 0,
  6623. Creater: creater,
  6624. BatchNumberId: 0,
  6625. WarehouseOutId: 0,
  6626. }
  6627. service.CreateGoodErrcode(goodErrcode)
  6628. }
  6629. }
  6630. }
  6631. }
  6632. c.ServeSuccessJSON(map[string]interface{}{
  6633. "msg": "提交成功",
  6634. "message": "2",
  6635. "good_name": "",
  6636. "specification_name": "",
  6637. })
  6638. return
  6639. }
  6640. if record.IsOpen == 1 {
  6641. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6642. //查询是否有库存
  6643. for _, item := range consumables {
  6644. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6645. if item.Count > warehouse.Count {
  6646. goodErrcode := models.XtGoodErrcode{
  6647. UserOrgId: item.UserOrgId,
  6648. Errcode: "自动出库库存不足",
  6649. GoodId: item.GoodId,
  6650. Status: 1,
  6651. Ctime: time.Now().Unix(),
  6652. Mtime: 0,
  6653. Count: 0,
  6654. StockCount: 0,
  6655. Creater: creator,
  6656. BatchNumberId: warehouse.ID,
  6657. WarehouseOutId: 0,
  6658. }
  6659. service.CreateGoodErrcode(goodErrcode)
  6660. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6661. c.ServeSuccessJSON(map[string]interface{}{
  6662. "message": "1",
  6663. "good_name": goodObj.GoodName,
  6664. "specification_name": goodObj.SpecificationName,
  6665. })
  6666. return
  6667. }
  6668. }
  6669. //查询是否有出库单
  6670. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6671. if err == gorm.ErrRecordNotFound {
  6672. //没有记录,则创建出库单
  6673. timeStr := time.Now().Format("2006-01-02")
  6674. timeArr := strings.Split(timeStr, "-")
  6675. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6676. total = total + 1
  6677. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6678. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6679. number = number + total
  6680. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6681. creater := adminInfo.AdminUser.Id
  6682. warehouseOut := models.WarehouseOut{
  6683. WarehouseOutOrderNumber: warehousing_out_order,
  6684. OperationTime: time.Now().Unix(),
  6685. OrgId: adminInfo.Org.Id,
  6686. Creater: creater,
  6687. Ctime: time.Now().Unix(),
  6688. Status: 1,
  6689. WarehouseOutTime: record_time,
  6690. Dealer: 0,
  6691. Manufacturer: 0,
  6692. Type: 1,
  6693. IsSys: 1,
  6694. StorehouseId: houseConfig.StorehouseOutInfo,
  6695. IsCheck: 1,
  6696. }
  6697. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6698. if err != nil {
  6699. goodErrcode := models.XtGoodErrcode{
  6700. UserOrgId: adminInfo.Org.Id,
  6701. Errcode: "创建出库单失败",
  6702. GoodId: 0,
  6703. Status: 1,
  6704. Ctime: time.Now().Unix(),
  6705. Mtime: 0,
  6706. Count: 0,
  6707. StockCount: 0,
  6708. Creater: creator,
  6709. BatchNumberId: 0,
  6710. WarehouseOutId: 0,
  6711. }
  6712. service.CreateGoodErrcode(goodErrcode)
  6713. utils.TraceLog("创建出库单失败 err = %v", err)
  6714. } else {
  6715. for _, item := range consumables {
  6716. //出库
  6717. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6718. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6719. if err == nil {
  6720. goodErrcode := models.XtGoodErrcode{
  6721. UserOrgId: adminInfo.Org.Id,
  6722. Errcode: "自动出库接口报错",
  6723. GoodId: 0,
  6724. Status: 1,
  6725. Ctime: time.Now().Unix(),
  6726. Mtime: 0,
  6727. Count: 0,
  6728. StockCount: 0,
  6729. Creater: creator,
  6730. BatchNumberId: 0,
  6731. WarehouseOutId: 0,
  6732. }
  6733. service.CreateGoodErrcode(goodErrcode)
  6734. utils.TraceLog("创建出库单失败 err = %v", err)
  6735. }
  6736. //查询
  6737. //出库数量相加
  6738. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6739. if errs != nil {
  6740. goodErrcode := models.XtGoodErrcode{
  6741. UserOrgId: item.UserOrgId,
  6742. Errcode: "创建剩余库存字段报错",
  6743. GoodId: item.GoodId,
  6744. Status: 1,
  6745. Ctime: time.Now().Unix(),
  6746. Mtime: 0,
  6747. Count: 0,
  6748. StockCount: 0,
  6749. Creater: creater,
  6750. BatchNumberId: 0,
  6751. WarehouseOutId: 0,
  6752. }
  6753. service.CreateGoodErrcode(goodErrcode)
  6754. }
  6755. }
  6756. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6757. if len(list) == 0 {
  6758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6759. return
  6760. }
  6761. for _, item := range list {
  6762. prepare := models.DialysisBeforePrepare{
  6763. UserOrgId: adminInfo.Org.Id,
  6764. PatientId: patient_id,
  6765. RecordDate: record_time,
  6766. GoodId: item.GoodId,
  6767. GoodTypeId: item.GoodTypeId,
  6768. Count: item.Count,
  6769. Creater: adminInfo.AdminUser.Id,
  6770. Status: 1,
  6771. Ctime: time.Now().Unix(),
  6772. StorehouseId: houseConfig.StorehouseOutInfo,
  6773. }
  6774. //清空准备表数据
  6775. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6776. if err != nil {
  6777. goodErrcode := models.XtGoodErrcode{
  6778. UserOrgId: item.OrgId,
  6779. Errcode: "自动出库清空准备表数据报错",
  6780. GoodId: item.GoodId,
  6781. Status: 1,
  6782. Ctime: time.Now().Unix(),
  6783. Mtime: 0,
  6784. Count: 0,
  6785. StockCount: 0,
  6786. Creater: creater,
  6787. BatchNumberId: 0,
  6788. WarehouseOutId: 0,
  6789. }
  6790. service.CreateGoodErrcode(goodErrcode)
  6791. }
  6792. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6793. if errs != nil {
  6794. goodErrcode := models.XtGoodErrcode{
  6795. UserOrgId: item.OrgId,
  6796. Errcode: "自动出库创建准备表数据报错",
  6797. GoodId: item.GoodId,
  6798. Status: 1,
  6799. Ctime: time.Now().Unix(),
  6800. Mtime: 0,
  6801. Count: 0,
  6802. StockCount: 0,
  6803. Creater: creater,
  6804. BatchNumberId: 0,
  6805. WarehouseOutId: 0,
  6806. }
  6807. service.CreateGoodErrcode(goodErrcode)
  6808. }
  6809. //查询默认仓库
  6810. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6811. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6812. var total_count int64
  6813. for _, it := range stockList {
  6814. total_count += it.StockCount
  6815. }
  6816. //基础库插入数据
  6817. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6818. if errcodes != nil {
  6819. goodErrcode := models.XtGoodErrcode{
  6820. UserOrgId: item.OrgId,
  6821. Errcode: "自动出库基础库插入数据",
  6822. GoodId: item.GoodId,
  6823. Status: 1,
  6824. Ctime: time.Now().Unix(),
  6825. Mtime: 0,
  6826. Count: 0,
  6827. StockCount: 0,
  6828. Creater: creater,
  6829. BatchNumberId: 0,
  6830. WarehouseOutId: 0,
  6831. }
  6832. service.CreateGoodErrcode(goodErrcode)
  6833. }
  6834. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6835. var flush_count int64
  6836. for _, it := range goodList {
  6837. flush_count += it.StockCount
  6838. }
  6839. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6840. if errsss != nil {
  6841. goodErrcode := models.XtGoodErrcode{
  6842. UserOrgId: item.OrgId,
  6843. Errcode: "自动出库剩余库存更新数据",
  6844. GoodId: item.GoodId,
  6845. Status: 1,
  6846. Ctime: time.Now().Unix(),
  6847. Mtime: 0,
  6848. Count: 0,
  6849. StockCount: 0,
  6850. Creater: creater,
  6851. BatchNumberId: 0,
  6852. WarehouseOutId: 0,
  6853. }
  6854. service.CreateGoodErrcode(goodErrcode)
  6855. }
  6856. }
  6857. }
  6858. //
  6859. } else if err == nil {
  6860. for _, item := range consumables {
  6861. //出库
  6862. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6863. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6864. if err != nil {
  6865. goodErrcode := models.XtGoodErrcode{
  6866. UserOrgId: adminInfo.Org.Id,
  6867. Errcode: "自动出库接口报错",
  6868. GoodId: 0,
  6869. Status: 1,
  6870. Ctime: time.Now().Unix(),
  6871. Mtime: 0,
  6872. Count: 0,
  6873. StockCount: 0,
  6874. Creater: creator,
  6875. BatchNumberId: 0,
  6876. WarehouseOutId: 0,
  6877. }
  6878. service.CreateGoodErrcode(goodErrcode)
  6879. }
  6880. //出库数量相加
  6881. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6882. if errss != nil {
  6883. goodErrcode := models.XtGoodErrcode{
  6884. UserOrgId: item.UserOrgId,
  6885. Errcode: "创建剩余库存字段报错",
  6886. GoodId: item.GoodId,
  6887. Status: 1,
  6888. Ctime: time.Now().Unix(),
  6889. Mtime: time.Now().Unix(),
  6890. Count: 0,
  6891. StockCount: 0,
  6892. Creater: item.Creater,
  6893. BatchNumberId: 0,
  6894. WarehouseOutId: 0,
  6895. }
  6896. service.CreateGoodErrcode(goodErrcode)
  6897. }
  6898. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6899. if len(list) == 0 {
  6900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6901. return
  6902. }
  6903. for _, item := range list {
  6904. prepare := models.DialysisBeforePrepare{
  6905. UserOrgId: adminInfo.Org.Id,
  6906. PatientId: patient_id,
  6907. RecordDate: record_time,
  6908. GoodId: item.GoodId,
  6909. GoodTypeId: item.GoodTypeId,
  6910. Count: item.Count,
  6911. Creater: adminInfo.AdminUser.Id,
  6912. Status: 1,
  6913. Ctime: time.Now().Unix(),
  6914. StorehouseId: houseConfig.StorehouseOutInfo,
  6915. }
  6916. //清空准备表数据
  6917. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6918. if errs != nil {
  6919. goodErrcode := models.XtGoodErrcode{
  6920. UserOrgId: adminInfo.Org.Id,
  6921. Errcode: "自动出库清空准备表数据报错",
  6922. GoodId: 0,
  6923. Status: 1,
  6924. Ctime: time.Now().Unix(),
  6925. Mtime: 0,
  6926. Count: 0,
  6927. StockCount: 0,
  6928. Creater: creator,
  6929. BatchNumberId: 0,
  6930. WarehouseOutId: 0,
  6931. }
  6932. service.CreateGoodErrcode(goodErrcode)
  6933. }
  6934. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6935. if errcodes != nil {
  6936. goodErrcode := models.XtGoodErrcode{
  6937. UserOrgId: adminInfo.Org.Id,
  6938. Errcode: "自动出库创建准备表数据报错",
  6939. GoodId: 0,
  6940. Status: 1,
  6941. Ctime: time.Now().Unix(),
  6942. Mtime: 0,
  6943. Count: 0,
  6944. StockCount: 0,
  6945. Creater: creator,
  6946. BatchNumberId: 0,
  6947. WarehouseOutId: 0,
  6948. }
  6949. service.CreateGoodErrcode(goodErrcode)
  6950. }
  6951. //查询默认仓库
  6952. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6953. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6954. var total_count int64
  6955. for _, it := range stockList {
  6956. total_count += it.StockCount
  6957. }
  6958. //基础库插入数据
  6959. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6960. if errcodes != nil {
  6961. goodErrcode := models.XtGoodErrcode{
  6962. UserOrgId: adminInfo.Org.Id,
  6963. Errcode: "自动出库基础库插入数据报错",
  6964. GoodId: 0,
  6965. Status: 1,
  6966. Ctime: time.Now().Unix(),
  6967. Mtime: 0,
  6968. Count: 0,
  6969. StockCount: 0,
  6970. Creater: creator,
  6971. BatchNumberId: 0,
  6972. WarehouseOutId: 0,
  6973. }
  6974. service.CreateGoodErrcode(goodErrcode)
  6975. }
  6976. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6977. var flush_count int64
  6978. for _, it := range goodList {
  6979. flush_count += it.StockCount
  6980. }
  6981. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6982. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6983. if errss != nil {
  6984. goodErrcode := models.XtGoodErrcode{
  6985. UserOrgId: item.OrgId,
  6986. Errcode: "自动出库剩余库存更新数据",
  6987. GoodId: item.GoodId,
  6988. Status: 1,
  6989. Ctime: time.Now().Unix(),
  6990. Mtime: 0,
  6991. Count: 0,
  6992. StockCount: 0,
  6993. Creater: creater,
  6994. BatchNumberId: 0,
  6995. WarehouseOutId: 0,
  6996. }
  6997. service.CreateGoodErrcode(goodErrcode)
  6998. }
  6999. }
  7000. }
  7001. }
  7002. c.ServeSuccessJSON(map[string]interface{}{
  7003. "msg": "提交成功",
  7004. "message": "2",
  7005. "good_name": "",
  7006. "specification_name": "",
  7007. })
  7008. return
  7009. } else {
  7010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  7011. return
  7012. }
  7013. }
  7014. func (c *DialysisAPIController) EditConsumables() {
  7015. patient_id, _ := c.GetInt64("patient_id", 0)
  7016. record_date := c.GetString("record_time")
  7017. if patient_id <= 0 {
  7018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7019. return
  7020. }
  7021. adminInfo := c.GetMobileAdminUserInfo()
  7022. timeLayout := "2006-01-02"
  7023. loc, _ := time.LoadLocation("Local")
  7024. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7025. record_time := theRecordTime.Unix()
  7026. // 查询信息规挡的设置天数
  7027. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7028. if infor.ID > 0 && infor.WeekDay > 0 {
  7029. var cha_time int64
  7030. timeNowStr := time.Now().Format("2006-01-02")
  7031. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7032. //今日的日期减去设置的日期
  7033. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7034. if cha_time >= record_time {
  7035. //查询审核是否允许
  7036. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7037. //申请状态不允许的情况 拒绝修改
  7038. if infor.ApplicationStatus != 1 {
  7039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7040. return
  7041. }
  7042. }
  7043. }
  7044. dataBody := make(map[string]interface{}, 0)
  7045. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7046. if err != nil {
  7047. utils.ErrorLog(err.Error())
  7048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7049. return
  7050. }
  7051. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7052. var beforePrepares []*models.DialysisBeforePrepareGoods
  7053. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7054. var cancelbefor []*models.DialysisBeforePrepareGoods
  7055. var outbefor []*models.DialysisBeforePrepareGoods
  7056. //判断是否开启自动出库
  7057. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7058. if record.IsOpen == 1 {
  7059. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7060. goods, _ := dataBody["goods"].([]interface{})
  7061. if len(goods) > 0 {
  7062. for _, item := range goods {
  7063. items := item.(map[string]interface{})
  7064. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7065. utils.ErrorLog("good_id")
  7066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7067. return
  7068. }
  7069. good_id := int64(items["good_id"].(float64))
  7070. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7071. utils.ErrorLog("good_type_id")
  7072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7073. return
  7074. }
  7075. good_type_id := int64(items["good_type_id"].(float64))
  7076. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7077. utils.ErrorLog("count")
  7078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7079. return
  7080. }
  7081. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7082. commdity_code := items["commdity_code"].(string)
  7083. fmt.Println(commdity_code)
  7084. prepareGoods := &models.DialysisBeforePrepareGoods{
  7085. GoodTypeId: good_type_id,
  7086. GoodId: good_id,
  7087. Count: count,
  7088. StorehouseId: houseConfig.StorehouseOutInfo,
  7089. }
  7090. beforePrepares = append(beforePrepares, prepareGoods)
  7091. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  7092. GoodTypeId: good_type_id,
  7093. GoodId: good_id,
  7094. Count: count,
  7095. StorehouseId: houseConfig.StorehouseOutInfo,
  7096. }
  7097. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  7098. }
  7099. for _, item := range beforePrepares {
  7100. //1.查看该患者该耗材型号最后一次出库数量
  7101. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7102. //判断当前出库数量和最后一次出库数量的大小
  7103. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  7104. if item.Count < goodInfo.Count {
  7105. cancelbefor = append(cancelbefor, item)
  7106. }
  7107. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  7108. if item.Count > goodInfo.Count {
  7109. outbefor = append(outbefor, item)
  7110. }
  7111. //处理编辑耗材新增不了的问题
  7112. if goodInfo.Count == item.Count {
  7113. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  7114. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  7115. }
  7116. }
  7117. if len(cancelbefor) > 0 {
  7118. //退库
  7119. for _, item := range cancelbefor {
  7120. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7121. creater := adminInfo.AdminUser.Id
  7122. //查询该患者当天已经出库的耗材信息
  7123. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  7124. var delete_count int64 = 0
  7125. delete_count = warehouseOutInfos.Count - item.Count
  7126. //增加库存数量
  7127. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  7128. //减少实际出库库存数量
  7129. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  7130. // 删除出库完成后,要增加对应批次的库存数量
  7131. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  7132. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7133. //更新剩余库存
  7134. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7135. var flush_count int64
  7136. for _, it := range goodListOne {
  7137. flush_count += it.StockCount
  7138. }
  7139. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7140. //查询剩余库存
  7141. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7142. var sum_count int64
  7143. for _, item := range goodList {
  7144. sum_count += item.StockCount
  7145. }
  7146. // 在出库记录表里记录退库详情
  7147. warehouseOutInfo := &models.WarehouseOutInfo{
  7148. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7149. WarehouseOutId: warehouseOut.ID,
  7150. Status: 1,
  7151. Ctime: time.Now().Unix(),
  7152. OrgId: adminInfo.Org.Id,
  7153. Type: 1,
  7154. IsSys: 1,
  7155. SysRecordTime: record_time,
  7156. GoodTypeId: item.GoodTypeId,
  7157. GoodId: item.GoodId,
  7158. PatientId: patient_id,
  7159. ConsumableType: 2,
  7160. StorehouseId: houseConfig.StorehouseOutInfo,
  7161. IsCheck: 1,
  7162. OverCount: sum_count,
  7163. }
  7164. warehouseOutInfo.Count = item.Count
  7165. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7166. warehouseOutInfo.Price = stockInInfo.Price
  7167. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7168. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7169. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7170. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7171. warehouseOutInfo.Number = warehouseOutInfos.Number
  7172. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7173. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7174. //查找当天是否存在出库记录
  7175. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7176. if errcod == gorm.ErrRecordNotFound {
  7177. service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  7178. //插入详情明细表
  7179. stockFlow := models.VmStockFlow{
  7180. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7181. WarehouseOutId: warehouseOut.ID,
  7182. GoodId: item.GoodId,
  7183. Number: warehouseOutInfos.Number,
  7184. ProductDate: stockInInfo.ProductDate,
  7185. ExpireDate: stockInInfo.ExpiryDate,
  7186. Count: item.Count,
  7187. Price: stockInInfo.Price,
  7188. Status: 1,
  7189. Ctime: record_time,
  7190. UserOrgId: adminInfo.Org.Id,
  7191. Manufacturer: stockInInfo.Manufacturer,
  7192. Dealer: stockInInfo.Dealer,
  7193. LicenseNumber: stockInInfo.LicenseNumber,
  7194. IsEdit: 2,
  7195. Creator: creater,
  7196. SystemTime: record_time,
  7197. ConsumableType: 3,
  7198. WarehousingDetailId: 0,
  7199. IsSys: 1,
  7200. UpdateCreator: creater,
  7201. PatientId: patient_id,
  7202. StorehouseId: houseConfig.StorehouseOutInfo,
  7203. }
  7204. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7205. if errflow == gorm.ErrRecordNotFound {
  7206. //创建流水表
  7207. err := service.CreateStockFlowOne(stockFlow)
  7208. fmt.Println("err", err)
  7209. } else if errflow == nil {
  7210. //插入详情明细表
  7211. stockFlow := models.VmStockFlow{
  7212. ID: exsit.ID,
  7213. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7214. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7215. WarehouseOutId: warehouseOut.ID,
  7216. GoodId: item.GoodId,
  7217. Number: warehouseOutInfos.Number,
  7218. ProductDate: stockInInfo.ProductDate,
  7219. ExpireDate: stockInInfo.ExpiryDate,
  7220. Count: exsit.Count - delete_count,
  7221. Price: stockInInfo.Price,
  7222. Status: 1,
  7223. Ctime: record_time,
  7224. UserOrgId: adminInfo.Org.Id,
  7225. Manufacturer: stockInInfo.Manufacturer,
  7226. Dealer: stockInInfo.Dealer,
  7227. LicenseNumber: stockInInfo.LicenseNumber,
  7228. IsEdit: 2,
  7229. Creator: creater,
  7230. SystemTime: record_time,
  7231. ConsumableType: 3,
  7232. WarehousingDetailId: 0,
  7233. IsSys: 1,
  7234. UpdateCreator: creater,
  7235. PatientId: patient_id,
  7236. StorehouseId: houseConfig.StorehouseOutInfo,
  7237. }
  7238. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7239. }
  7240. } else if errcod == nil {
  7241. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7242. //查询剩余库存
  7243. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7244. var sum_count int64
  7245. for _, item := range goodList {
  7246. sum_count += item.StockCount
  7247. }
  7248. //创建退库单,生成退库数据
  7249. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7250. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7251. operation_time := time.Now().Unix()
  7252. creater := adminInfo.AdminUser.Id
  7253. //创建退库单
  7254. timeStr := time.Now().Format("2006-01-02")
  7255. timeArr := strings.Split(timeStr, "-")
  7256. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7257. total = total + 1
  7258. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7259. cancelStock := models.CancelStock{
  7260. OrderNumber: orderNumber,
  7261. OperaTime: operation_time,
  7262. OrgId: adminInfo.Org.Id,
  7263. Creater: creater,
  7264. Ctime: time.Now().Unix(),
  7265. Status: 1,
  7266. ReturnTime: record_time,
  7267. Type: 1,
  7268. StorehouseId: houseConfig.StorehouseOutInfo,
  7269. IsCheck: 1,
  7270. }
  7271. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7272. if msgerrkonde == gorm.ErrRecordNotFound {
  7273. service.AddSigleCancelStock(&cancelStock)
  7274. }
  7275. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7276. //查询是否有出库
  7277. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7278. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7279. deaerler, _ := service.GetDealerById(info.Dealer)
  7280. if info.ID > 0 {
  7281. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7282. cancelStockInfo := models.CancelStockInfo{
  7283. GoodId: item.GoodId,
  7284. CancelStockId: cancel.ID,
  7285. GoodTypeId: good.GoodTypeId,
  7286. Count: delete_count,
  7287. Price: info.Price,
  7288. Total: 0,
  7289. ProductDate: info.ProductDate,
  7290. ExpiryDate: info.ExpiryDate,
  7291. Ctime: time.Now().Unix(),
  7292. Status: 1,
  7293. OrgId: adminInfo.Org.Id,
  7294. OrderNumber: cancel.OrderNumber,
  7295. Type: 0,
  7296. Dealer: deaerler.DealerName,
  7297. Manufacturer: manufacturer.ManufacturerName,
  7298. Number: info.Number,
  7299. RegisterAccount: "",
  7300. Remark: "",
  7301. WarehouseInfoId: info.WarehouseInfotId,
  7302. PatientId: info.PatientId,
  7303. RecordDate: info.SysRecordTime,
  7304. StorehouseId: houseConfig.StorehouseOutInfo,
  7305. IsCheck: 1,
  7306. }
  7307. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7308. //退库数量增加
  7309. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7310. //查询剩余库存
  7311. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7312. var over_count int64
  7313. for _, it := range goodList {
  7314. over_count += it.StockCount
  7315. }
  7316. flow := models.VmStockFlow{
  7317. WarehousingId: info.WarehouseInfotId,
  7318. GoodId: item.GoodId,
  7319. Number: info.Number,
  7320. LicenseNumber: info.LicenseNumber,
  7321. Count: delete_count,
  7322. UserOrgId: adminInfo.Org.Id,
  7323. PatientId: patient_id,
  7324. SystemTime: info.SysRecordTime,
  7325. ConsumableType: 7,
  7326. IsSys: 0,
  7327. WarehousingOrder: "",
  7328. WarehouseOutId: info.WarehouseOutId,
  7329. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7330. IsEdit: 0,
  7331. CancelStockId: cancel.ID,
  7332. CancelOrderNumber: cancel.OrderNumber,
  7333. Manufacturer: manufacturer.ID,
  7334. Dealer: 0,
  7335. Creator: adminInfo.AdminUser.Id,
  7336. UpdateCreator: 0,
  7337. Status: 1,
  7338. Ctime: record_time,
  7339. Mtime: 0,
  7340. Price: info.Price,
  7341. WarehousingDetailId: info.WarehouseInfotId,
  7342. WarehouseOutDetailId: info.ID,
  7343. CancelOutDetailId: cancelInfo.ID,
  7344. ProductDate: info.ProductDate,
  7345. ExpireDate: info.ExpiryDate,
  7346. StorehouseId: houseConfig.StorehouseOutInfo,
  7347. OverCount: over_count,
  7348. }
  7349. service.CreateStockFlowOne(flow)
  7350. }
  7351. }
  7352. //更改自动出库的表格
  7353. details := models.BloodAutomaticReduceDetail{
  7354. WarehouseOutId: warehouseOutInfo.ID,
  7355. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7356. PatientId: patient_id,
  7357. Ctime: time.Now().Unix(),
  7358. Mtime: time.Now().Unix(),
  7359. Status: 1,
  7360. RecordTime: record_time,
  7361. OrgId: adminInfo.Org.Id,
  7362. GoodId: item.GoodId,
  7363. GoodTypeId: item.GoodTypeId,
  7364. Count: item.Count,
  7365. StorehouseId: houseConfig.StorehouseOutInfo,
  7366. }
  7367. //查询当天耗材是否已经存在数据
  7368. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7369. if errcode == gorm.ErrRecordNotFound {
  7370. service.CreateAutoReduceRecord(&details)
  7371. } else if errcode == nil {
  7372. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7373. service.CreateAutoReduceRecord(&details)
  7374. }
  7375. //查询默认仓库
  7376. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7377. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7378. var total_count int64
  7379. for _, it := range stockList {
  7380. total_count += it.StockCount
  7381. }
  7382. //基础库插入数据
  7383. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7384. }
  7385. }
  7386. if len(outbefor) > 0 {
  7387. //出库
  7388. for _, item := range outbefor {
  7389. var last_total int64
  7390. //1.查看该患者该耗材型号最后一次出库数量
  7391. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7392. //计算当前出库和最后一次出库数据相差数据
  7393. last_total = item.Count - goodInfoOne.Count
  7394. //查询该耗材的总库存
  7395. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7396. // 如果库存差大于剩余库存则提示库存不足
  7397. if last_total > wareinfo.StockCount {
  7398. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7399. c.ServeSuccessJSON(map[string]interface{}{
  7400. "message": "1",
  7401. "good_name": goodObj.GoodName,
  7402. "specification_name": goodObj.SpecificationName,
  7403. })
  7404. return
  7405. } else {
  7406. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7407. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7408. if err == gorm.ErrRecordNotFound {
  7409. //没有记录,则创建出库单
  7410. timeStr := time.Now().Format("2006-01-02")
  7411. timeArr := strings.Split(timeStr, "-")
  7412. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7413. total = total + 1
  7414. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7415. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7416. number = number + total
  7417. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7418. warehouseOut := models.WarehouseOut{
  7419. WarehouseOutOrderNumber: warehousing_out_order,
  7420. OperationTime: time.Now().Unix(),
  7421. OrgId: adminInfo.Org.Id,
  7422. Creater: adminInfo.AdminUser.Id,
  7423. Ctime: time.Now().Unix(),
  7424. Status: 1,
  7425. WarehouseOutTime: record_time,
  7426. Dealer: 0,
  7427. Manufacturer: 0,
  7428. Type: 1,
  7429. IsSys: 1,
  7430. StorehouseId: houseConfig.StorehouseOutInfo,
  7431. IsCheck: 1,
  7432. }
  7433. service.AddSigleWarehouseOutOne(&warehouseOut)
  7434. }
  7435. //出库
  7436. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7437. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7438. //1.查看该患者该耗材型号最后一次出库数量
  7439. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7440. prepare := models.DialysisBeforePrepare{
  7441. UserOrgId: adminInfo.Org.Id,
  7442. PatientId: patient_id,
  7443. RecordDate: record_time,
  7444. GoodId: item.GoodId,
  7445. GoodTypeId: item.GoodTypeId,
  7446. Count: item.Count - goodInfoTwo.Count,
  7447. Ctime: time.Now().Unix(),
  7448. Mtime: 0,
  7449. Creater: adminInfo.AdminUser.Id,
  7450. Modifier: adminInfo.AdminUser.Id,
  7451. Status: 1,
  7452. CommdityCode: "",
  7453. NewCount: 0,
  7454. ProjectId: 0,
  7455. StorehouseId: houseConfig.StorehouseOutInfo,
  7456. }
  7457. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7458. //增加出库数量
  7459. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7460. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7461. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7462. var total_count int64
  7463. for _, it := range stockList {
  7464. total_count += it.StockCount
  7465. }
  7466. //基础库插入数据
  7467. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7468. //剩余库存
  7469. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7470. var flush_count int64
  7471. for _, it := range goodList {
  7472. flush_count += it.StockCount
  7473. }
  7474. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7475. }
  7476. }
  7477. }
  7478. //查询今日出库数据
  7479. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7480. for _, it := range list {
  7481. prepare := models.DialysisBeforePrepare{
  7482. UserOrgId: it.OrgId,
  7483. PatientId: patient_id,
  7484. RecordDate: it.RecordTime,
  7485. GoodId: it.GoodId,
  7486. GoodTypeId: it.GoodTypeId,
  7487. Count: it.Count,
  7488. Ctime: time.Now().Unix(),
  7489. Creater: adminInfo.AdminUser.Id,
  7490. Status: 1,
  7491. StorehouseId: houseConfig.StorehouseOutInfo,
  7492. ProjectId: it.ProjectId,
  7493. }
  7494. //删除准备表数据
  7495. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7496. service.CreateDialysisBeforePrepareOne(&prepare)
  7497. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7498. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7499. var total_count int64
  7500. for _, it := range stockList {
  7501. total_count += it.StockCount
  7502. }
  7503. //基础库插入数据
  7504. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7505. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7506. var flush_count int64
  7507. for _, it := range goodList {
  7508. flush_count += it.StockCount
  7509. }
  7510. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7511. }
  7512. }
  7513. }
  7514. //更新自动出库的地方
  7515. var errs error
  7516. if errs == nil {
  7517. c.ServeSuccessJSON(map[string]interface{}{
  7518. "msg": "修改成功",
  7519. "message": "2",
  7520. "good_name": "",
  7521. "specification_name": "",
  7522. })
  7523. return
  7524. } else {
  7525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7526. return
  7527. }
  7528. }
  7529. }
  7530. func (c *DialysisAPIController) GetDialysisGoods() {
  7531. schedualDate := c.GetString("schedule_date")
  7532. schedule_type, _ := c.GetInt64("schedule_type")
  7533. partition_id, _ := c.GetInt64("partition_id")
  7534. page, _ := c.GetInt("page")
  7535. patient_id, _ := c.GetInt64("patient_id")
  7536. schedualEndDate := int64(0)
  7537. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7538. if parseDateErr != nil && len(schedualDate) != 0 {
  7539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7540. return
  7541. }
  7542. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7543. if parseDateErr != nil && len(schedualDate) != 0 {
  7544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7545. return
  7546. }
  7547. schedualEndDate = endDate.Unix()
  7548. adminUser := c.GetMobileAdminUserInfo()
  7549. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7550. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7551. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7552. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7553. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7554. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7555. //获取当天该病人的透析处方
  7556. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7557. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7558. if err == gorm.ErrRecordNotFound {
  7559. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7560. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7561. if patient_id != 0 {
  7562. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7563. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7564. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7565. //获取患者总的出库数据
  7566. item.LastAutomaticReduceDetail = goodUser
  7567. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7568. item.Project = project
  7569. for _, it := range item.AutomaticReduceDetail {
  7570. var total int64
  7571. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7572. for _, its := range auto {
  7573. total += its.Count
  7574. }
  7575. it.Count = total
  7576. }
  7577. }
  7578. }
  7579. c.ServeSuccessJSON(map[string]interface{}{
  7580. "dialysis_goods": dialysisGoods,
  7581. "good_type": goodTypes,
  7582. "total": total,
  7583. "prescribe": prescribe,
  7584. "good_info": good_info,
  7585. "warehouseOutList": warehouseOutList,
  7586. "config": config,
  7587. "outConfig": outConfig,
  7588. "settleConfig": settleConfig,
  7589. })
  7590. return
  7591. } else if err == nil {
  7592. //获取当天排班的每个患者的库存使用情况
  7593. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7594. //获取患者总的出库数据
  7595. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7596. if patient_id != 0 {
  7597. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7598. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7599. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7600. item.Project = project
  7601. item.LastAutomaticReduceDetail = goodUser
  7602. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7603. for _, it := range item.AutomaticReduceDetail {
  7604. var total int64
  7605. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7606. for _, its := range auto {
  7607. total += its.Count
  7608. }
  7609. it.Count = total
  7610. }
  7611. }
  7612. }
  7613. if err == nil {
  7614. c.ServeSuccessJSON(map[string]interface{}{
  7615. "dialysis_goods": dialysisGoods,
  7616. "good_type": goodTypes,
  7617. "total": total,
  7618. "prescribe": prescribe,
  7619. "good_info": good_info,
  7620. "project": project,
  7621. "warehouseOutList": warehouseOutList,
  7622. "config": config,
  7623. "outConfig": outConfig,
  7624. "settleConfig": settleConfig,
  7625. })
  7626. return
  7627. } else {
  7628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7629. return
  7630. }
  7631. } else if err != nil {
  7632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7633. return
  7634. }
  7635. }
  7636. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7637. start_time := c.GetString("start_time")
  7638. end_time := c.GetString("end_time")
  7639. timeLayout := "2006-01-02"
  7640. loc, _ := time.LoadLocation("Local")
  7641. var theStartTime int64
  7642. if len(start_time) > 0 {
  7643. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7644. if err != nil {
  7645. utils.ErrorLog(err.Error())
  7646. }
  7647. theStartTime = theTime.Unix()
  7648. }
  7649. var theEndtTime int64
  7650. if len(end_time) > 0 {
  7651. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7652. if err != nil {
  7653. utils.ErrorLog(err.Error())
  7654. }
  7655. theEndtTime = theTime.Unix()
  7656. }
  7657. adminUser := c.GetMobileAdminUserInfo()
  7658. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7659. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7660. if err == nil {
  7661. c.ServeSuccessJSON(map[string]interface{}{
  7662. "stock_out": outInfo,
  7663. "stockCount": stockCount,
  7664. })
  7665. return
  7666. } else {
  7667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7668. return
  7669. }
  7670. }
  7671. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7672. patient_id, _ := c.GetInt64("patient_id", 0)
  7673. record_time := c.GetString("record_time")
  7674. adminUser := c.GetMobileAdminUserInfo()
  7675. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7676. if parseDateErr != nil && len(record_time) != 0 {
  7677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7678. return
  7679. }
  7680. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7681. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7682. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7683. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7684. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7685. //获取今日患者的透析处方参数
  7686. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7687. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7688. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7689. c.ServeSuccessJSON(map[string]interface{}{
  7690. "good_type": goodTypes,
  7691. "good_user": goodUser,
  7692. "good_info": good_info,
  7693. "last_good_user": lastGoodUserDetial,
  7694. "project": project,
  7695. "prescription": prescribe,
  7696. "outInfo": outInfo,
  7697. "configs": configs,
  7698. })
  7699. return
  7700. }
  7701. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7702. patient_id, _ := c.GetInt64("patient_id", 0)
  7703. record_date := c.GetString("record_time")
  7704. timeLayout := "2006-01-02"
  7705. loc, _ := time.LoadLocation("Local")
  7706. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7707. record_time := theRecordTime.Unix()
  7708. adminInfo := c.GetMobileAdminUserInfo()
  7709. dataBody := make(map[string]interface{}, 0)
  7710. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7711. if err != nil {
  7712. utils.ErrorLog(err.Error())
  7713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7714. return
  7715. }
  7716. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7717. var beforePrepares []*models.DialysisBeforePrepareGoods
  7718. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7719. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7720. goods, _ := dataBody["goods"].([]interface{})
  7721. if len(goods) > 0 {
  7722. for _, item := range goods {
  7723. items := item.(map[string]interface{})
  7724. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7725. utils.ErrorLog("good_id")
  7726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7727. return
  7728. }
  7729. good_id := int64(items["good_id"].(float64))
  7730. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7731. utils.ErrorLog("good_type_id")
  7732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7733. return
  7734. }
  7735. good_type_id := int64(items["good_type_id"].(float64))
  7736. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7737. utils.ErrorLog("count")
  7738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7739. return
  7740. }
  7741. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7742. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7743. utils.ErrorLog("project_id")
  7744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7745. return
  7746. }
  7747. project_id := int64(items["project_id"].(float64))
  7748. new_count := int64(items["new_count"].(float64))
  7749. old_count := int64(items["old_count"].(float64))
  7750. prepare := &models.DialysisBeforePrepareGoods{
  7751. GoodId: good_id,
  7752. GoodTypeId: good_type_id,
  7753. Count: count,
  7754. ProjectId: project_id,
  7755. StorehouseId: houseConfig.StorehouseOutInfo,
  7756. NewCount: new_count,
  7757. OldCount: old_count,
  7758. }
  7759. beforePrepares = append(beforePrepares, prepare)
  7760. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7761. GoodId: good_id,
  7762. GoodTypeId: good_type_id,
  7763. Count: count,
  7764. ProjectId: project_id,
  7765. StorehouseId: houseConfig.StorehouseOutInfo,
  7766. NewCount: new_count,
  7767. OldCount: old_count,
  7768. }
  7769. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7770. }
  7771. }
  7772. }
  7773. //查询是否有库存
  7774. for _, item := range beforePrepares {
  7775. if item.NewCount > 0 {
  7776. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7777. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7778. if item.Count > warehouse.Count {
  7779. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7780. c.ServeSuccessJSON(map[string]interface{}{
  7781. "message": "1",
  7782. "good_name": goodObj.GoodName,
  7783. "specification_name": goodObj.SpecificationName,
  7784. })
  7785. return
  7786. }
  7787. }
  7788. }
  7789. // 查询信息规挡的设置天数
  7790. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7791. if infor.ID > 0 && infor.WeekDay > 0 {
  7792. var cha_time int64
  7793. timeNowStr := time.Now().Format("2006-01-02")
  7794. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7795. //今日的日期减去设置的日期
  7796. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7797. if cha_time >= record_time {
  7798. //查询审核是否允许
  7799. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7800. //申请状态不允许的情况 拒绝修改
  7801. if infor.ApplicationStatus != 1 {
  7802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7803. return
  7804. }
  7805. }
  7806. }
  7807. //出库逻辑
  7808. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7809. if err != nil {
  7810. utils.ErrorLog(err.Error())
  7811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7812. return
  7813. }
  7814. finish := models.XtDialysisFinish{
  7815. IsFinish: 1,
  7816. UserOrgId: adminInfo.Org.Id,
  7817. Status: 1,
  7818. Ctime: time.Now().Unix(),
  7819. Mtime: 0,
  7820. Module: 11,
  7821. RecordDate: record_time,
  7822. Sourse: 1,
  7823. PatientId: patient_id,
  7824. }
  7825. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7826. if dialysisFinish.ID == 0 {
  7827. service.CreateDialysisFinish(finish)
  7828. }
  7829. //查询当天出库的数据
  7830. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7831. for _, item := range list {
  7832. prepare := models.DialysisBeforePrepare{
  7833. UserOrgId: item.OrgId,
  7834. PatientId: item.PatientId,
  7835. RecordDate: item.RecordTime,
  7836. GoodId: item.GoodId,
  7837. GoodTypeId: item.GoodTypeId,
  7838. Count: item.Count,
  7839. Creater: adminInfo.AdminUser.Id,
  7840. Status: 1,
  7841. Ctime: time.Now().Unix(),
  7842. ProjectId: item.ProjectId,
  7843. StorehouseId: houseConfig.StorehouseOutInfo,
  7844. }
  7845. //清空准备表的数据
  7846. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7847. //插入准备表数据
  7848. service.CreateDialysisBeforePrepareOne(&prepare)
  7849. //查询默认仓库
  7850. //查询默认仓库
  7851. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7852. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7853. var total_count int64
  7854. for _, it := range stockList {
  7855. total_count += it.StockCount
  7856. }
  7857. //基础库插入数据
  7858. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7859. ////更新剩余库存
  7860. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7861. var flush_count int64
  7862. for _, it := range goodList {
  7863. flush_count += it.StockCount
  7864. }
  7865. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7866. if errs != nil {
  7867. goodErrcode := models.XtGoodErrcode{
  7868. UserOrgId: item.OrgId,
  7869. Errcode: "手动出库更新剩余出库失败",
  7870. GoodId: item.GoodId,
  7871. Status: 1,
  7872. Ctime: time.Now().Unix(),
  7873. Mtime: 0,
  7874. Count: 0,
  7875. StockCount: 0,
  7876. Creater: adminInfo.AdminUser.Id,
  7877. BatchNumberId: 0,
  7878. WarehouseOutId: 0,
  7879. }
  7880. service.CreateGoodErrcode(goodErrcode)
  7881. }
  7882. }
  7883. //更新自动出库的地方
  7884. var errs error
  7885. if errs == nil {
  7886. c.ServeSuccessJSON(map[string]interface{}{
  7887. "msg": "修改成功",
  7888. "message": "2",
  7889. "good_name": "",
  7890. "specification_name": "",
  7891. })
  7892. return
  7893. } else {
  7894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7895. return
  7896. }
  7897. }
  7898. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7899. newArr = make([]*models.DialysisBeforePrepare, 0)
  7900. for i := 0; i < len(arr); i++ {
  7901. repeat := false
  7902. for j := i + 1; j < len(arr); j++ {
  7903. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7904. repeat = true
  7905. break
  7906. }
  7907. }
  7908. if !repeat {
  7909. newArr = append(newArr, arr[i])
  7910. }
  7911. }
  7912. return
  7913. }
  7914. func (c *DialysisAPIController) GetAllDrug() {
  7915. patient_id, _ := c.GetInt64("patient_id", 0)
  7916. adminInfo := c.GetMobileAdminUserInfo()
  7917. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7918. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7919. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7920. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7921. c.ServeSuccessJSON(map[string]interface{}{
  7922. "base_drug_config": drugStockConfig,
  7923. "private_drug_config": privateDrugConfig,
  7924. "base_drug_list": drugList,
  7925. "private_drug_list": privateDrugList,
  7926. })
  7927. }
  7928. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7929. newArr = make([]*models.DialysisBeforePrepare, 0)
  7930. for i := 0; i < len(arr); i++ {
  7931. repeat := false
  7932. for j := i + 1; j < len(arr); j++ {
  7933. if arr[i].GoodId == arr[j].GoodId {
  7934. repeat = true
  7935. break
  7936. }
  7937. }
  7938. if !repeat {
  7939. newArr = append(newArr, arr[i])
  7940. }
  7941. }
  7942. return
  7943. }
  7944. func (c *DialysisAPIController) GetDepartment() {
  7945. adminInfo := c.GetMobileAdminUserInfo()
  7946. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7947. if err == nil {
  7948. c.ServeSuccessJSON(map[string]interface{}{
  7949. "departments": departments,
  7950. })
  7951. } else {
  7952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7953. return
  7954. }
  7955. }
  7956. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7957. types, _ := c.GetInt("type", 0)
  7958. start_time := c.GetString("start_time")
  7959. end_time := c.GetString("end_time")
  7960. orgId := c.GetMobileAdminUserInfo().Org.Id
  7961. timeLayout := "2006-01-02"
  7962. loc, _ := time.LoadLocation("Local")
  7963. var startTime int64
  7964. if len(start_time) > 0 {
  7965. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7966. if err != nil {
  7967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7968. return
  7969. }
  7970. startTime = theTime.Unix()
  7971. }
  7972. var endTime int64
  7973. if len(end_time) > 0 {
  7974. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7975. if err != nil {
  7976. utils.ErrorLog(err.Error())
  7977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7978. return
  7979. }
  7980. endTime = theTime.Unix()
  7981. }
  7982. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7983. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7984. if err != nil {
  7985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7986. } else {
  7987. c.ServeSuccessJSON(map[string]interface{}{
  7988. "list": list,
  7989. "type": types,
  7990. "stockTotal": stockTotal,
  7991. })
  7992. }
  7993. }
  7994. func (c *DialysisAPIController) GetPrescriptionList() {
  7995. start_time := c.GetString("start_time")
  7996. end_time := c.GetString("end_time")
  7997. schedule_type, _ := c.GetInt64("schedule_type")
  7998. partion_id, _ := c.GetInt64("partion_id")
  7999. orgId := c.GetMobileAdminUserInfo().Org.Id
  8000. timeLayout := "2006-01-02"
  8001. loc, _ := time.LoadLocation("Local")
  8002. var startTime int64
  8003. if len(start_time) > 0 {
  8004. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8005. if err != nil {
  8006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8007. return
  8008. }
  8009. startTime = theTime.Unix()
  8010. }
  8011. var endTime int64
  8012. if len(end_time) > 0 {
  8013. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8014. if err != nil {
  8015. utils.ErrorLog(err.Error())
  8016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8017. return
  8018. }
  8019. endTime = theTime.Unix()
  8020. }
  8021. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  8022. fmt.Println("schedulelist22222222", schedulelist)
  8023. c.ServeSuccessJSON(map[string]interface{}{
  8024. "list": schedulelist,
  8025. })
  8026. return
  8027. }
  8028. func (c *DialysisAPIController) BatchDeleteMonitor() {
  8029. ids := c.GetString("ids")
  8030. //patient_id, _ := c.GetInt64("patient_id")
  8031. //monitoring_date, _ := c.GetInt64("monitoring_date")
  8032. idArray := strings.Split(ids, ",")
  8033. err := service.BatchDeleteMonitor(idArray)
  8034. fmt.Print("err", err)
  8035. //orgid := c.GetMobileAdminUserInfo().Org.Id
  8036. //redis := service.RedisClient()
  8037. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  8038. //redis.Set(key, "", time.Second)
  8039. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  8040. //redis.Set(keyOne, "", time.Second)
  8041. //fmt.Println("keyo呢32332322332332232332",keyOne)
  8042. //redis.Close()
  8043. c.ServeSuccessJSON(map[string]interface{}{
  8044. "msg": "批量删除成功",
  8045. })
  8046. return
  8047. }
  8048. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  8049. id, _ := c.GetInt64("id")
  8050. timeLayout := "2006-01-02"
  8051. loc, _ := time.LoadLocation("Local")
  8052. //start_time := time.Now().Format("2006-01-02")
  8053. start_time := c.GetString("start_time")
  8054. end_time := c.GetString("end_time")
  8055. var startdateunix int64
  8056. if len(start_time) > 0 {
  8057. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8058. if err != nil {
  8059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8060. return
  8061. }
  8062. startdateunix = theTime.Unix()
  8063. }
  8064. var enddateunix int64
  8065. if len(end_time) > 0 {
  8066. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8067. if err != nil {
  8068. utils.ErrorLog(err.Error())
  8069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8070. return
  8071. }
  8072. enddateunix = theTime.Unix()
  8073. }
  8074. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8075. //nowTime := time.Now()
  8076. //endTime := nowTime.AddDate(-30, 0, 0)
  8077. //endTimes := endTime.Format("2006-01-02")
  8078. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8079. org_id := c.GetMobileAdminUserInfo().Org.Id
  8080. //if org_id == 10579 {
  8081. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8082. // c.ServeSuccessJSON(map[string]interface{}{
  8083. // "list": list,
  8084. // })
  8085. // return
  8086. //} else {
  8087. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8088. // c.ServeSuccessJSON(map[string]interface{}{
  8089. // "list": list,
  8090. // })
  8091. // return
  8092. //}
  8093. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  8094. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8095. c.ServeSuccessJSON(map[string]interface{}{
  8096. "list": list,
  8097. })
  8098. return
  8099. } else {
  8100. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8101. c.ServeSuccessJSON(map[string]interface{}{
  8102. "list": list,
  8103. })
  8104. }
  8105. return
  8106. }
  8107. func (c *DialysisAPIController) BathDeleteAdviceList() {
  8108. dataBody := make(map[string]interface{}, 0)
  8109. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8110. ids := c.GetString("ids")
  8111. idArray := strings.Split(ids, ",")
  8112. origin, _ := c.GetInt64("origin")
  8113. if origin == 1 {
  8114. err = service.BatchDeleteAdvice(idArray)
  8115. fmt.Print("err", err)
  8116. c.ServeSuccessJSON(map[string]interface{}{
  8117. "msg": "批量删除成功",
  8118. })
  8119. return
  8120. }
  8121. if origin == 2 {
  8122. service.BatchDeleteHisAdvice(idArray)
  8123. }
  8124. }
  8125. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  8126. good_id, _ := c.GetInt64("good_id")
  8127. count, _ := c.GetInt64("count")
  8128. record_time, _ := c.GetInt64("record_time")
  8129. patient_id, _ := c.GetInt64("patient_id")
  8130. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  8131. c.ServeSuccessJSON(map[string]interface{}{
  8132. "detail": detail,
  8133. })
  8134. return
  8135. }
  8136. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  8137. good_id, _ := c.GetInt64("good_id")
  8138. record_time, _ := c.GetInt64("record_time")
  8139. patient_id, _ := c.GetInt64("patient_id")
  8140. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8141. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8142. fmt.Print("err", err)
  8143. c.ServeSuccessJSON(map[string]interface{}{
  8144. "msg": "批量删除成功",
  8145. })
  8146. return
  8147. }
  8148. func (c *DialysisAPIController) BatchAdviceCheck() {
  8149. ids := c.GetString("ids")
  8150. idArray := strings.Split(ids, ",")
  8151. creator, _ := c.GetInt64("creator")
  8152. origin, _ := c.GetInt64("origin")
  8153. if origin == 1 {
  8154. err := service.BatchAdviceCheck(idArray, creator)
  8155. fmt.Println(err)
  8156. list, _ := service.GetAdviceExecutionById(idArray)
  8157. c.ServeSuccessJSON(map[string]interface{}{
  8158. "list": list,
  8159. })
  8160. return
  8161. }
  8162. if origin == 2 {
  8163. service.BatchHisAdviceCheck(idArray, creator)
  8164. list, _ := service.GetHisAdviceExecutionById(idArray)
  8165. c.ServeSuccessJSON(map[string]interface{}{
  8166. "list": list,
  8167. })
  8168. return
  8169. }
  8170. }
  8171. func (c *DialysisAPIController) BatchAdviceExecution() {
  8172. ids := c.GetString("ids")
  8173. idArray := strings.Split(ids, ",")
  8174. executionTime := c.GetString("execution_time")
  8175. creator, _ := c.GetInt64("creator")
  8176. timeLayout := "2006-01-02 15:04:05"
  8177. loc, _ := time.LoadLocation("Local")
  8178. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8179. orgin, _ := c.GetInt64("origin")
  8180. if orgin == 1 {
  8181. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8182. list, _ := service.GetAdviceExecutionById(idArray)
  8183. fmt.Println(err)
  8184. c.ServeSuccessJSON(map[string]interface{}{
  8185. "list": list,
  8186. })
  8187. return
  8188. }
  8189. if orgin == 2 {
  8190. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8191. list, _ := service.GetHisAdviceExecutionById(idArray)
  8192. fmt.Println(err)
  8193. c.ServeSuccessJSON(map[string]interface{}{
  8194. "list": list,
  8195. })
  8196. return
  8197. }
  8198. }
  8199. func (c *DialysisAPIController) UpdateStockGoods() {
  8200. good_id, _ := c.GetInt64("good_id")
  8201. record_time, _ := c.GetInt64("record_time")
  8202. patient_id, _ := c.GetInt64("patient_id")
  8203. count, _ := c.GetInt64("count")
  8204. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8205. fmt.Print("err", err)
  8206. c.ServeSuccessJSON(map[string]interface{}{
  8207. "msg": "更新成功",
  8208. })
  8209. return
  8210. }
  8211. // 当前数据比上一次出库数据少
  8212. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8213. //查询该患者当天已经出库的耗材信息
  8214. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8215. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8216. for i := len(goods_yc) - 1; i >= 0; i-- {
  8217. goods_yc_temp := goods_yc[i]
  8218. for j := len(goods) - 1; j >= 0; j-- {
  8219. goods_temp := goods[j]
  8220. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8221. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8222. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8223. if goods_yc_temp.Count == goods_temp.Count {
  8224. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8225. goods = append(goods[:j], goods[j+1:]...)
  8226. break
  8227. }
  8228. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8229. if goods_yc_temp.Count > goods_temp.Count {
  8230. temp_count := goods_yc_temp.Count - goods_temp.Count
  8231. goods_yc[i].Count = temp_count
  8232. goods = append(goods[:j], goods[j+1:]...)
  8233. break
  8234. }
  8235. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8236. if goods_yc_temp.Count < goods_temp.Count {
  8237. temp_count := goods_temp.Count - goods_yc_temp.Count
  8238. goods[j].Count = temp_count
  8239. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8240. break
  8241. }
  8242. }
  8243. }
  8244. }
  8245. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8246. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8247. //退库
  8248. if len(goods_yc) > 0 {
  8249. for _, good_yc := range goods_yc {
  8250. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8251. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8252. }
  8253. }
  8254. return nil
  8255. }
  8256. // 耗材出库删除
  8257. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8258. // 先根据相关信息查询当天该耗材的出库信息
  8259. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8260. if err != nil {
  8261. return err
  8262. }
  8263. var delete_count int64 = 0
  8264. delete_count = warehouseOutInfos.Count - count
  8265. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8266. // 在出库记录表里记录退库详情
  8267. warehouseOutInfo := &models.WarehouseOutInfo{
  8268. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8269. WarehouseOutId: warehouseOut.ID,
  8270. Status: 1,
  8271. Ctime: time.Now().Unix(),
  8272. OrgId: orgID,
  8273. Type: 1,
  8274. IsSys: 1,
  8275. SysRecordTime: record_time,
  8276. GoodTypeId: good_yc.GoodTypeId,
  8277. GoodId: good_yc.GoodId,
  8278. PatientId: good_yc.PatientId,
  8279. ConsumableType: 2,
  8280. StorehouseId: houseConfig.StorehouseOutInfo,
  8281. IsCheck: 1,
  8282. }
  8283. warehouseOutInfo.Count = count
  8284. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8285. warehouseOutInfo.Price = stockInInfo.Price
  8286. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8287. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8288. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8289. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8290. warehouseOutInfo.Number = warehouseOutInfos.Number
  8291. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8292. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8293. //查找当天是否存在出库记录
  8294. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8295. if errcod == gorm.ErrRecordNotFound {
  8296. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8297. //插入详情明细表
  8298. stockFlow := models.VmStockFlow{
  8299. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8300. WarehouseOutId: warehouseOut.ID,
  8301. GoodId: good_yc.GoodId,
  8302. Number: warehouseOutInfos.Number,
  8303. ProductDate: stockInInfo.ProductDate,
  8304. ExpireDate: stockInInfo.ExpiryDate,
  8305. Count: count,
  8306. Price: stockInInfo.Price,
  8307. Status: 1,
  8308. Ctime: time.Now().Unix(),
  8309. UserOrgId: good_yc.OrgId,
  8310. Manufacturer: stockInInfo.Manufacturer,
  8311. Dealer: stockInInfo.Dealer,
  8312. LicenseNumber: stockInInfo.LicenseNumber,
  8313. IsEdit: 2,
  8314. Creator: creater,
  8315. SystemTime: record_time,
  8316. ConsumableType: 3,
  8317. WarehousingDetailId: 0,
  8318. IsSys: 1,
  8319. UpdateCreator: creater,
  8320. PatientId: patient_id,
  8321. StorehouseId: houseConfig.StorehouseOutInfo,
  8322. }
  8323. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8324. if errflow == gorm.ErrRecordNotFound {
  8325. //创建流水表
  8326. err := service.CreateStockFlowOne(stockFlow)
  8327. fmt.Println("err", err)
  8328. } else if errflow == nil {
  8329. //插入详情明细表
  8330. stockFlow := models.VmStockFlow{
  8331. ID: exsit.ID,
  8332. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8333. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8334. WarehouseOutId: warehouseOut.ID,
  8335. GoodId: good_yc.GoodId,
  8336. Number: warehouseOutInfos.Number,
  8337. ProductDate: stockInInfo.ProductDate,
  8338. ExpireDate: stockInInfo.ExpiryDate,
  8339. Count: exsit.Count - delete_count,
  8340. Price: stockInInfo.Price,
  8341. Status: 1,
  8342. Ctime: time.Now().Unix(),
  8343. UserOrgId: good_yc.OrgId,
  8344. Manufacturer: stockInInfo.Manufacturer,
  8345. Dealer: stockInInfo.Dealer,
  8346. LicenseNumber: stockInInfo.LicenseNumber,
  8347. IsEdit: 2,
  8348. Creator: creater,
  8349. SystemTime: record_time,
  8350. ConsumableType: 3,
  8351. WarehousingDetailId: 0,
  8352. IsSys: 1,
  8353. UpdateCreator: creater,
  8354. PatientId: patient_id,
  8355. StorehouseId: houseConfig.StorehouseOutInfo,
  8356. }
  8357. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8358. }
  8359. if errOne != nil {
  8360. return errOne
  8361. }
  8362. } else if errcod == nil {
  8363. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8364. //插入详情明细表
  8365. stockFlow := models.VmStockFlow{
  8366. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8367. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8368. WarehouseOutId: warehouseOut.ID,
  8369. GoodId: good_yc.GoodId,
  8370. Number: warehouseOutInfos.Number,
  8371. ProductDate: stockInInfo.ProductDate,
  8372. ExpireDate: stockInInfo.ExpiryDate,
  8373. Count: count,
  8374. Price: stockInInfo.Price,
  8375. Status: 1,
  8376. Ctime: time.Now().Unix(),
  8377. UserOrgId: good_yc.OrgId,
  8378. Manufacturer: stockInInfo.Manufacturer,
  8379. Dealer: stockInInfo.Dealer,
  8380. LicenseNumber: stockInInfo.LicenseNumber,
  8381. IsEdit: 2,
  8382. Creator: creater,
  8383. SystemTime: record_time,
  8384. ConsumableType: 3,
  8385. WarehousingDetailId: 0,
  8386. IsSys: 1,
  8387. UpdateCreator: creater,
  8388. PatientId: patient_id,
  8389. ReturnCount: delete_count,
  8390. StorehouseId: houseConfig.StorehouseOutInfo,
  8391. }
  8392. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8393. if errflows == gorm.ErrRecordNotFound {
  8394. //创建流水表
  8395. service.CreateStockFlowOne(stockFlow)
  8396. } else if errflows == nil {
  8397. stockFlow := models.VmStockFlow{
  8398. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8399. ID: exsit.ID,
  8400. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8401. WarehouseOutId: warehouseOut.ID,
  8402. GoodId: good_yc.GoodId,
  8403. Number: warehouseOutInfos.Number,
  8404. ProductDate: stockInInfo.ProductDate,
  8405. ExpireDate: stockInInfo.ExpiryDate,
  8406. Count: exsit.Count - delete_count,
  8407. Price: stockInInfo.Price,
  8408. Status: 1,
  8409. Ctime: time.Now().Unix(),
  8410. UserOrgId: good_yc.OrgId,
  8411. Manufacturer: stockInInfo.Manufacturer,
  8412. Dealer: stockInInfo.Dealer,
  8413. LicenseNumber: stockInInfo.LicenseNumber,
  8414. IsEdit: 2,
  8415. Creator: creater,
  8416. SystemTime: record_time,
  8417. ConsumableType: 3,
  8418. WarehousingDetailId: 0,
  8419. IsSys: 1,
  8420. UpdateCreator: creater,
  8421. PatientId: patient_id,
  8422. ReturnCount: delete_count,
  8423. StorehouseId: houseConfig.StorehouseOutInfo,
  8424. }
  8425. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8426. }
  8427. }
  8428. //更改自动出库的表格
  8429. details := models.BloodAutomaticReduceDetail{
  8430. WarehouseOutId: warehouseOutInfo.ID,
  8431. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8432. PatientId: patient_id,
  8433. Ctime: time.Now().Unix(),
  8434. Mtime: time.Now().Unix(),
  8435. Status: 1,
  8436. RecordTime: record_time,
  8437. OrgId: orgID,
  8438. GoodId: good_yc.GoodId,
  8439. GoodTypeId: good_yc.GoodTypeId,
  8440. Count: count,
  8441. StorehouseId: houseConfig.StorehouseOutInfo,
  8442. }
  8443. //查询当天耗材是否已经存在数据
  8444. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8445. if errcode == gorm.ErrRecordNotFound {
  8446. errTwo := service.CreateAutoReduceRecord(&details)
  8447. if errTwo != nil {
  8448. return errTwo
  8449. }
  8450. } else if errcode == nil {
  8451. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8452. service.CreateAutoReduceRecord(&details)
  8453. }
  8454. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8455. //增加出库库存数量
  8456. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8457. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8458. fmt.Println("errOne", errOne)
  8459. // 删除出库完成后,要增加对应批次的库存数量
  8460. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8461. if errThree != nil {
  8462. return errThree
  8463. }
  8464. if good_yc.Count == 0 {
  8465. return nil
  8466. } else {
  8467. return errors.New("退库和出库数据不匹配")
  8468. }
  8469. }
  8470. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8471. //查询该患者当天已经出库的耗材信息
  8472. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8473. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8474. for i := len(goods_yc) - 1; i >= 0; i-- {
  8475. goods_yc_temp := goods_yc[i]
  8476. for j := len(goods) - 1; j >= 0; j-- {
  8477. goods_temp := goods[j]
  8478. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8479. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8480. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8481. if goods_yc_temp.Count == goods_temp.Count {
  8482. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8483. goods = append(goods[:j], goods[j+1:]...)
  8484. break
  8485. }
  8486. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8487. if goods_yc_temp.Count > goods_temp.Count {
  8488. temp_count := goods_yc_temp.Count - goods_temp.Count
  8489. goods_yc[i].Count = temp_count
  8490. goods = append(goods[:j], goods[j+1:]...)
  8491. break
  8492. }
  8493. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8494. if goods_yc_temp.Count < goods_temp.Count {
  8495. temp_count := goods_temp.Count - goods_yc_temp.Count
  8496. goods[j].Count = temp_count
  8497. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8498. break
  8499. }
  8500. }
  8501. }
  8502. }
  8503. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8504. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8505. fmt.Println("剩余需要出库的", len(goods))
  8506. if len(goods) > 0 {
  8507. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8508. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8509. if err == gorm.ErrRecordNotFound {
  8510. //没有记录,则创建出库单
  8511. timeStr := time.Now().Format("2006-01-02")
  8512. timeArr := strings.Split(timeStr, "-")
  8513. total, _ := service.FindAllWarehouseOut(orgID)
  8514. total = total + 1
  8515. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8516. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8517. number = number + total
  8518. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8519. warehouseOut := models.WarehouseOut{
  8520. WarehouseOutOrderNumber: warehousing_out_order,
  8521. OperationTime: time.Now().Unix(),
  8522. OrgId: orgID,
  8523. Creater: creater,
  8524. Ctime: time.Now().Unix(),
  8525. Status: 1,
  8526. WarehouseOutTime: record_time,
  8527. Dealer: 0,
  8528. Manufacturer: 0,
  8529. Type: 1,
  8530. IsSys: 1,
  8531. StorehouseId: houseConfig.StorehouseOutInfo,
  8532. IsCheck: 1,
  8533. }
  8534. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  8535. if err != nil {
  8536. utils.TraceLog("创建出库单失败 err = %v", err)
  8537. return err
  8538. } else {
  8539. out = warehouseOut
  8540. }
  8541. }
  8542. for _, item := range goods {
  8543. var newCount int64 = 0
  8544. for _, it := range goodOne {
  8545. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8546. newCount = it.Count
  8547. }
  8548. }
  8549. prepare := models.DialysisBeforePrepare{
  8550. GoodTypeId: item.GoodTypeId,
  8551. GoodId: item.GoodId,
  8552. Count: item.Count,
  8553. StorehouseId: houseConfig.StorehouseOutInfo,
  8554. }
  8555. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8556. //增加出库数量
  8557. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8558. }
  8559. }
  8560. if len(goods_yc) > 0 {
  8561. for _, good_yc := range goods_yc {
  8562. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8563. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8564. }
  8565. }
  8566. return nil
  8567. }
  8568. // 耗材出库删除
  8569. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8570. // 先根据相关信息查询当天该耗材的出库信息
  8571. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8572. if err != nil {
  8573. return err
  8574. }
  8575. var delete_count int64 = 0
  8576. for _, ware := range warehouseOutInfos {
  8577. // 判断当前出库的数据和删除出库数量
  8578. if good_yc.Count <= ware.Count {
  8579. delete_count = good_yc.Count
  8580. } else {
  8581. delete_count = ware.Count
  8582. }
  8583. warehouseOutInfo := &models.WarehouseOutInfo{
  8584. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8585. WarehouseOutId: warehouseOut.ID,
  8586. Status: 1,
  8587. Ctime: time.Now().Unix(),
  8588. Remark: "",
  8589. OrgId: orgID,
  8590. Type: 1,
  8591. Manufacturer: 0,
  8592. Dealer: 0,
  8593. IsSys: 0,
  8594. SysRecordTime: record_time,
  8595. GoodTypeId: good_yc.GoodTypeId,
  8596. GoodId: good_yc.GoodId,
  8597. StorehouseId: warehouseOut.StorehouseId,
  8598. IsCheck: 1,
  8599. }
  8600. warehouseOutInfo.Count = delete_count
  8601. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8602. warehouseOutInfo.Price = stockInInfo.Price
  8603. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8604. if errOne != nil {
  8605. return errOne
  8606. }
  8607. // 删除出库完成后,要改变流水库存(有疑问)
  8608. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8609. fmt.Println("errOne", errOne)
  8610. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8611. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8612. //扣减出库数量
  8613. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8614. if errThree != nil {
  8615. return errThree
  8616. }
  8617. }
  8618. if good_yc.Count == 0 {
  8619. return nil
  8620. } else {
  8621. return errors.New("退库和出库数据不匹配")
  8622. }
  8623. }
  8624. func (this *DialysisAPIController) GetMobileScheduleList() {
  8625. limit, _ := this.GetInt64("limit")
  8626. page, _ := this.GetInt64("page")
  8627. type_options_visible, _ := this.GetInt64("type_options_visible")
  8628. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8629. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8630. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8631. }
  8632. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8633. newArr = make([]*models.HisPrescriptionProject, 0)
  8634. for i := 0; i < len(arr); i++ {
  8635. repeat := false
  8636. for j := i + 1; j < len(arr); j++ {
  8637. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8638. repeat = true
  8639. break
  8640. }
  8641. }
  8642. if !repeat {
  8643. newArr = append(newArr, arr[i])
  8644. }
  8645. }
  8646. return
  8647. }
  8648. func (this *DialysisAPIController) GetRoleList() {
  8649. admin_user_id, _ := this.GetInt64("admin_user_id")
  8650. orgid := this.GetMobileAdminUserInfo().Org.Id
  8651. list, err := service.GetRoleList(orgid, admin_user_id)
  8652. fmt.Println(err)
  8653. this.ServeSuccessJSON(map[string]interface{}{
  8654. "list": list,
  8655. })
  8656. return
  8657. }
  8658. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8659. // 先根据相关信息查询当天该耗材的出库信息
  8660. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8661. if err != nil {
  8662. return err
  8663. }
  8664. var delete_count int64 = 0
  8665. delete_count = warehouseOutInfos.Count - count
  8666. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8667. // 删除出库完成后,要增加对应批次的库存数量
  8668. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8669. if errThree != nil {
  8670. return errThree
  8671. }
  8672. //增加退库数量
  8673. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8674. //扣减出库数量
  8675. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8676. //查询剩余库存
  8677. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8678. var sum_count int64
  8679. for _, item := range goodList {
  8680. sum_count += item.StockCount
  8681. }
  8682. // 在出库记录表里记录退库详情
  8683. warehouseOutInfo := &models.WarehouseOutInfo{
  8684. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8685. WarehouseOutId: warehouseOut.ID,
  8686. Status: 1,
  8687. Ctime: time.Now().Unix(),
  8688. OrgId: orgID,
  8689. Type: 1,
  8690. IsSys: 1,
  8691. SysRecordTime: record_time,
  8692. GoodTypeId: good_yc.GoodTypeId,
  8693. GoodId: good_yc.GoodId,
  8694. PatientId: good_yc.PatientId,
  8695. ConsumableType: 2,
  8696. StorehouseId: houseConfig.StorehouseOutInfo,
  8697. IsCheck: 1,
  8698. OverCount: sum_count,
  8699. }
  8700. warehouseOutInfo.Count = count
  8701. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8702. warehouseOutInfo.Price = stockInInfo.Price
  8703. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8704. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8705. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8706. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8707. warehouseOutInfo.Number = warehouseOutInfos.Number
  8708. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8709. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8710. //查找当天是否存在出库记录
  8711. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8712. if errcod == gorm.ErrRecordNotFound {
  8713. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8714. //插入详情明细表
  8715. if errOne != nil {
  8716. return errOne
  8717. }
  8718. //插入详情明细表
  8719. stockFlow := models.VmStockFlow{
  8720. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8721. WarehouseOutId: warehouseOut.ID,
  8722. GoodId: good_yc.GoodId,
  8723. Number: warehouseOutInfos.Number,
  8724. ProductDate: stockInInfo.ProductDate,
  8725. ExpireDate: stockInInfo.ExpiryDate,
  8726. Count: count,
  8727. Price: stockInInfo.Price,
  8728. Status: 1,
  8729. Ctime: record_time,
  8730. UserOrgId: good_yc.OrgId,
  8731. Manufacturer: stockInInfo.Manufacturer,
  8732. Dealer: stockInInfo.Dealer,
  8733. LicenseNumber: stockInInfo.LicenseNumber,
  8734. IsEdit: 2,
  8735. Creator: creater,
  8736. SystemTime: record_time,
  8737. ConsumableType: 3,
  8738. WarehousingDetailId: 0,
  8739. IsSys: 1,
  8740. UpdateCreator: creater,
  8741. PatientId: patient_id,
  8742. StorehouseId: houseConfig.StorehouseOutInfo,
  8743. OverCount: sum_count,
  8744. ProjectId: good_yc.ProjectId,
  8745. }
  8746. err := service.CreateStockFlowOne(stockFlow)
  8747. fmt.Println("err", err)
  8748. } else if errcod == nil {
  8749. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8750. }
  8751. //创建退库单
  8752. operation_time := time.Now().Unix()
  8753. //创建退库单
  8754. timeStr := time.Now().Format("2006-01-02")
  8755. timeArr := strings.Split(timeStr, "-")
  8756. total, _ := service.FindAllCancelStockTotal(orgID)
  8757. total = total + 1
  8758. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8759. cancelStock := models.CancelStock{
  8760. OrderNumber: orderNumber,
  8761. OperaTime: operation_time,
  8762. OrgId: orgID,
  8763. Creater: warehouseOut.Creater,
  8764. Ctime: time.Now().Unix(),
  8765. Status: 1,
  8766. ReturnTime: record_time,
  8767. Type: 1,
  8768. StorehouseId: stockInInfo.StorehouseId,
  8769. IsCheck: 1,
  8770. }
  8771. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8772. if msgerrkonde == gorm.ErrRecordNotFound {
  8773. service.AddSigleCancelStock(&cancelStock)
  8774. }
  8775. cancel, _ := service.GetLastCancelStockById(orgID)
  8776. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8777. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8778. cancelStockInfo := models.CancelStockInfo{
  8779. GoodId: stockInInfo.GoodId,
  8780. CancelStockId: cancel.ID,
  8781. GoodTypeId: stockInInfo.GoodTypeId,
  8782. Count: delete_count,
  8783. Price: stockInInfo.PackingPrice,
  8784. Total: 0,
  8785. ProductDate: stockInInfo.ProductDate,
  8786. ExpiryDate: stockInInfo.ExpiryDate,
  8787. Ctime: record_time,
  8788. Status: 1,
  8789. OrgId: orgID,
  8790. OrderNumber: cancel.OrderNumber,
  8791. Type: 0,
  8792. Dealer: deaerler.DealerName,
  8793. Manufacturer: manufacturer.ManufacturerName,
  8794. Number: stockInInfo.Number,
  8795. RegisterAccount: "",
  8796. Remark: "",
  8797. WarehouseInfoId: stockInInfo.ID,
  8798. PatientId: patient_id,
  8799. RecordDate: record_time,
  8800. StorehouseId: stockInInfo.StorehouseId,
  8801. IsCheck: 1,
  8802. }
  8803. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8804. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8805. flow := models.VmStockFlow{
  8806. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8807. GoodId: good_yc.GoodId,
  8808. Number: warehouseOutInfos.Number,
  8809. LicenseNumber: stockInInfo.LicenseNumber,
  8810. Count: delete_count,
  8811. UserOrgId: orgID,
  8812. PatientId: patient_id,
  8813. SystemTime: record_time,
  8814. ConsumableType: 7,
  8815. IsSys: 0,
  8816. WarehousingOrder: "",
  8817. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8818. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8819. IsEdit: 0,
  8820. CancelStockId: cancel.ID,
  8821. CancelOrderNumber: cancel.OrderNumber,
  8822. Manufacturer: manufacturer.ID,
  8823. Dealer: 0,
  8824. Creator: warehouseOut.Creater,
  8825. UpdateCreator: 0,
  8826. Status: 1,
  8827. Ctime: record_time,
  8828. Mtime: 0,
  8829. Price: stockInInfo.Price,
  8830. WarehousingDetailId: stockInInfo.ID,
  8831. WarehouseOutDetailId: warehouseOutInfos.ID,
  8832. CancelOutDetailId: cancelInfo.ID,
  8833. ProductDate: stockInInfo.ProductDate,
  8834. ExpireDate: stockInInfo.ExpiryDate,
  8835. StorehouseId: houseConfig.StorehouseOutInfo,
  8836. OverCount: sum_count,
  8837. }
  8838. service.CreateStockFlowOne(flow)
  8839. //更改自动出库的表格
  8840. details := models.BloodAutomaticReduceDetail{
  8841. WarehouseOutId: warehouseOutInfo.ID,
  8842. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8843. PatientId: patient_id,
  8844. Ctime: time.Now().Unix(),
  8845. Mtime: time.Now().Unix(),
  8846. Status: 1,
  8847. RecordTime: record_time,
  8848. OrgId: orgID,
  8849. GoodId: good_yc.GoodId,
  8850. GoodTypeId: good_yc.GoodTypeId,
  8851. Count: count,
  8852. StorehouseId: houseConfig.StorehouseOutInfo,
  8853. }
  8854. //查询当天耗材是否已经存在数据
  8855. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8856. if errcode == gorm.ErrRecordNotFound {
  8857. errTwo := service.CreateAutoReduceRecord(&details)
  8858. if errTwo != nil {
  8859. return errTwo
  8860. }
  8861. } else if errcode == nil {
  8862. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8863. service.CreateAutoReduceRecord(&details)
  8864. }
  8865. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8866. //增加出库库存数量
  8867. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8868. if good_yc.Count == 0 {
  8869. return nil
  8870. } else {
  8871. return errors.New("退库和出库数据不匹配")
  8872. }
  8873. }
  8874. func (this *DialysisAPIController) SavePatientSign() {
  8875. adminUserInfo := this.GetMobileAdminUserInfo()
  8876. patient_id, _ := this.GetInt64("patient_id")
  8877. dialysis_date, _ := this.GetInt64("dialysis_date")
  8878. orgid := adminUserInfo.Org.Id
  8879. var esdata models.DialysisOrder
  8880. var err error
  8881. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8882. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8883. return
  8884. }
  8885. esdata.Hash = esdata.Hash
  8886. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8887. order := models.DialysisOrder{
  8888. Hash: esdata.Hash,
  8889. Url: esdata.Url,
  8890. }
  8891. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8892. redis := service.RedisClient()
  8893. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8894. redis.Set(key, "", time.Second)
  8895. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8896. //清空key 值
  8897. redis.Set(keyOne, "", time.Second)
  8898. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8899. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8900. //redis.Set(keyTwo, "", time.Second)
  8901. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8902. redis.Set(keyThree, "", time.Second)
  8903. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8904. redis.Set(keyFour, "", time.Second)
  8905. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8906. redis.Set(keyFive, "", time.Second)
  8907. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8908. redis.Set(keySix, "", time.Second)
  8909. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8910. redis.Set(keySeven, "", time.Second)
  8911. if err != nil {
  8912. fmt.Println(err)
  8913. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8914. return
  8915. }
  8916. this.ServeSuccessJSON(map[string]interface{}{
  8917. "electronic_signature": esdata,
  8918. })
  8919. }
  8920. func (this *DialysisAPIController) GetPatientSign() {
  8921. patient_id, _ := this.GetInt64("patient_id")
  8922. dialysis_date, _ := this.GetInt64("dialysis_date")
  8923. adminUserInfo := this.GetMobileAdminUserInfo()
  8924. orgId := adminUserInfo.Org.Id
  8925. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8926. if err != nil {
  8927. fmt.Println(err)
  8928. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8929. return
  8930. }
  8931. this.ServeSuccessJSON(map[string]interface{}{
  8932. "dialysisOrder": dialysisOrder,
  8933. })
  8934. }
  8935. func (this *DialysisAPIController) GetScheduleByPatient() {
  8936. patient_id, _ := this.GetInt64("patient_id")
  8937. schedule_date, _ := this.GetInt64("schedule_date")
  8938. orgid := this.GetMobileAdminUserInfo().Org.Id
  8939. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8940. this.ServeSuccessJSON(map[string]interface{}{
  8941. "schedule": schedule,
  8942. })
  8943. }
  8944. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8945. org_id := this.GetMobileAdminUserInfo().Org.Id
  8946. patient_id, _ := this.GetInt64("patient_id")
  8947. schedule_date, _ := this.GetInt64("schedule_date")
  8948. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8949. this.ServeSuccessJSON(map[string]interface{}{
  8950. "order": order,
  8951. })
  8952. }
  8953. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8954. org_id := this.GetMobileAdminUserInfo().Org.Id
  8955. schedule_date := this.GetString("schedule_date")
  8956. schedule_type, _ := this.GetInt64("schedule_type")
  8957. timeLayout := "2006-01-02"
  8958. loc, _ := time.LoadLocation("Local")
  8959. var startdateunix int64
  8960. if len(schedule_date) > 0 {
  8961. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8962. if err != nil {
  8963. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8964. return
  8965. }
  8966. startdateunix = theTime.Unix()
  8967. }
  8968. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8969. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8970. devices, _ := service.GetAllDevicetByListSix(org_id)
  8971. for key, item := range scheduals {
  8972. // 床位信息
  8973. for _, device := range devices {
  8974. if item.BedId == device.ID {
  8975. scheduals[key].DeviceNumber = device
  8976. break
  8977. }
  8978. }
  8979. }
  8980. this.ServeSuccessJSON(map[string]interface{}{
  8981. "list": list,
  8982. "scheduals": scheduals,
  8983. })
  8984. }
  8985. func (this *DialysisAPIController) SavePatientPicture() {
  8986. patient_id, _ := this.GetInt64("patient_id")
  8987. dialysis_date, _ := this.GetInt64("schedule_date")
  8988. avatar := this.GetString("avatar")
  8989. fmt.Println("patient_id", patient_id)
  8990. orgId := this.GetMobileAdminUserInfo().Org.Id
  8991. order := models.DialysisOrder{
  8992. Url: avatar,
  8993. }
  8994. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8995. redis := service.RedisClient()
  8996. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8997. redis.Set(key, "", time.Second)
  8998. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8999. //清空key 值
  9000. redis.Set(keyOne, "", time.Second)
  9001. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9002. redis.Set(keyThree, "", time.Second)
  9003. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9004. redis.Set(keyFour, "", time.Second)
  9005. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9006. redis.Set(keyFive, "", time.Second)
  9007. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9008. redis.Set(keySix, "", time.Second)
  9009. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  9010. redis.Set(keySeven, "", time.Second)
  9011. if err != nil {
  9012. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9013. return
  9014. }
  9015. this.ServeSuccessJSON(map[string]interface{}{
  9016. "order": order,
  9017. })
  9018. }
  9019. func (this *DialysisAPIController) ExectionMobileAdvice() {
  9020. ids := this.GetString("ids")
  9021. idSplit := strings.Split(ids, ",")
  9022. orgId := this.GetMobileAdminUserInfo().Org.Id
  9023. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9024. execution_time := this.GetString("exce_time")
  9025. timeLayout2 := "2006-01-02 15:04:05"
  9026. loc, _ := time.LoadLocation("Local")
  9027. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  9028. if errs != nil {
  9029. utils.ErrorLog(errs.Error())
  9030. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9031. return
  9032. }
  9033. //his客户
  9034. if config.IsOpen == 1 {
  9035. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  9036. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  9037. for _, item := range list {
  9038. for _, it := range adviceList {
  9039. if item.DrugId == it.DrugId {
  9040. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9041. }
  9042. }
  9043. }
  9044. for _, item := range list {
  9045. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9046. var sum_out_count int64
  9047. for _, itemThree := range item.ChildDoctorAdvice {
  9048. var prescribing_number int64
  9049. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9050. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9051. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9052. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9053. }
  9054. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9055. prescribing_number = parseIntPrescribingNumber
  9056. }
  9057. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9058. prescribing_number = parseIntPrescribingNumber
  9059. }
  9060. sum_out_count += prescribing_number
  9061. }
  9062. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9063. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9064. //库存不足
  9065. if sum_out_count > drugStockOut.FlushCount {
  9066. this.ServeSuccessJSON(map[string]interface{}{
  9067. "msg": "2",
  9068. "drug": medical,
  9069. "ids": ids,
  9070. })
  9071. return
  9072. }
  9073. }
  9074. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9075. //执行医嘱
  9076. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9077. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  9078. for _, item := range advices {
  9079. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9080. redis := service.RedisClient()
  9081. //清空key 值
  9082. redis.Set(key, "", time.Second)
  9083. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9084. redis.Set(keyTwo, "", time.Second)
  9085. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9086. redis.Set(keyThree, "", time.Second)
  9087. recordDate := theTime.Format("2006-01-02")
  9088. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9089. redis.Set(keyFour, "", time.Second)
  9090. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9091. redis.Set(keyFive, "", time.Second)
  9092. defer redis.Close()
  9093. }
  9094. if errs == nil {
  9095. //药品管理信息
  9096. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9097. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9098. if drugStockConfig.IsOpen == 1 {
  9099. for _, item := range advices {
  9100. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  9101. config, _ := service.GetDrugOpenConfigOne(orgId)
  9102. if config.IsOpen != 1 {
  9103. //查询该药品是否有库存
  9104. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9105. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  9106. if medical.IsUse == 2 {
  9107. if config.IsOpen != 1 {
  9108. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9109. service.HisDrugsDelivery(orgId, creater, &advice)
  9110. if orgId == 3877 || orgId == 10265 {
  9111. //查询该药品是否有出库记录
  9112. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9113. if len(flowMap) == 0 {
  9114. errs := service.UpdateHisAdviceById(advice.ID)
  9115. if errs != nil {
  9116. drugError := models.XtDrugError{
  9117. UserOrgId: orgId,
  9118. DrugId: item.DrugId,
  9119. RecordDate: item.AdviceDate,
  9120. PatientId: item.PatientId,
  9121. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9122. Status: 1,
  9123. Ctime: time.Now().Unix(),
  9124. Mtime: 0,
  9125. SumCount: 0,
  9126. Prescribingnumber: advice.PrescribingNumber,
  9127. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9128. }
  9129. service.CreateDrugError(drugError)
  9130. }
  9131. this.ServeSuccessJSON(map[string]interface{}{
  9132. "msg": "2",
  9133. "drug": medical,
  9134. "ids": ids,
  9135. })
  9136. return
  9137. }
  9138. }
  9139. }
  9140. if pharmacyConfig.IsOpen != 1 {
  9141. service.HisDrugsDelivery(orgId, creater, &advice)
  9142. if orgId == 3877 || orgId == 10265 {
  9143. //查询该药品是否有出库记录
  9144. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9145. if len(flowMap) == 0 {
  9146. errs := service.UpdateHisAdviceById(advice.ID)
  9147. if errs != nil {
  9148. drugError := models.XtDrugError{
  9149. UserOrgId: orgId,
  9150. DrugId: item.DrugId,
  9151. RecordDate: item.AdviceDate,
  9152. PatientId: item.PatientId,
  9153. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9154. Status: 1,
  9155. Ctime: time.Now().Unix(),
  9156. Mtime: 0,
  9157. SumCount: 0,
  9158. Prescribingnumber: advice.PrescribingNumber,
  9159. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9160. }
  9161. service.CreateDrugError(drugError)
  9162. }
  9163. this.ServeSuccessJSON(map[string]interface{}{
  9164. "msg": "2",
  9165. "drug": medical,
  9166. "ids": ids,
  9167. })
  9168. return
  9169. }
  9170. }
  9171. }
  9172. //更新字典里面的库存
  9173. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9174. var sum_count int64
  9175. for _, its := range stockInfo {
  9176. if its.MaxUnit == medical.MaxUnit {
  9177. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9178. }
  9179. sum_count += its.StockMaxNumber + its.StockMinNumber
  9180. }
  9181. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9182. //剩余库存
  9183. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9184. }
  9185. }
  9186. }
  9187. }
  9188. }
  9189. this.ServeSuccessJSON(map[string]interface{}{
  9190. "msg": "1",
  9191. "ids": ids,
  9192. })
  9193. return
  9194. } else {
  9195. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9196. }
  9197. }
  9198. //血透客户
  9199. if config.IsOpen == 2 || config.IsOpen == 0 {
  9200. //药品管理信息
  9201. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9202. if drugStockConfig.IsOpen == 1 {
  9203. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9204. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9205. for _, item := range list {
  9206. for _, it := range adviceList {
  9207. if item.DrugId == it.DrugId {
  9208. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9209. }
  9210. }
  9211. }
  9212. for _, item := range list {
  9213. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9214. var sum_out_count int64
  9215. for _, itemThree := range item.ChildDoctorAdvice {
  9216. var prescribing_number int64
  9217. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9218. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9219. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9220. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9221. }
  9222. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9223. prescribing_number = parseIntPrescribingNumber
  9224. }
  9225. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9226. prescribing_number = parseIntPrescribingNumber
  9227. }
  9228. sum_out_count += prescribing_number
  9229. }
  9230. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9231. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9232. //库存不足
  9233. if sum_out_count > drugStockOut.FlushCount {
  9234. this.ServeSuccessJSON(map[string]interface{}{
  9235. "msg": "2",
  9236. "drug": medical,
  9237. "ids": ids,
  9238. })
  9239. return
  9240. }
  9241. }
  9242. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9243. //执行医嘱
  9244. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9245. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9246. for _, item := range advices {
  9247. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9248. redis := service.RedisClient()
  9249. //清空key 值
  9250. redis.Set(key, "", time.Second)
  9251. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9252. redis.Set(keyTwo, "", time.Second)
  9253. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9254. redis.Set(keyThree, "", time.Second)
  9255. recordDate := theTime.Format("2006-01-02")
  9256. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9257. redis.Set(keyFour, "", time.Second)
  9258. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9259. redis.Set(keyFive, "", time.Second)
  9260. defer redis.Close()
  9261. }
  9262. if errs == nil {
  9263. for _, item := range advices {
  9264. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9265. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9266. //查询是否出库按钮开启
  9267. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9268. if adviceSetting.IsAdviceOpen == 1 {
  9269. //查询是否出库按钮开启
  9270. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9271. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9272. if prescriptionConfig.IsOpen == 1 {
  9273. if medical.IsUse == 2 {
  9274. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9275. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9276. }
  9277. if pharmacyConfig.IsOpen != 1 {
  9278. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9279. }
  9280. //更新字典里面的库存
  9281. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9282. var sum_count int64
  9283. for _, its := range stockInfo {
  9284. if its.MaxUnit == medical.MaxUnit {
  9285. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9286. }
  9287. sum_count += its.StockMaxNumber + its.StockMinNumber
  9288. }
  9289. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9290. //剩余库存
  9291. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9292. }
  9293. }
  9294. } else {
  9295. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9296. if medical.IsUse == 2 {
  9297. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9298. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9299. }
  9300. if pharmacyConfig.IsOpen != 1 {
  9301. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9302. }
  9303. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9304. var sum_count int64
  9305. for _, its := range stockInfo {
  9306. if its.MaxUnit == medical.MaxUnit {
  9307. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9308. }
  9309. sum_count += its.StockMaxNumber + its.StockMinNumber
  9310. }
  9311. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9312. //剩余库存
  9313. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9314. }
  9315. }
  9316. }
  9317. }
  9318. this.ServeSuccessJSON(map[string]interface{}{
  9319. "msg": "1",
  9320. "ids": ids,
  9321. })
  9322. return
  9323. } else {
  9324. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9325. //执行医嘱
  9326. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9327. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9328. for _, item := range advices {
  9329. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9330. redis := service.RedisClient()
  9331. //清空key 值
  9332. redis.Set(key, "", time.Second)
  9333. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9334. redis.Set(keyTwo, "", time.Second)
  9335. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9336. redis.Set(keyThree, "", time.Second)
  9337. recordDate := theTime.Format("2006-01-02")
  9338. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9339. redis.Set(keyFour, "", time.Second)
  9340. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9341. redis.Set(keyFive, "", time.Second)
  9342. defer redis.Close()
  9343. }
  9344. this.ServeSuccessJSON(map[string]interface{}{
  9345. "msg": "1",
  9346. "ids": ids,
  9347. })
  9348. return
  9349. }
  9350. }
  9351. }
  9352. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9353. ids := this.GetString("ids")
  9354. idSplit := strings.Split(ids, ",")
  9355. orgId := this.GetMobileAdminUserInfo().Org.Id
  9356. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9357. if config.IsOpen == 1 {
  9358. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9359. this.ServeSuccessJSON(map[string]interface{}{
  9360. "msg": "1",
  9361. "ids": ids,
  9362. })
  9363. return
  9364. }
  9365. if config.IsOpen == 0 || config.IsOpen == 2 {
  9366. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9367. this.ServeSuccessJSON(map[string]interface{}{
  9368. "msg": "1",
  9369. "ids": ids,
  9370. })
  9371. return
  9372. }
  9373. }
  9374. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9375. ids := this.GetString("ids")
  9376. idSplit := strings.Split(ids, ",")
  9377. orgId := this.GetMobileAdminUserInfo().Org.Id
  9378. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9379. //his
  9380. if config.IsOpen == 1 {
  9381. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9382. theTime := time.Now()
  9383. advices := models.HisDoctorAdviceThirty{
  9384. CheckTime: theTime.Unix(),
  9385. Checker: checker,
  9386. UpdatedTime: time.Now().Unix(),
  9387. }
  9388. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9389. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9390. for _, item := range list {
  9391. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9392. redis := service.RedisClient()
  9393. //清空key 值
  9394. redis.Set(key, "", time.Second)
  9395. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9396. redis.Set(keyTwo, "", time.Second)
  9397. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9398. redis.Set(keyThree, "", time.Second)
  9399. recordDate := theTime.Format("2006-01-02")
  9400. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9401. redis.Set(keyFour, "", time.Second)
  9402. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9403. redis.Set(keyFive, "", time.Second)
  9404. defer redis.Close()
  9405. }
  9406. this.ServeSuccessJSON(map[string]interface{}{
  9407. "msg": "1",
  9408. "ids": ids,
  9409. })
  9410. return
  9411. }
  9412. //血透
  9413. if config.IsOpen == 0 || config.IsOpen == 2 {
  9414. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9415. theTime := time.Now()
  9416. advices := models.DoctorAdvice{
  9417. CheckTime: theTime.Unix(),
  9418. Checker: checker,
  9419. UpdatedTime: time.Now().Unix(),
  9420. }
  9421. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9422. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9423. for _, item := range list {
  9424. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9425. redis := service.RedisClient()
  9426. //清空key 值
  9427. redis.Set(key, "", time.Second)
  9428. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9429. redis.Set(keyTwo, "", time.Second)
  9430. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9431. redis.Set(keyThree, "", time.Second)
  9432. recordDate := theTime.Format("2006-01-02")
  9433. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9434. redis.Set(keyFour, "", time.Second)
  9435. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9436. redis.Set(keyFive, "", time.Second)
  9437. defer redis.Close()
  9438. }
  9439. this.ServeSuccessJSON(map[string]interface{}{
  9440. "msg": "1",
  9441. "ids": ids,
  9442. })
  9443. return
  9444. }
  9445. }
  9446. func (this *DialysisAPIController) CheckSchedule() {
  9447. patientID, _ := this.GetInt64("patient_id")
  9448. recordDateStr := this.GetString("record_date")
  9449. nurseID, _ := this.GetInt64("start_nurse")
  9450. schedual_type, _ := this.GetInt64("schedual_type")
  9451. bedID, _ := this.GetInt64("bed")
  9452. start_time := this.GetString("start_time")
  9453. fmt.Println("patientID", patientID)
  9454. fmt.Println("recordDateStr", recordDateStr)
  9455. fmt.Println("nurseID", nurseID)
  9456. fmt.Println("schedual_type------", schedual_type)
  9457. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9458. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9459. return
  9460. }
  9461. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9462. if parseStartDateErr != nil {
  9463. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9464. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9465. return
  9466. }
  9467. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9468. if parseErr != nil {
  9469. this.ErrorLog("时间解析失败:%v", parseErr)
  9470. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9471. return
  9472. }
  9473. adminUserInfo := this.GetMobileAdminUserInfo()
  9474. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9475. if getPatientErr != nil {
  9476. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9477. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9478. return
  9479. } else if patient == nil {
  9480. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9481. return
  9482. }
  9483. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9484. if getNurseErr != nil {
  9485. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9486. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9487. return
  9488. } else if nurse == nil {
  9489. this.ErrorLog("护士不存在")
  9490. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9491. return
  9492. }
  9493. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9494. if getDeviceNumberErr != nil {
  9495. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9496. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9497. return
  9498. } else if deviceNumber == nil {
  9499. this.ErrorLog("床位号不存在")
  9500. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9501. return
  9502. }
  9503. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9504. if getRecordErr != nil {
  9505. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9506. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9507. return
  9508. } else if dialysisRecord != nil {
  9509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9510. return
  9511. }
  9512. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9513. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9514. timeLayout := "2006-01-02 15:04:05"
  9515. loc, _ := time.LoadLocation("Local")
  9516. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9517. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9518. schedulestartTime := theStartTime.Unix()
  9519. scheduleendTime := theEndTime.Unix()
  9520. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9521. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9522. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9523. //查询该床位是否有人用了
  9524. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9525. if err == nil {
  9526. if schedule.ID == 0 {
  9527. this.ServeSuccessJSON(map[string]interface{}{
  9528. "status": 0,
  9529. "msg": "请求失败",
  9530. })
  9531. } else {
  9532. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9533. if order.ID > 0 { //该机位被其他人占用了
  9534. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9535. return
  9536. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9537. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9538. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9539. this.ServeSuccessJSON(map[string]interface{}{
  9540. "status": 1,
  9541. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9542. })
  9543. return
  9544. } else {
  9545. this.ServeSuccessJSON(map[string]interface{}{
  9546. "status": 0,
  9547. "msg": "",
  9548. })
  9549. }
  9550. }
  9551. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9552. this.ServeSuccessJSON(map[string]interface{}{
  9553. "status": 2,
  9554. "msg": "当前机位已有患者在使用,请重新选择!",
  9555. })
  9556. }
  9557. }
  9558. } else {
  9559. this.ServeSuccessJSON(map[string]interface{}{
  9560. "status": 0,
  9561. "msg": "",
  9562. })
  9563. }
  9564. }
  9565. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9566. orgId := this.GetMobileAdminUserInfo().Org.Id
  9567. schedule_type, _ := this.GetInt64("schedule_type")
  9568. partion_type, _ := this.GetInt64("partion_type")
  9569. start_time := this.GetString("start_time")
  9570. timeLayout := "2006-01-02"
  9571. loc, _ := time.LoadLocation("Local")
  9572. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9573. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9574. _, config := service.FindXTHisRecordByOrgId(orgId)
  9575. appId := this.GetMobileAdminUserInfo().App.Id
  9576. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9577. if err == nil {
  9578. this.ServeSuccessJSON(map[string]interface{}{
  9579. "list": list,
  9580. "config": config,
  9581. "doctorList": doctorList,
  9582. })
  9583. return
  9584. } else {
  9585. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9586. return
  9587. }
  9588. }
  9589. func (this *DialysisAPIController) SaveMobileInformation() {
  9590. patient_id, _ := this.GetInt64("patient_id")
  9591. record_date, _ := this.GetInt64("record_date")
  9592. startTime := this.GetString("start_time")
  9593. module, _ := this.GetInt64("module")
  9594. remark := this.GetString("remark")
  9595. timeLayout := "2006-01-02 15:04"
  9596. loc, _ := time.LoadLocation("Local")
  9597. if len(startTime) == 0 {
  9598. utils.ErrorLog("len(start_time) == 0")
  9599. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9600. return
  9601. }
  9602. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9603. if err != nil {
  9604. utils.ErrorLog(err.Error())
  9605. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9606. return
  9607. }
  9608. StartTime := theTime.Unix()
  9609. fmt.Println("startime-------------", StartTime)
  9610. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9611. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9612. information := models.XtDialysisInformation{
  9613. Module: module,
  9614. PatientId: patient_id,
  9615. RecordDate: record_date,
  9616. ApplicationDate: StartTime,
  9617. Creater: creater,
  9618. ApplicationStatus: 2,
  9619. Checker: 0,
  9620. CheckTime: 0,
  9621. Remark: remark,
  9622. UserOrgId: user_org_id,
  9623. Ctime: time.Now().Unix(),
  9624. Status: 1,
  9625. Mtime: 0,
  9626. }
  9627. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9628. if infor.ID == 0 {
  9629. service.SaveDialysisInformation(information)
  9630. }
  9631. if infor.ID > 0 {
  9632. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9633. }
  9634. this.ServeSuccessJSON(map[string]interface{}{
  9635. "information": information,
  9636. })
  9637. return
  9638. }
  9639. func (this *DialysisAPIController) GetMobileInformation() {
  9640. limit, _ := this.GetInt64("limit")
  9641. page, _ := this.GetInt64("page")
  9642. orgid := this.GetMobileAdminUserInfo().Org.Id
  9643. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9644. appid := this.GetMobileAdminUserInfo().App.Id
  9645. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9646. patients, _ := service.GetAllpatientThirty(orgid)
  9647. this.ServeSuccessJSON(map[string]interface{}{
  9648. "information": information,
  9649. "total": total,
  9650. "doclist": doclist,
  9651. "patients": patients,
  9652. })
  9653. return
  9654. }
  9655. func (this *DialysisAPIController) GetMobileInformationOne() {
  9656. limit, _ := this.GetInt64("limit")
  9657. page, _ := this.GetInt64("page")
  9658. orgid := this.GetMobileAdminUserInfo().Org.Id
  9659. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9660. appid := this.GetMobileAdminUserInfo().App.Id
  9661. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9662. patients, _ := service.GetAllpatientThirty(orgid)
  9663. this.ServeSuccessJSON(map[string]interface{}{
  9664. "information": information,
  9665. "total": total,
  9666. "doclist": doclist,
  9667. "patients": patients,
  9668. })
  9669. return
  9670. }
  9671. func (this *DialysisAPIController) CheckMobileInformation() {
  9672. id, _ := this.GetInt64("id")
  9673. application_status, _ := this.GetInt64("application_status")
  9674. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9675. checktime := time.Now().Unix()
  9676. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9677. if err == nil {
  9678. this.ServeSuccessJSON(map[string]interface{}{
  9679. "msg": "ok",
  9680. })
  9681. return
  9682. }
  9683. }
  9684. func (c *DialysisAPIController) GetControlMonitorList() {
  9685. partition, _ := c.GetInt64("partition")
  9686. monitorDate := c.GetString("date")
  9687. patient_id, _ := c.GetInt64("patient_id")
  9688. pat_type, _ := c.GetInt64("pat_type")
  9689. timeLayout := "2006-01-02"
  9690. loc, _ := time.LoadLocation("Local")
  9691. var theStartTime int64
  9692. if len(monitorDate) > 0 {
  9693. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9694. if err != nil {
  9695. theStartTime = 0
  9696. }
  9697. theStartTime = theTime.Unix()
  9698. }
  9699. adminInfo := c.GetMobileAdminUserInfo()
  9700. orgID := adminInfo.Org.Id
  9701. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9702. if err != nil {
  9703. c.ErrorLog("获取排班信息失败:%v", err)
  9704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9705. } else {
  9706. if len(monitor) > 0 {
  9707. //获取所有床位
  9708. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9709. //获取所有分区
  9710. zoneList, _ := service.GetAllZoneByList(orgID)
  9711. //获取透析处方
  9712. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9713. //获取透前评估
  9714. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9715. //获取上机
  9716. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9717. //获取透后
  9718. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9719. //获取透后监测
  9720. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9721. //获取所有的患者
  9722. patients, _ := service.GetAllPatientListByListOne(orgID)
  9723. //获取所有透析模式
  9724. treatments, _ := service.GetAllTreatModeByList(orgID)
  9725. //获取所有医嘱
  9726. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9727. //获取双人核对
  9728. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9729. //治疗小结
  9730. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9731. //待消毒
  9732. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9733. for key, item := range monitor {
  9734. // 获取床位信息
  9735. for _, it := range numberList {
  9736. if item.BedId == it.ID {
  9737. monitor[key].DeviceNumber = it
  9738. break
  9739. }
  9740. }
  9741. //获取分区信息
  9742. for _, it := range zoneList {
  9743. if item.PartitionId == it.ID {
  9744. monitor[key].DeviceZone = it
  9745. }
  9746. }
  9747. for _, prescription := range prescriptions {
  9748. if item.PatientId == prescription.PatientId {
  9749. monitor[key].Prescription = prescription
  9750. break
  9751. }
  9752. }
  9753. for _, it := range checkList {
  9754. if item.PatientId == it.PatientId {
  9755. monitor[key].DoubleCheck = it
  9756. break
  9757. }
  9758. }
  9759. for _, it := range summaryList {
  9760. if item.PatientId == it.PatientId {
  9761. monitor[key].TreatmentSummaryForList = it
  9762. break
  9763. }
  9764. }
  9765. // 透前评估
  9766. for _, assessmentBefore := range assessmentBefores {
  9767. if item.PatientId == assessmentBefore.PatientId {
  9768. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9769. break
  9770. }
  9771. }
  9772. // 透析上下机
  9773. for _, dialysisOrder := range dialysisOrders {
  9774. if item.PatientId == dialysisOrder.PatientId {
  9775. monitor[key].DialysisOrder = dialysisOrder
  9776. break
  9777. }
  9778. }
  9779. // 治疗小节
  9780. for _, afterDislysis := range AssessmentAfterDislysis {
  9781. if item.PatientId == afterDislysis.PatientId {
  9782. monitor[key].AssessmentAfterDislysis = afterDislysis
  9783. break
  9784. }
  9785. }
  9786. for _, it := range monitorlist {
  9787. if item.PatientId == it.PatientId {
  9788. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9789. }
  9790. }
  9791. for _, it := range adviceList {
  9792. if item.PatientId == it.PatientId {
  9793. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9794. }
  9795. }
  9796. for _, patient := range patients {
  9797. if item.PatientId == patient.ID {
  9798. monitor[key].MonitorPatients = patient
  9799. break
  9800. }
  9801. }
  9802. for _, treatment := range treatments {
  9803. if item.ModeId == treatment.ID {
  9804. monitor[key].TreatmentMode = treatment
  9805. break
  9806. }
  9807. }
  9808. for _, infor := range informationList {
  9809. if item.PatientId == infor.PatientId {
  9810. monitor[key].NewDeviceInformation = infor
  9811. break
  9812. }
  9813. }
  9814. }
  9815. }
  9816. }
  9817. patients, err := service.GetAllpatientFourty(orgID)
  9818. var mds []*models.NewMonitorDialysisScheduleList
  9819. if pat_type == 0 {
  9820. for _, item := range monitor {
  9821. mds = append(mds, item)
  9822. }
  9823. }
  9824. //待医嘱核对
  9825. if pat_type == 1 {
  9826. for _, item := range monitor {
  9827. if len(item.AdviceList) > 0 {
  9828. mds = append(mds, item)
  9829. }
  9830. }
  9831. }
  9832. //待开小结
  9833. if pat_type == 2 {
  9834. for _, item := range monitor {
  9835. if item.TreatmentSummaryForList == nil {
  9836. mds = append(mds, item)
  9837. }
  9838. }
  9839. }
  9840. //待下机
  9841. if pat_type == 3 {
  9842. for _, item := range monitor {
  9843. if item.DialysisOrder != nil {
  9844. if item.DialysisOrder.ID > 0 {
  9845. mds = append(mds, item)
  9846. }
  9847. }
  9848. }
  9849. }
  9850. //待消毒
  9851. if pat_type == 4 {
  9852. for _, item := range monitor {
  9853. if item.NewDeviceInformation == nil {
  9854. mds = append(mds, item)
  9855. }
  9856. }
  9857. }
  9858. //待双人核对
  9859. if pat_type == 5 {
  9860. for _, item := range monitor {
  9861. if item.DoubleCheck == nil {
  9862. mds = append(mds, item)
  9863. }
  9864. }
  9865. }
  9866. //医嘱未执行
  9867. if pat_type == 6 {
  9868. for _, item := range monitor {
  9869. if len(item.AdviceList) > 0 {
  9870. mds = append(mds, item)
  9871. }
  9872. }
  9873. }
  9874. //患者未签名
  9875. if pat_type == 7 {
  9876. for _, item := range monitor {
  9877. if item.DialysisOrder != nil {
  9878. if item.DialysisOrder.ID > 0 {
  9879. mds = append(mds, item)
  9880. }
  9881. }
  9882. }
  9883. }
  9884. //目标超滤于实际超滤不同
  9885. if pat_type == 8 {
  9886. for _, item := range monitor {
  9887. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9888. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9889. mds = append(mds, item)
  9890. }
  9891. }
  9892. }
  9893. }
  9894. //血压少于5次
  9895. if pat_type == 9 {
  9896. for _, item := range monitor {
  9897. if len(item.MonitoringRecord) < 5 {
  9898. mds = append(mds, item)
  9899. }
  9900. }
  9901. }
  9902. if pat_type == 10 {
  9903. for _, item := range monitor {
  9904. if len(item.MonitoringRecord) == 0 {
  9905. mds = append(mds, item)
  9906. }
  9907. }
  9908. }
  9909. if pat_type == 11 {
  9910. for _, item := range monitor {
  9911. if len(item.MonitoringRecord) > 0 {
  9912. mds = append(mds, item)
  9913. }
  9914. }
  9915. }
  9916. if pat_type == 12 {
  9917. for _, item := range monitor {
  9918. if len(item.MonitoringRecord) > 0 {
  9919. mds = append(mds, item)
  9920. }
  9921. }
  9922. }
  9923. if err == nil {
  9924. c.ServeSuccessJSON(map[string]interface{}{
  9925. "monitor": mds,
  9926. "patients": patients,
  9927. })
  9928. } else {
  9929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9930. }
  9931. }
  9932. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9933. admin_user_id, _ := c.GetInt64("admin_user_id")
  9934. timeStr := time.Now().Format("2006-01-02")
  9935. timeLayout := "2006-01-02 15:04:05"
  9936. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9937. timenow := timeStringToTime.Unix()
  9938. orgId := c.GetMobileAdminUserInfo().Org.Id
  9939. //查询当前护士的患者
  9940. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9941. var patientIds []int64
  9942. for _, item := range orderList {
  9943. patientIds = append(patientIds, item.PatientId)
  9944. }
  9945. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9946. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9947. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9948. //药品管理信息
  9949. _, drugStockConfig := service.FindHisConfig(orgId)
  9950. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9951. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9952. c.ServeSuccessJSON(map[string]interface{}{
  9953. "adviceList": adviceList,
  9954. "hisAdviceList": hisAdviceList,
  9955. "projectList": projectList,
  9956. "drugStockConfig": drugStockConfig,
  9957. "patientList": patientList,
  9958. "projectConfig": projectConfig,
  9959. })
  9960. }
  9961. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9962. patient_id, _ := c.GetInt64("patient_id")
  9963. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9964. c.ServeSuccessJSON(map[string]interface{}{
  9965. "recrods": recrods,
  9966. })
  9967. }
  9968. func (c *DialysisAPIController) ExMobileChangeSch() {
  9969. id_one, _ := c.GetInt64("id_one")
  9970. id_two, _ := c.GetInt64("id_two")
  9971. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9972. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9973. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9974. //if order2.ID > 0 {
  9975. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9976. // return
  9977. //}
  9978. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9979. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9980. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9981. if count > 0 {
  9982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9983. return
  9984. }
  9985. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9986. if count1 > 0 {
  9987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9988. return
  9989. }
  9990. }
  9991. err := service.UpdateScheduleThree(sch, sch_two)
  9992. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  9993. if order.ID > 0 {
  9994. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  9995. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9996. redis := service.RedisClient()
  9997. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  9998. redis.Set(key, "", time.Second)
  9999. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10000. //清空key 值
  10001. redis.Set(keyOne, "", time.Second)
  10002. }
  10003. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10004. if orderOne.ID > 0 {
  10005. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10006. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10007. redis := service.RedisClient()
  10008. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10009. redis.Set(key, "", time.Second)
  10010. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10011. //清空key 值
  10012. redis.Set(keyOne, "", time.Second)
  10013. }
  10014. if err == nil {
  10015. //去除当天患者排班中重复数据,保留最后一条数据
  10016. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10017. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10018. c.ServeSuccessJSON(map[string]interface{}{
  10019. "msg": "交换成功",
  10020. })
  10021. } else {
  10022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10023. return
  10024. }
  10025. }
  10026. func (c *DialysisAPIController) MobileCoverSch() {
  10027. id_one, _ := c.GetInt64("id_one")
  10028. id_two, _ := c.GetInt64("id_two")
  10029. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10030. //针对凤凰医院
  10031. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  10032. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10033. if len(advice) > 0 {
  10034. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10035. }
  10036. }
  10037. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  10038. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10039. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10040. if len(hisAdvice) > 0 {
  10041. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10042. }
  10043. if len(project) > 0 {
  10044. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10045. }
  10046. }
  10047. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10048. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10049. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10050. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10051. if count > 0 {
  10052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10053. return
  10054. }
  10055. }
  10056. var new_sch models.Schedule
  10057. new_sch = sch
  10058. new_sch.BedId = sch_two.BedId
  10059. new_sch.ScheduleDate = sch_two.ScheduleDate
  10060. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  10061. new_sch.PartitionId = sch_two.PartitionId
  10062. new_sch.ScheduleType = sch_two.ScheduleType
  10063. new_sch.ID = 0
  10064. //删除原来的排班
  10065. err := service.SaveSchTwo(sch, sch_two)
  10066. //生成新的排班
  10067. if err == nil {
  10068. err2 := service.SaveSch(&new_sch)
  10069. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10070. if order.ID > 0 {
  10071. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10072. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10073. redis := service.RedisClient()
  10074. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10075. redis.Set(key, "", time.Second)
  10076. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10077. //清空key 值
  10078. redis.Set(keyOne, "", time.Second)
  10079. }
  10080. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10081. if orderOne.ID > 0 {
  10082. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10083. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10084. redis := service.RedisClient()
  10085. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10086. redis.Set(key, "", time.Second)
  10087. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10088. //清空key 值
  10089. redis.Set(keyOne, "", time.Second)
  10090. }
  10091. if err2 == nil {
  10092. //去除当天患者排班中重复数据,保留最后一条数据
  10093. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10094. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10095. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  10096. c.ServeSuccessJSON(map[string]interface{}{
  10097. "msg": "覆盖成功",
  10098. "new_sch": new_sch,
  10099. })
  10100. } else {
  10101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10102. return
  10103. }
  10104. } else {
  10105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10106. return
  10107. }
  10108. }
  10109. func (c *DialysisAPIController) BatchCheckAdvice() {
  10110. patient_id, _ := c.GetInt64("patient_id")
  10111. advice_date, _ := c.GetInt64("advice_date")
  10112. org_id := c.GetMobileAdminUserInfo().Org.Id
  10113. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  10114. //查询是his系统还是血透系统
  10115. _, configs := service.FindXTHisRecordByOrgId(org_id)
  10116. //his客户
  10117. if configs.IsOpen == 1 {
  10118. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  10119. for _, item := range adviceList {
  10120. service.BatchCheckHisAdvice(item.ID, creater)
  10121. }
  10122. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10123. for _, item := range projectList {
  10124. service.BatchCheckProject(item.ID, creater)
  10125. }
  10126. c.ServeSuccessJSON(map[string]interface{}{
  10127. "adviceList": adviceList,
  10128. "projectList": projectList,
  10129. })
  10130. }
  10131. if configs.IsOpen != 1 {
  10132. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  10133. for _, item := range adviceList {
  10134. service.BatchAdviceList(item.ID, creater)
  10135. }
  10136. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10137. for _, item := range projectList {
  10138. service.BatchCheckProject(item.ID, creater)
  10139. }
  10140. c.ServeSuccessJSON(map[string]interface{}{
  10141. "adviceList": adviceList,
  10142. "projectList": projectList,
  10143. })
  10144. }
  10145. return
  10146. }
  10147. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10148. org_id := c.GetMobileAdminUserInfo().Org.Id
  10149. drugList, _ := service.GetAllDrugList(org_id)
  10150. c.ServeSuccessJSON(map[string]interface{}{
  10151. "drugList": drugList,
  10152. })
  10153. }
  10154. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10155. org_id := c.GetMobileAdminUserInfo().Org.Id
  10156. dataBody := make(map[string]interface{}, 0)
  10157. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10158. if err != nil {
  10159. utils.ErrorLog(err.Error())
  10160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10161. return
  10162. }
  10163. timeLayout := "2006-01-02"
  10164. loc, _ := time.LoadLocation("Local")
  10165. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10166. utils.ErrorLog("advice_type")
  10167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10168. return
  10169. }
  10170. adviceType := int64(dataBody["advice_type"].(float64))
  10171. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10172. utils.ErrorLog("start_time")
  10173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10174. return
  10175. }
  10176. startTime2, _ := dataBody["start_time"].(string)
  10177. time_arr := strings.Split(startTime2, " ")
  10178. if len(time_arr) > 0 {
  10179. startTime2 = time_arr[0]
  10180. }
  10181. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10182. utils.ErrorLog("advice_date")
  10183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10184. return
  10185. }
  10186. advice_date, _ := dataBody["advice_date"].(string)
  10187. var advicedateunix int64
  10188. if len(advice_date) > 0 {
  10189. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10190. if err != nil {
  10191. fmt.Println(err)
  10192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10193. return
  10194. }
  10195. advicedateunix = theTime.Unix()
  10196. }
  10197. adviceDate := startTime2
  10198. if len(adviceDate) == 0 {
  10199. utils.ErrorLog("len(adviceDate) == 0")
  10200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10201. return
  10202. }
  10203. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10204. if err != nil {
  10205. utils.ErrorLog(err.Error())
  10206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10207. return
  10208. }
  10209. AdviceDate := advicedateunix
  10210. RecordDate := advicedateunix
  10211. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10212. utils.ErrorLog("start_time")
  10213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10214. return
  10215. }
  10216. startTime, _ := dataBody["start_time"].(string)
  10217. if len(startTime) == 0 {
  10218. utils.ErrorLog("len(start_time) == 0")
  10219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10220. return
  10221. }
  10222. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10223. if err != nil {
  10224. utils.ErrorLog(err.Error())
  10225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10226. return
  10227. }
  10228. StartTime := theTime.Unix()
  10229. advice_name, _ := dataBody["advice_name"].(string)
  10230. advice_desc, _ := dataBody["advice_desc"].(string)
  10231. delivery_way, _ := dataBody["delivery_way"].(string)
  10232. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10233. frequency_type := int64(dataBody["frequency_type"].(float64))
  10234. frequency_week, _ := dataBody["frequency_week"].(string)
  10235. prescribing_number := dataBody["prescribing_number"].(float64)
  10236. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10237. remark := dataBody["remark"].(string)
  10238. single_dose := dataBody["single_dose"].(float64)
  10239. single_dose_unit := dataBody["single_dose_unit"].(string)
  10240. patient_id := int64(dataBody["patient_id"].(float64))
  10241. day_count := int64(dataBody["day_count"].(float64))
  10242. groupNo := int64(dataBody["group_no"].(float64))
  10243. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10244. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10245. if groupNo <= 0 {
  10246. group := service.GetMaxAdviceGroupID(org_id)
  10247. groupNo = group + 1
  10248. }
  10249. var template_id = ""
  10250. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10251. template_id = "M" + adviceLastId
  10252. advice := models.DoctorAdvice{
  10253. UserOrgId: org_id,
  10254. PatientId: patient_id,
  10255. AdviceType: adviceType,
  10256. AdviceDate: AdviceDate,
  10257. StartTime: StartTime,
  10258. AdviceName: advice_name,
  10259. AdviceDesc: advice_desc,
  10260. ReminderDate: 0,
  10261. SingleDose: single_dose,
  10262. SingleDoseUnit: single_dose_unit,
  10263. DrugSpec: 0,
  10264. DrugSpecUnit: "",
  10265. PrescribingNumber: prescribing_number,
  10266. PrescribingNumberUnit: prescribing_number_unit,
  10267. DeliveryWay: delivery_way,
  10268. ExecutionFrequency: execution_frequency,
  10269. AdviceDoctor: advice_doctor,
  10270. Status: 1,
  10271. CreatedTime: time.Now().Unix(),
  10272. UpdatedTime: 0,
  10273. AdviceAffirm: "",
  10274. Remark: remark,
  10275. StopTime: 0,
  10276. StopReason: "",
  10277. StopDoctor: 0,
  10278. StopState: 0,
  10279. ParentId: 0,
  10280. ExecutionTime: 0,
  10281. ExecutionStaff: 0,
  10282. ExecutionState: 0,
  10283. Checker: 0,
  10284. RecordDate: RecordDate,
  10285. DialysisOrderId: 0,
  10286. CheckTime: 0,
  10287. CheckState: 0,
  10288. AdviceId: 0,
  10289. RemindType: 0,
  10290. FrequencyType: frequency_type,
  10291. DayCount: day_count,
  10292. WeekDay: frequency_week,
  10293. ChildDoctorAdvice: nil,
  10294. TemplateId: template_id,
  10295. Modifier: 0,
  10296. IsCheck: 0,
  10297. Way: 0,
  10298. DrugId: 0,
  10299. DrugNameId: 0,
  10300. IsMedicine: 0,
  10301. PushStartTime: 0,
  10302. IsSettle: 0,
  10303. IsPrescription: 0,
  10304. GroupNo: groupNo,
  10305. }
  10306. service.CreateMobileAdivce(advice)
  10307. c.ServeSuccessJSON(map[string]interface{}{
  10308. "msg": "保存成功!",
  10309. })
  10310. }
  10311. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10312. patient_id, _ := c.GetInt64("patient_id")
  10313. org_id := c.GetMobileAdminUserInfo().Org.Id
  10314. app_id := c.GetMobileAdminUserInfo().App.Id
  10315. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10316. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10317. c.ServeSuccessJSON(map[string]interface{}{
  10318. "adviceList": adviceList,
  10319. "adminRoles": adminRoles,
  10320. })
  10321. }
  10322. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10323. org_id := c.GetMobileAdminUserInfo().Org.Id
  10324. dataBody := make(map[string]interface{}, 0)
  10325. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10326. if err != nil {
  10327. utils.ErrorLog(err.Error())
  10328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10329. return
  10330. }
  10331. timeLayout := "2006-01-02"
  10332. loc, _ := time.LoadLocation("Local")
  10333. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10334. utils.ErrorLog("start_time")
  10335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10336. return
  10337. }
  10338. startTime2, _ := dataBody["start_time"].(string)
  10339. time_arr := strings.Split(startTime2, " ")
  10340. if len(time_arr) > 0 {
  10341. startTime2 = time_arr[0]
  10342. }
  10343. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10344. utils.ErrorLog("advice_date")
  10345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10346. return
  10347. }
  10348. advice_date, _ := dataBody["advice_date"].(string)
  10349. var advicedateunix int64
  10350. if len(advice_date) > 0 {
  10351. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10352. if err != nil {
  10353. fmt.Println(err)
  10354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10355. return
  10356. }
  10357. advicedateunix = theTime.Unix()
  10358. }
  10359. adviceDate := startTime2
  10360. if len(adviceDate) == 0 {
  10361. utils.ErrorLog("len(adviceDate) == 0")
  10362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10363. return
  10364. }
  10365. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10366. if err != nil {
  10367. utils.ErrorLog(err.Error())
  10368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10369. return
  10370. }
  10371. AdviceDate := advicedateunix
  10372. RecordDate := advicedateunix
  10373. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10374. utils.ErrorLog("start_time")
  10375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10376. return
  10377. }
  10378. startTime, _ := dataBody["start_time"].(string)
  10379. if len(startTime) == 0 {
  10380. utils.ErrorLog("len(start_time) == 0")
  10381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10382. return
  10383. }
  10384. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10385. if err != nil {
  10386. utils.ErrorLog(err.Error())
  10387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10388. return
  10389. }
  10390. StartTime := theTime.Unix()
  10391. advice_name, _ := dataBody["advice_name"].(string)
  10392. advice_desc, _ := dataBody["advice_desc"].(string)
  10393. delivery_way, _ := dataBody["delivery_way"].(string)
  10394. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10395. prescribing_number := dataBody["prescribing_number"].(float64)
  10396. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10397. remark := dataBody["remark"].(string)
  10398. single_dose := dataBody["single_dose"].(float64)
  10399. single_dose_unit := dataBody["single_dose_unit"].(string)
  10400. patient_id := int64(dataBody["patient_id"].(float64))
  10401. groupNo := int64(dataBody["group_no"].(float64))
  10402. parent_id := int64(dataBody["parent_id"].(float64))
  10403. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10404. advice := models.XtDoctorAdviceOne{
  10405. UserOrgId: org_id,
  10406. PatientId: patient_id,
  10407. AdviceType: 1,
  10408. AdviceDate: AdviceDate,
  10409. StartTime: StartTime,
  10410. AdviceName: advice_name,
  10411. AdviceDesc: advice_desc,
  10412. ReminderDate: 0,
  10413. SingleDose: single_dose,
  10414. SingleDoseUnit: single_dose_unit,
  10415. PrescribingNumber: prescribing_number,
  10416. PrescribingNumberUnit: prescribing_number_unit,
  10417. DeliveryWay: delivery_way,
  10418. ExecutionFrequency: execution_frequency,
  10419. AdviceDoctor: advice_doctor,
  10420. Status: 1,
  10421. CreatedTime: time.Now().Unix(),
  10422. UpdatedTime: time.Now().Unix(),
  10423. AdviceAffirm: "",
  10424. Remark: remark,
  10425. StopTime: 0,
  10426. StopReason: "",
  10427. StopDoctor: 0,
  10428. StopState: 2,
  10429. ParentId: parent_id,
  10430. ExecutionTime: 0,
  10431. ExecutionStaff: 0,
  10432. ExecutionState: 0,
  10433. Checker: 0,
  10434. RecordDate: RecordDate,
  10435. DialysisOrderId: 0,
  10436. CheckTime: 0,
  10437. CheckState: 0,
  10438. DrugSpec: 0,
  10439. DrugSpecUnit: "",
  10440. Groupno: groupNo,
  10441. RemindType: 0,
  10442. FrequencyType: 0,
  10443. DayCount: 0,
  10444. WeekDay: "",
  10445. TemplateId: "",
  10446. Modifier: 0,
  10447. }
  10448. service.CreateMobileAdivceOne(advice)
  10449. c.ServeSuccessJSON(map[string]interface{}{
  10450. "msg": "保存成功!",
  10451. })
  10452. }
  10453. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10454. id, _ := c.GetInt64("id")
  10455. service.DeleteSelfAdviceSubAdvice(id)
  10456. c.ServeSuccessJSON(map[string]interface{}{
  10457. "msg": "保存成功!",
  10458. })
  10459. }
  10460. func (c *DialysisAPIController) GetEditAdviceAction() {
  10461. id, _ := c.GetInt64("id")
  10462. org_id := c.GetMobileAdminUserInfo().Org.Id
  10463. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10464. drugList, _ := service.GetAllDrugList(org_id)
  10465. c.ServeSuccessJSON(map[string]interface{}{
  10466. "advice": advice,
  10467. "drugList": drugList,
  10468. })
  10469. }
  10470. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10471. dataBody := make(map[string]interface{}, 0)
  10472. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10473. if err != nil {
  10474. utils.ErrorLog(err.Error())
  10475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10476. return
  10477. }
  10478. timeLayout := "2006-01-02"
  10479. loc, _ := time.LoadLocation("Local")
  10480. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10481. utils.ErrorLog("start_time")
  10482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10483. return
  10484. }
  10485. startTime2, _ := dataBody["start_time"].(string)
  10486. time_arr := strings.Split(startTime2, " ")
  10487. if len(time_arr) > 0 {
  10488. startTime2 = time_arr[0]
  10489. }
  10490. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10491. utils.ErrorLog("advice_date")
  10492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10493. return
  10494. }
  10495. advice_date, _ := dataBody["advice_date"].(string)
  10496. var advicedateunix int64
  10497. if len(advice_date) > 0 {
  10498. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10499. if err != nil {
  10500. fmt.Println(err)
  10501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10502. return
  10503. }
  10504. advicedateunix = theTime.Unix()
  10505. }
  10506. adviceDate := startTime2
  10507. if len(adviceDate) == 0 {
  10508. utils.ErrorLog("len(adviceDate) == 0")
  10509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10510. return
  10511. }
  10512. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10513. if err != nil {
  10514. utils.ErrorLog(err.Error())
  10515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10516. return
  10517. }
  10518. AdviceDate := advicedateunix
  10519. RecordDate := advicedateunix
  10520. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10521. utils.ErrorLog("start_time")
  10522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10523. return
  10524. }
  10525. startTime, _ := dataBody["start_time"].(string)
  10526. if len(startTime) == 0 {
  10527. utils.ErrorLog("len(start_time) == 0")
  10528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10529. return
  10530. }
  10531. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10532. if err != nil {
  10533. utils.ErrorLog(err.Error())
  10534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10535. return
  10536. }
  10537. StartTime := theTime.Unix()
  10538. advice_name, _ := dataBody["advice_name"].(string)
  10539. advice_desc, _ := dataBody["advice_desc"].(string)
  10540. delivery_way, _ := dataBody["delivery_way"].(string)
  10541. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10542. prescribing_number := dataBody["prescribing_number"].(float64)
  10543. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10544. remark := dataBody["remark"].(string)
  10545. single_dose := dataBody["single_dose"].(float64)
  10546. single_dose_unit := dataBody["single_dose_unit"].(string)
  10547. id := int64(dataBody["id"].(float64))
  10548. frequency_type := int64(dataBody["frequency_type"].(float64))
  10549. frequency_week, _ := dataBody["frequency_week"].(string)
  10550. day_count := int64(dataBody["day_count"].(float64))
  10551. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10552. advice := models.XtDoctorAdviceOne{
  10553. AdviceDate: AdviceDate,
  10554. StartTime: StartTime,
  10555. AdviceName: advice_name,
  10556. AdviceDesc: advice_desc,
  10557. SingleDose: single_dose,
  10558. SingleDoseUnit: single_dose_unit,
  10559. PrescribingNumber: prescribing_number,
  10560. PrescribingNumberUnit: prescribing_number_unit,
  10561. DeliveryWay: delivery_way,
  10562. ExecutionFrequency: execution_frequency,
  10563. AdviceDoctor: advice_doctor,
  10564. Remark: remark,
  10565. RecordDate: RecordDate,
  10566. FrequencyType: frequency_type,
  10567. DayCount: day_count,
  10568. WeekDay: frequency_week,
  10569. }
  10570. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10571. c.ServeSuccessJSON(map[string]interface{}{
  10572. "advice": advice,
  10573. })
  10574. }
  10575. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10576. dataBody := make(map[string]interface{}, 0)
  10577. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10578. if err != nil {
  10579. utils.ErrorLog(err.Error())
  10580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10581. return
  10582. }
  10583. timeLayout := "2006-01-02"
  10584. loc, _ := time.LoadLocation("Local")
  10585. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10586. utils.ErrorLog("start_time")
  10587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10588. return
  10589. }
  10590. startTime2, _ := dataBody["start_time"].(string)
  10591. time_arr := strings.Split(startTime2, " ")
  10592. if len(time_arr) > 0 {
  10593. startTime2 = time_arr[0]
  10594. }
  10595. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10596. utils.ErrorLog("advice_date")
  10597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10598. return
  10599. }
  10600. advice_date, _ := dataBody["advice_date"].(string)
  10601. var advicedateunix int64
  10602. if len(advice_date) > 0 {
  10603. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10604. if err != nil {
  10605. fmt.Println(err)
  10606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10607. return
  10608. }
  10609. advicedateunix = theTime.Unix()
  10610. }
  10611. adviceDate := startTime2
  10612. if len(adviceDate) == 0 {
  10613. utils.ErrorLog("len(adviceDate) == 0")
  10614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10615. return
  10616. }
  10617. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10618. if err != nil {
  10619. utils.ErrorLog(err.Error())
  10620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10621. return
  10622. }
  10623. AdviceDate := advicedateunix
  10624. RecordDate := advicedateunix
  10625. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10626. utils.ErrorLog("start_time")
  10627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10628. return
  10629. }
  10630. startTime, _ := dataBody["start_time"].(string)
  10631. if len(startTime) == 0 {
  10632. utils.ErrorLog("len(start_time) == 0")
  10633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10634. return
  10635. }
  10636. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10637. if err != nil {
  10638. utils.ErrorLog(err.Error())
  10639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10640. return
  10641. }
  10642. StartTime := theTime.Unix()
  10643. advice_name, _ := dataBody["advice_name"].(string)
  10644. advice_desc, _ := dataBody["advice_desc"].(string)
  10645. delivery_way, _ := dataBody["delivery_way"].(string)
  10646. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10647. prescribing_number := dataBody["prescribing_number"].(float64)
  10648. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10649. remark := dataBody["remark"].(string)
  10650. single_dose := dataBody["single_dose"].(float64)
  10651. single_dose_unit := dataBody["single_dose_unit"].(string)
  10652. id := int64(dataBody["id"].(float64))
  10653. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10654. advice := models.XtDoctorAdviceOne{
  10655. AdviceDate: AdviceDate,
  10656. StartTime: StartTime,
  10657. AdviceName: advice_name,
  10658. AdviceDesc: advice_desc,
  10659. SingleDose: single_dose,
  10660. SingleDoseUnit: single_dose_unit,
  10661. PrescribingNumber: prescribing_number,
  10662. PrescribingNumberUnit: prescribing_number_unit,
  10663. DeliveryWay: delivery_way,
  10664. ExecutionFrequency: execution_frequency,
  10665. AdviceDoctor: advice_doctor,
  10666. Remark: remark,
  10667. RecordDate: RecordDate,
  10668. }
  10669. service.UpdateMobileDoctorAdviceById(id, advice)
  10670. c.ServeSuccessJSON(map[string]interface{}{
  10671. "advice": advice,
  10672. })
  10673. }
  10674. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10675. dataBody := make(map[string]interface{}, 0)
  10676. timeLayout := "2006-01-02"
  10677. loc, _ := time.LoadLocation("Local")
  10678. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10679. if err != nil {
  10680. utils.ErrorLog(err.Error())
  10681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10682. return
  10683. }
  10684. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10685. utils.ErrorLog("start_time")
  10686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10687. return
  10688. }
  10689. startTime2, _ := dataBody["start_time"].(string)
  10690. time_arr := strings.Split(startTime2, " ")
  10691. if len(time_arr) > 0 {
  10692. startTime2 = time_arr[0]
  10693. }
  10694. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10695. utils.ErrorLog("advice_date")
  10696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10697. return
  10698. }
  10699. advice_date, _ := dataBody["advice_date"].(string)
  10700. var advicedateunix int64
  10701. if len(advice_date) > 0 {
  10702. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10703. if err != nil {
  10704. fmt.Println(err)
  10705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10706. return
  10707. }
  10708. advicedateunix = theTime.Unix()
  10709. }
  10710. adviceDate := startTime2
  10711. if len(adviceDate) == 0 {
  10712. utils.ErrorLog("len(adviceDate) == 0")
  10713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10714. return
  10715. }
  10716. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10717. if err != nil {
  10718. utils.ErrorLog(err.Error())
  10719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10720. return
  10721. }
  10722. RecordDate := advicedateunix
  10723. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10724. utils.ErrorLog("start_time")
  10725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10726. return
  10727. }
  10728. startTime, _ := dataBody["start_time"].(string)
  10729. if len(startTime) == 0 {
  10730. utils.ErrorLog("len(start_time) == 0")
  10731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10732. return
  10733. }
  10734. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10735. if err != nil {
  10736. utils.ErrorLog(err.Error())
  10737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10738. return
  10739. }
  10740. StartTime := theTime.Unix()
  10741. patient_id := int64(dataBody["patient_id"].(float64))
  10742. group_no := int64(dataBody["group_no"].(float64))
  10743. org_id := c.GetMobileAdminUserInfo().Org.Id
  10744. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10745. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10746. utils.ErrorLog("advices")
  10747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10748. return
  10749. }
  10750. adviceNames := dataBody["advices"].([]interface{})
  10751. var advices []*models.GroupAdvice
  10752. for _, adviceNameMap := range adviceNames {
  10753. var advice models.GroupAdvice
  10754. adviceNameM := adviceNameMap.(map[string]interface{})
  10755. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10756. utils.ErrorLog("advice_name")
  10757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10758. return
  10759. }
  10760. adviceName, _ := adviceNameM["advice_name"].(string)
  10761. if len(adviceName) == 0 {
  10762. utils.ErrorLog("len(advice_name) == 0")
  10763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10764. return
  10765. }
  10766. advice.AdviceName = adviceName
  10767. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10768. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10769. advice.DrugSpec = drugSpec
  10770. }
  10771. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10772. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10773. advice.AdviceDesc = adviceDesc
  10774. }
  10775. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10776. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10777. advice.DrugSpecUnit = drugSpecUnit
  10778. }
  10779. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10780. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10781. advice.SingleDose = singleDose
  10782. }
  10783. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10784. singleDose := adviceNameM["single_dose"].(float64)
  10785. advice.SingleDose = singleDose
  10786. }
  10787. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10788. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10789. advice.SingleDoseUnit = singleDoseUnit
  10790. }
  10791. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10792. tmp := adviceNameM["single_dose_unit"].(float64)
  10793. singleDoseUnit := service.TypeConversion(tmp)
  10794. advice.SingleDoseUnit = singleDoseUnit
  10795. }
  10796. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10797. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10798. advice.PrescribingNumber = prescribingNumber
  10799. }
  10800. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10801. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10802. advice.PrescribingNumber = prescribingNumber
  10803. }
  10804. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10805. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10806. advice.PrescribingNumberUnit = prescribingNumberUnit
  10807. }
  10808. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10809. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10810. advice.DeliveryWay = deliveryWay
  10811. }
  10812. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10813. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10814. advice.ExecutionFrequency = executionFrequency
  10815. }
  10816. remark, _ := adviceNameM["remark"].(string)
  10817. advice.Remark = remark
  10818. advice.AdviceType = 1
  10819. advice.StartTime = StartTime
  10820. advice.RecordDate = RecordDate
  10821. advice.PatientId = patient_id
  10822. advice.UserOrgId = org_id
  10823. advice.AdviceDoctor = advice_doctor
  10824. advice.StopState = 2
  10825. advices = append(advices, &advice)
  10826. }
  10827. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10828. c.ServeSuccessJSON(map[string]interface{}{
  10829. "advice": newAdvices,
  10830. })
  10831. }
  10832. func (c *DialysisAPIController) StopLongAdvice() {
  10833. stop_time := c.GetString("execution_time")
  10834. id, _ := c.GetInt64("id")
  10835. if len(stop_time) <= 0 {
  10836. utils.ErrorLog("stop_time")
  10837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10838. return
  10839. }
  10840. timeLayout2 := "2006-01-02 15:04:05"
  10841. loc, _ := time.LoadLocation("Local")
  10842. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  10843. if errs != nil {
  10844. utils.ErrorLog(errs.Error())
  10845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10846. return
  10847. }
  10848. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  10849. c.ServeSuccessJSON(map[string]interface{}{
  10850. "advice": advice,
  10851. })
  10852. }