dialysis_api_controller.go 379KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592
  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 {
  474. projects = append(projects, item)
  475. }
  476. //组套里面检验项目的
  477. if item.HisProject.CostClassify == 3 {
  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. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  891. redis := service.RedisClient()
  892. //清空key 值
  893. redis.Set(key, "", time.Second)
  894. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  895. redis.Set(keyOne, "", time.Second)
  896. defer redis.Close()
  897. if err == nil {
  898. c.ServeSuccessJSON(map[string]interface{}{
  899. "doubleCheck": &doubleCheck,
  900. })
  901. }
  902. } else { //修改
  903. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  904. if infor.ID > 0 {
  905. var cha_time int64
  906. timeNowStr := time.Now().Format("2006-01-02")
  907. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  908. //今日的日期减去设置的日期
  909. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  910. if cha_time >= recordDate.Unix() {
  911. //查询审核是否允许
  912. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  913. //申请状态不允许的情况 拒绝修改
  914. if infor.ApplicationStatus != 1 {
  915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  916. return
  917. }
  918. }
  919. }
  920. doubleCheck.FirstCheckTime = firstCheckDate
  921. doubleCheck.CheckTime = checkDate
  922. doubleCheck.Creater = creater
  923. doubleCheck.Modifier = modifier
  924. doubleCheck.CreatedTime = check.CreatedTime
  925. doubleCheck.ID = check.ID
  926. doubleCheck.EmployeeNumber = employee_number
  927. doubleCheck.NeedleBatchNumber = needle_batch_number
  928. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  929. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  930. //查询未核对的医嘱
  931. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  932. for _, advice := range doctorList {
  933. if advice.ExecutionStaff == modifier {
  934. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  935. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  936. return
  937. }
  938. }
  939. }
  940. err := service.UpdateDoubleCheck(&doubleCheck)
  941. //针对长沙南雅
  942. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  943. //查询未核对的医嘱
  944. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  945. if len(doctorList) > 0 && modifier > 0 {
  946. for _, advice := range doctorList {
  947. service.UpdateDoctorAdviceList(advice.ID, modifier)
  948. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  949. redis := service.RedisClient()
  950. //清空key 值
  951. redis.Set(key, "", time.Second)
  952. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  953. redis.Set(keyTwo, "", time.Second)
  954. theTime := time.Now()
  955. recordDate := theTime.Format("2006-01-02")
  956. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  957. redis.Set(keyFour, "", time.Second)
  958. defer redis.Close()
  959. }
  960. }
  961. }
  962. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  963. redis := service.RedisClient()
  964. //清空key 值
  965. redis.Set(key, "", time.Second)
  966. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  967. redis.Set(keyOne, "", time.Second)
  968. defer redis.Close()
  969. if err == nil {
  970. c.ServeSuccessJSON(map[string]interface{}{
  971. "doubleCheck": &doubleCheck,
  972. "msg": "1",
  973. })
  974. }
  975. }
  976. }
  977. func (c *DialysisAPIController) PostAcceptsAssessment() {
  978. id, _ := c.GetInt64("patient", 0)
  979. recordDateStr := c.GetString("record_date")
  980. way, _ := c.GetInt64("way", 0)
  981. consciousness, _ := c.GetInt64("consciousness", 0)
  982. appetite, _ := c.GetInt64("appetite", 0)
  983. condition, _ := c.GetInt64("condition", 0)
  984. posture, _ := c.GetInt64("posture")
  985. sick_condition, _ := c.GetInt64("sick_condition", 0)
  986. danger_level, _ := c.GetInt64("danger_level", 0)
  987. intake, _ := c.GetInt64("intake", 0)
  988. nutrition, _ := c.GetInt64("nutrition", 0)
  989. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  990. psychological_assessment_other := c.GetString("psychological_assessment_other")
  991. score := c.GetString("score")
  992. sick_condition_other := c.GetString("sick_condition_other")
  993. //precaution, _ := c.GetInt64("precaution", 0)
  994. precaution := c.GetString("precaution")
  995. precaution_other := c.GetString("precaution_other")
  996. psychological_other := c.GetString("psychological_other")
  997. admission_number := c.GetString("admission_number")
  998. tumble, _ := c.GetInt64("tumble")
  999. diacrisis := c.GetString("diacrisis")
  1000. his_department := c.GetString("his_department")
  1001. his_bed := c.GetString("his_bed")
  1002. if id <= 0 {
  1003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1004. return
  1005. }
  1006. adminUserInfo := c.GetMobileAdminUserInfo()
  1007. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1008. if patient.ID == 0 {
  1009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1010. return
  1011. }
  1012. //now := time.Now()
  1013. //year, month, day := now.Date()
  1014. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1015. //todayTimeStamp := today_time.Unix()
  1016. if len(recordDateStr) == 0 {
  1017. recordDateStr = time.Now().Format("2006-01-02")
  1018. }
  1019. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1020. if parseDateErr != nil {
  1021. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1023. return
  1024. }
  1025. // 查询信息规挡的设置天数
  1026. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1027. if infor.ID > 0 && infor.WeekDay > 0 {
  1028. var cha_time int64
  1029. timeNowStr := time.Now().Format("2006-01-02")
  1030. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1031. //今日的日期减去设置的日期
  1032. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1033. if cha_time >= recordDate.Unix() {
  1034. //查询审核是否允许
  1035. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1036. //申请状态不允许的情况 拒绝修改
  1037. if infor.ApplicationStatus != 1 {
  1038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1039. return
  1040. }
  1041. }
  1042. }
  1043. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1044. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1045. UserOrgId: adminUserInfo.Org.Id,
  1046. PatientId: id,
  1047. RecordDate: recordDate.Unix(),
  1048. Way: way,
  1049. Consciousness: consciousness,
  1050. Appetite: appetite,
  1051. Condition: condition,
  1052. SickCondition: sick_condition,
  1053. DangerLevel: danger_level,
  1054. Intake: intake,
  1055. Nutrition: nutrition,
  1056. PsychologicalAssessment: psychological_assessment,
  1057. PsychologicalAssessmentOther: psychological_assessment_other,
  1058. SickConditionOther: sick_condition_other,
  1059. Posture: posture,
  1060. CreatedTime: time.Now().Unix(),
  1061. UpdateTime: time.Now().Unix(),
  1062. Status: 1,
  1063. Score: score,
  1064. Precaution: precaution,
  1065. PrecautionOther: precaution_other,
  1066. PsychologicalOther: psychological_other,
  1067. AdmissionNumber: admission_number,
  1068. Tumble: tumble,
  1069. Diacrisis: diacrisis,
  1070. HisBed: his_bed,
  1071. HisDepartment: his_department,
  1072. }
  1073. if receiveTreatment.ID == 0 { //新增
  1074. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1075. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1076. finish := models.XtDialysisFinish{
  1077. IsFinish: 1,
  1078. UserOrgId: adminUserInfo.Org.Id,
  1079. Status: 1,
  1080. Ctime: time.Now().Unix(),
  1081. Mtime: 0,
  1082. Module: 2,
  1083. RecordDate: recordDate.Unix(),
  1084. Sourse: 1,
  1085. PatientId: id,
  1086. }
  1087. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1088. if dialysisFinish.ID == 0 {
  1089. service.CreateDialysisFinish(finish)
  1090. }
  1091. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1092. redis := service.RedisClient()
  1093. defer redis.Close()
  1094. //清空key 值
  1095. redis.Set(key, "", time.Second)
  1096. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1097. redis.Set(keyOne, "", time.Second)
  1098. if err == nil {
  1099. c.ServeSuccessJSON(map[string]interface{}{
  1100. "receiveTreatmentAsses": receiveTreatmentAsses,
  1101. })
  1102. }
  1103. } else { //修改
  1104. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1105. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1106. // if getPermissionErr != nil {
  1107. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1108. // return
  1109. // } else if headNursePermission == nil {
  1110. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1111. // return
  1112. // }
  1113. //}
  1114. // 查询信息规挡的设置天数
  1115. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1116. if infor.ID > 0 && infor.WeekDay > 0 {
  1117. var cha_time int64
  1118. timeNowStr := time.Now().Format("2006-01-02")
  1119. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1120. //今日的日期减去设置的日期
  1121. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1122. if cha_time >= recordDate.Unix() {
  1123. //查询审核是否允许
  1124. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1125. //申请状态不允许的情况 拒绝修改
  1126. if infor.ApplicationStatus != 1 {
  1127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1128. return
  1129. }
  1130. }
  1131. }
  1132. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1133. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1134. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1135. receiveTreatmentAsses.ID = receiveTreatment.ID
  1136. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1137. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1138. redis := service.RedisClient()
  1139. defer redis.Close()
  1140. //清空key 值
  1141. redis.Set(key, "", time.Second)
  1142. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1143. redis.Set(keyOne, "", time.Second)
  1144. if err == nil {
  1145. c.ServeSuccessJSON(map[string]interface{}{
  1146. "receiveTreatmentAsses": receiveTreatmentAsses,
  1147. })
  1148. }
  1149. }
  1150. }
  1151. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1152. id, _ := c.GetInt64("patient", 0)
  1153. recordDateStr := c.GetString("record_date")
  1154. weightAfter, _ := c.GetFloat("weight_after", 0)
  1155. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1156. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1157. fmt.Println("weight_loss", weightReduce)
  1158. temperature, _ := c.GetFloat("temperature", 0)
  1159. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1160. breathing_rate := c.GetString("breathing_rate")
  1161. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1162. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1163. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1164. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1165. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1166. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1167. cruor := c.GetString("cruor")
  1168. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1169. internalFistula := c.GetString("internal_fistula")
  1170. catheter := c.GetString("catheter")
  1171. complications := c.GetString("complication")
  1172. remark := c.GetString("remark")
  1173. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1174. dialysis_intakes := c.GetString("dialysis_intakes")
  1175. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1176. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1177. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1178. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1179. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1180. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1181. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1182. patientGose, _ := c.GetInt64("patient_gose", 0)
  1183. inpatientDepartment := c.GetString("inpatient_department")
  1184. observationContent := c.GetString("observation_content")
  1185. observationContentOther := c.GetString("observation_content_other")
  1186. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1187. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1188. in_advance_reason := c.GetString("in_advance_reason")
  1189. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1190. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1191. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1192. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1193. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1194. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1195. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1196. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1197. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1198. is_eat, _ := c.GetInt64("is_eat", 0)
  1199. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1200. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1201. channels, _ := c.GetInt64("channel", 0)
  1202. return_blood, _ := c.GetInt64("return_blood", 0)
  1203. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1204. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1205. dialysis_during, _ := c.GetFloat("dialysis_during")
  1206. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1207. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1208. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1209. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1210. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1211. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1212. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1213. setting_pressure := c.GetString("setting_pressure")
  1214. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1215. diastolic_pressure := c.GetString("diastolic_pressure")
  1216. other_complication := c.GetString("other_complication")
  1217. ktv := c.GetString("ktv")
  1218. urr := c.GetString("urr")
  1219. hypertenison, _ := c.GetInt64("hypertenison")
  1220. hypopiesia, _ := c.GetInt64("hypopiesia")
  1221. leave_office_method, _ := c.GetInt64("leave_office_method")
  1222. lapse, _ := c.GetInt64("lapse")
  1223. consciousness, _ := c.GetInt64("consciousness")
  1224. fallrisk, _ := c.GetInt64("fallrisk")
  1225. machine_run := c.GetString("machine_run")
  1226. after_urea := c.GetString("after_urea")
  1227. pip_coagulation := c.GetString("pip_coagulation")
  1228. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1229. transfusion_volume := c.GetString("transfusion_volume")
  1230. last_after_weight := c.GetString("last_after_weight")
  1231. displace_liqui_value := c.GetString("displace_liqui_value")
  1232. if id <= 0 {
  1233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1234. return
  1235. }
  1236. adminUserInfo := c.GetMobileAdminUserInfo()
  1237. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1238. if patient.ID == 0 {
  1239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1240. return
  1241. }
  1242. if len(recordDateStr) == 0 {
  1243. recordDateStr = time.Now().Format("2006-01-02")
  1244. }
  1245. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1246. fmt.Println("parseDateErr", parseDateErr)
  1247. if parseDateErr != nil {
  1248. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1250. return
  1251. }
  1252. //now := time.Now()
  1253. //year, month, day := now.Date()
  1254. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1255. //todayTimeStamp := today_time.Unix()
  1256. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1257. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1258. UserOrgId: adminUserInfo.Org.Id,
  1259. PatientId: id,
  1260. AssessmentDate: recordDate.Unix(),
  1261. Temperature: temperature,
  1262. PulseFrequency: pulse_frequency,
  1263. BreathingRate: breathing_rate,
  1264. SystolicBloodPressure: systolic_blood_pressure,
  1265. DiastolicBloodPressure: diastolic_blood_pressure,
  1266. ActualUltrafiltration: actual_ultrafiltration,
  1267. ActualDisplacement: actual_displacement,
  1268. ActualTreatmentHour: actualtreatHour,
  1269. ActualTreatmentMinute: actualtreatmin,
  1270. WeightAfter: weightAfter,
  1271. AdditionalWeight: additionalWeight,
  1272. WeightLoss: weightReduce,
  1273. Cruor: cruor,
  1274. SymptomAfterDialysis: symptomsAfterDialysi,
  1275. InternalFistula: internalFistula,
  1276. Catheter: catheter,
  1277. Complication: complications,
  1278. DialysisIntakes: dialysateVolume,
  1279. CreatedTime: time.Now().Unix(),
  1280. UpdatedTime: time.Now().Unix(),
  1281. Status: 1,
  1282. Remark: remark,
  1283. BloodAccessPartId: blood_access_part_id,
  1284. BloodAccessPartOperaId: blood_access_part_opera_id,
  1285. DialysisIntakesUnit: dialysis_intakes_unit,
  1286. PuncturePointOozingBlood: puncturePointOozingBlood,
  1287. PuncturePointHaematoma: puncturePointHaematoma,
  1288. InternalFistulaTremorAc: internalFistulaTremorAc,
  1289. PatientGose: patientGose,
  1290. InpatientDepartment: inpatientDepartment,
  1291. ObservationContent: observationContent,
  1292. ObservationContentOther: observationContentOther,
  1293. DialysisProcess: dialysis_process,
  1294. InAdvanceMinute: in_advance_minute,
  1295. InAdvanceReason: in_advance_reason,
  1296. HemostasisMinute: hemostasis_minute,
  1297. HemostasisOpera: hemostasis_opera,
  1298. TremorNoise: tremor_noise,
  1299. DisequilibriumSyndrome: disequilibrium_syndrome,
  1300. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1301. ArterialTube: arterial_tube,
  1302. IntravenousTube: intravenous_tube,
  1303. Dialyzer: dialyzer,
  1304. InAdvanceReasonOther: in_advance_reason_other,
  1305. IsEat: is_eat,
  1306. CvcA: cvc_a,
  1307. CvcV: cvc_v,
  1308. Channel: channels,
  1309. ReturnBlood: return_blood,
  1310. RehydrationVolume: rehydration_volume,
  1311. DialysisDuring: dialysis_during,
  1312. StrokeVolume: stroke_volume,
  1313. BloodFlow: blood_flow,
  1314. SealingFluidDispose: sealing_fluid_dispose,
  1315. SealingFluidSpecial: sealing_fluid_special,
  1316. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1317. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1318. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1319. SettingPressure: setting_pressure,
  1320. DiastolicPressure: diastolic_pressure,
  1321. OtherComplication: other_complication,
  1322. Ktv: ktv,
  1323. Urr: urr,
  1324. Hypopiesia: hypopiesia,
  1325. Hypertenison: hypertenison,
  1326. Lapse: lapse,
  1327. LeaveOfficeMethod: leave_office_method,
  1328. Consciousness: consciousness,
  1329. Fallrisk: fallrisk,
  1330. MachineRun: machine_run,
  1331. AfterUrea: after_urea,
  1332. PipCoagulation: pip_coagulation,
  1333. AccumulatedBloodVolume: accumulated_blood_volume,
  1334. TransfusionVolume: transfusion_volume,
  1335. LastAfterWeight: last_after_weight,
  1336. DisplaceLiquiValue: displace_liqui_value,
  1337. }
  1338. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1339. // 查询信息规挡的设置天数
  1340. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1341. if infor.ID > 0 && infor.WeekDay > 0 {
  1342. var cha_time int64
  1343. timeNowStr := time.Now().Format("2006-01-02")
  1344. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1345. //今日的日期减去设置的日期
  1346. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1347. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1348. if cha_time >= recordDate.Unix() {
  1349. //查询审核是否允许
  1350. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1351. //申请状态不允许的情况 拒绝修改
  1352. if infor.ApplicationStatus != 1 {
  1353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1354. return
  1355. }
  1356. }
  1357. }
  1358. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1359. if assessmentAfter.ID == 0 { //新增
  1360. if appRole.UserType == 2 || appRole.UserType == 1 {
  1361. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1362. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1363. } else {
  1364. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1365. }
  1366. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1367. if assessmentAfterDislysis.UserOrgId != 10340 {
  1368. if assessmentAfterDislysis.WeightAfter == 0 {
  1369. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1370. }
  1371. }
  1372. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1373. //记录日志
  1374. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1375. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1376. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1377. PatientId: assessmentAfterDislysis.PatientId,
  1378. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1379. Status: 1,
  1380. ErrLog: string(byterequest),
  1381. AdminUserId: adminUserInfo.AdminUser.Id,
  1382. Ctime: 0,
  1383. Mtime: 0,
  1384. Source: "手机端保存透后评估",
  1385. }
  1386. service.CreateAfterDialysisLog(afterDialysisLog)
  1387. finish := models.XtDialysisFinish{
  1388. IsFinish: 1,
  1389. UserOrgId: adminUserInfo.Org.Id,
  1390. Status: 1,
  1391. Ctime: time.Now().Unix(),
  1392. Mtime: 0,
  1393. Module: 9,
  1394. RecordDate: recordDate.Unix(),
  1395. Sourse: 1,
  1396. PatientId: id,
  1397. }
  1398. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1399. if dialysisFinish.ID == 0 {
  1400. service.CreateDialysisFinish(finish)
  1401. }
  1402. redis := service.RedisClient()
  1403. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1404. redis.Set(keyTwo, "", time.Second)
  1405. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1406. //清空key 值
  1407. redis.Set(key, "", time.Second)
  1408. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1409. redis.Set(keyOne, "", time.Second)
  1410. defer redis.Close()
  1411. if err == nil {
  1412. c.ServeSuccessJSON(map[string]interface{}{
  1413. "assessmentAfterDislysis": assessmentAfterDislysis,
  1414. })
  1415. }
  1416. return
  1417. } else { //修改
  1418. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1419. if infor.ID > 0 && infor.WeekDay > 0 {
  1420. var cha_time int64
  1421. timeNowStr := time.Now().Format("2006-01-02")
  1422. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1423. //今日的日期减去设置的日期
  1424. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1425. if cha_time >= recordDate.Unix() {
  1426. //查询审核是否允许
  1427. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1428. //申请状态不允许的情况 拒绝修改
  1429. if infor.ApplicationStatus != 1 {
  1430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1431. return
  1432. }
  1433. }
  1434. }
  1435. if appRole.UserType == 2 || appRole.UserType == 1 {
  1436. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1437. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1438. } else {
  1439. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1440. if assessmentAfterDislysis.Creater == 0 {
  1441. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1442. }
  1443. }
  1444. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1445. assessmentAfterDislysis.ID = assessmentAfter.ID
  1446. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1447. if assessmentAfterDislysis.UserOrgId != 10340 {
  1448. if assessmentAfterDislysis.WeightAfter == 0 {
  1449. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1450. }
  1451. }
  1452. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1453. //记录日志
  1454. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1455. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1456. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1457. PatientId: assessmentAfterDislysis.PatientId,
  1458. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1459. Status: 1,
  1460. ErrLog: string(byterequest),
  1461. AdminUserId: adminUserInfo.AdminUser.Id,
  1462. Ctime: time.Now().Unix(),
  1463. Mtime: 0,
  1464. Source: "手机端修改保存透后评估",
  1465. }
  1466. service.CreateAfterDialysisLog(afterDialysisLog)
  1467. redis := service.RedisClient()
  1468. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1469. redis.Set(keyTwo, "", time.Second)
  1470. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1471. //清空key 值
  1472. redis.Set(key, "", time.Second)
  1473. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1474. redis.Set(keyOne, "", time.Second)
  1475. if err == nil {
  1476. c.ServeSuccessJSON(map[string]interface{}{
  1477. "assessmentAfterDislysis": assessmentAfterDislysis,
  1478. })
  1479. return
  1480. }
  1481. }
  1482. return
  1483. }
  1484. func (c *DialysisAPIController) PostDialysisPrescription() {
  1485. id, _ := c.GetInt64("patient", 0)
  1486. recordDateStr := c.GetString("record_date")
  1487. if id <= 0 {
  1488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1489. return
  1490. }
  1491. adminUserInfo := c.GetMobileAdminUserInfo()
  1492. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1493. if patient.ID == 0 {
  1494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1495. return
  1496. }
  1497. if len(recordDateStr) == 0 {
  1498. recordDateStr = time.Now().Format("2006-01-02")
  1499. }
  1500. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1501. if parseDateErr != nil {
  1502. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1504. return
  1505. }
  1506. mode_id, _ := c.GetInt64("mode_id", 0)
  1507. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1508. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1509. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1510. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1511. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1512. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1513. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1514. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1515. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1516. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1517. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1518. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1519. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1520. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1521. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1522. kalium, _ := c.GetFloat("kalium", 0)
  1523. sodium, _ := c.GetFloat("sodium", 0)
  1524. calcium, _ := c.GetFloat("calcium", 0)
  1525. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1526. glucose, _ := c.GetFloat("glucose", 0)
  1527. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1528. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1529. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1530. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1531. conductivity, _ := c.GetFloat("conductivity", 0)
  1532. remark := c.GetString("remark")
  1533. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1534. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1535. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1536. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1537. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1538. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1539. special_medicine_other := c.GetString("special_medicine_other")
  1540. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1541. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1542. blood_access, _ := c.GetInt64("blood_access", 0)
  1543. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1544. body_fluid_other := c.GetString("body_fluid_other")
  1545. niprocart, _ := c.GetInt64("niprocart", 0)
  1546. jms, _ := c.GetInt64("jms", 0)
  1547. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1548. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1549. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1550. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1551. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1552. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1553. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1554. injector, _ := c.GetInt64("injector", 0)
  1555. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1556. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1557. safe_package, _ := c.GetInt64("package", 0)
  1558. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1559. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1560. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1561. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1562. blood := c.GetString("blood")
  1563. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1564. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1565. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1566. displace_speed := c.GetString("displace_speed")
  1567. illness, _ := c.GetInt64("illness")
  1568. amylaceum := c.GetString("amylaceum")
  1569. single_time := c.GetString("single_time")
  1570. single_water := c.GetString("single_water")
  1571. replacement_flow := c.GetString("replacement_flow")
  1572. plasma_separator := c.GetString("plasma_separator")
  1573. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1574. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1575. oxygen_flow := c.GetString("oxygen_flow")
  1576. oxygen_time := c.GetString("oxygen_time")
  1577. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1578. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1579. puncture_needle := c.GetString("puncture_needle")
  1580. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1581. epo := c.GetString("epo")
  1582. epo_count, _ := c.GetFloat("epo_count", 0)
  1583. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1584. admin_user_id, _ := c.GetInt64("admin_user_id")
  1585. is_water := c.GetString("is_water")
  1586. var is_war int64
  1587. if is_water == "是" {
  1588. is_war = 1
  1589. }
  1590. if is_water == "否" {
  1591. is_war = 2
  1592. }
  1593. if is_water == "请选择" {
  1594. is_war = 0
  1595. }
  1596. drhy_water := c.GetString("drhy_water")
  1597. dry_water_hour := c.GetString("dry_water_hour")
  1598. water_machine := c.GetString("water_machine")
  1599. add_amount, _ := c.GetFloat("add_amount")
  1600. reduce_amount, _ := c.GetFloat("reduce_amount")
  1601. dialysis_remark := c.GetString("dialysis_remark")
  1602. prescribing_number, _ := c.GetFloat("prescribing_number")
  1603. prescription_sodium := c.GetString("prescription_sodium")
  1604. start_sodium := c.GetString("start_sodium")
  1605. sodium_curve := c.GetString("sodium_curve")
  1606. treatment_remark := c.GetString("treatment_remark")
  1607. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1608. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1609. prescription_water, _ := c.GetFloat("prescription_water")
  1610. dialysis_strainer := c.GetString("dialysis_strainer")
  1611. chaptalization := c.GetString("chaptalization")
  1612. washing_time := c.GetString("washing_time")
  1613. warsh_count := c.GetString("warsh_count")
  1614. blood_access_part_id := c.GetString("blood_access_part_id")
  1615. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1616. dialyzate := c.GetString("dialyzate")
  1617. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1618. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1619. //
  1620. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1621. // if appRole.UserType == 3 {
  1622. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1623. // if getPermissionErr != nil {
  1624. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1625. // return
  1626. // } else if headNursePermission == nil {
  1627. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1628. // return
  1629. // }
  1630. // }
  1631. //}
  1632. // 查询信息规挡的设置天数
  1633. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1634. if infor.ID > 0 && infor.WeekDay > 0 {
  1635. var cha_time int64
  1636. timeNowStr := time.Now().Format("2006-01-02")
  1637. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1638. //今日的日期减去设置的日期
  1639. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1640. if cha_time >= recordDate.Unix() {
  1641. //查询审核是否允许
  1642. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1643. //申请状态不允许的情况 拒绝修改
  1644. if infor.ApplicationStatus != 1 {
  1645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1646. return
  1647. }
  1648. }
  1649. }
  1650. if mode_id > 0 {
  1651. var str string
  1652. //查找该机构用的是什么透析器
  1653. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1654. if filedConfig.ID > 0 {
  1655. str = dialyzerPerfusionApparatus
  1656. } else {
  1657. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1658. }
  1659. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1660. }
  1661. //TODO 需要根据角色去判断
  1662. prescription := models.DialysisPrescription{
  1663. UserOrgId: adminUserInfo.Org.Id,
  1664. PatientId: id,
  1665. RecordDate: recordDate.Unix(),
  1666. ModeId: mode_id,
  1667. DialysisDuration: dialysis_duration,
  1668. Dialyzer: dialyzer,
  1669. PerfusionApparatus: perfusion_apparatus,
  1670. BloodFlowVolume: blood_flow_volume,
  1671. DewaterAmount: dewater_amount,
  1672. DisplaceLiqui: displace_liqui,
  1673. ReplacementWay: replacement_way,
  1674. Anticoagulant: anticoagulant,
  1675. AnticoagulantShouji: anticoagulant_shouji,
  1676. AnticoagulantWeichi: anticoagulant_weichi,
  1677. AnticoagulantZongliang: anticoagulant_zongliang,
  1678. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1679. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1680. Kalium: kalium,
  1681. Sodium: sodium,
  1682. Calcium: calcium,
  1683. Bicarbonate: bicarbonate,
  1684. Glucose: glucose,
  1685. // DryWeight: dry_weight,
  1686. DialysateFlow: dialysate_flow,
  1687. DialysateTemperature: dialysate_temperature,
  1688. // PrescriptionDoctor: prescription_doctor,
  1689. ReplacementTotal: replacement_total,
  1690. Conductivity: conductivity,
  1691. Remark: remark,
  1692. Status: 1,
  1693. CreatedTime: time.Now().Unix(),
  1694. UpdatedTime: time.Now().Unix(),
  1695. DialysisDurationMinute: dialysisDurationMinute,
  1696. DialysisDurationHour: dialysisDurationHour,
  1697. TargetUltrafiltration: targetUltrafiltration,
  1698. DialysateFormulation: dialysateFormulation,
  1699. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1700. BodyFluid: body_fluid,
  1701. SpecialMedicine: special_medicine,
  1702. SpecialMedicineOther: special_medicine_other,
  1703. DisplaceLiquiPart: displace_liqui_part,
  1704. DisplaceLiquiValue: displace_liqui_value,
  1705. BloodAccess: blood_access,
  1706. Ultrafiltration: ultrafiltration,
  1707. BodyFluidOther: body_fluid_other,
  1708. Niprocart: niprocart,
  1709. Jms: jms,
  1710. FistulaNeedleSet: fistula_needle_set,
  1711. FistulaNeedleSet16: fistula_needle_set_16,
  1712. Hemoperfusion: hemoperfusion,
  1713. DialyserSterilised: dialyser_sterilised,
  1714. Filtryzer: filtryzer,
  1715. Dialyzers: dialyzers,
  1716. Injector: injector,
  1717. Bloodlines: bloodlines,
  1718. TubingHemodialysis: tubing_hemodialysis,
  1719. Package: safe_package,
  1720. ALiquid: a_liquid,
  1721. TargetKtv: target_ktv,
  1722. PreImpulse: pre_impulse,
  1723. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1724. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1725. Blood: blood,
  1726. DialysisDialyszers: dialysis_dialyszers,
  1727. DialysisIrrigation: dialysis_irrigation,
  1728. AntioxidantCommodityName: antioxidant_commodity_name,
  1729. DisplaceSpeed: displace_speed,
  1730. Illness: illness,
  1731. Amylaceum: amylaceum,
  1732. SingleTime: single_time,
  1733. SingleWater: single_water,
  1734. ReplacementFlow: replacement_flow,
  1735. PlasmaSeparator: plasma_separator,
  1736. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1737. OxygenUptake: oxygen_uptake,
  1738. OxygenFlow: oxygen_flow,
  1739. OxygenTime: oxygen_time,
  1740. HemodialysisPipelines: hemodialysis_pipelines,
  1741. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1742. PunctureNeedle: puncture_needle,
  1743. PunctureNeedleCount: puncture_needle_count,
  1744. Epo: epo,
  1745. EpoCount: epo_count,
  1746. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1747. AdminUserId: admin_user_id,
  1748. IsWater: is_war,
  1749. DrhyWater: drhy_water,
  1750. DryWaterHour: dry_water_hour,
  1751. WaterMachine: water_machine,
  1752. AddAmount: add_amount,
  1753. ReduceAmount: reduce_amount,
  1754. DialysisRemark: dialysis_remark,
  1755. PrescribingNumber: prescribing_number,
  1756. StartSodium: start_sodium,
  1757. SodiumCurve: sodium_curve,
  1758. TreatmentRemark: treatment_remark,
  1759. PrescriptionSodium: prescription_sodium,
  1760. DialysisFluidFlow: dialysis_fluid_flow,
  1761. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1762. PrescriptionWater: prescription_water,
  1763. DialysisStrainer: dialysis_strainer,
  1764. Chaptalization: chaptalization,
  1765. WashingTime: washing_time,
  1766. WarshCount: warsh_count,
  1767. BloodAccessPartId: blood_access_part_id,
  1768. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1769. Dialyzate: dialyzate,
  1770. }
  1771. //查询最近透析准备表里是否存在 透析器 灌流器
  1772. //
  1773. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1774. //
  1775. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1776. //
  1777. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1778. //if len(mation)>0{
  1779. // for _, item := range splitStr {
  1780. // for _,it := range mation{
  1781. // if(item == it.SpecificationName){
  1782. //
  1783. // //查询最近一次的透析器
  1784. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1785. //
  1786. // if errcode == gorm.ErrRecordNotFound{
  1787. // //插入数据
  1788. // prepare := models.DialysisBeforePrepare{
  1789. // UserOrgId: adminUserInfo.Org.Id,
  1790. // PatientId: id,
  1791. // RecordDate: recordDate.Unix(),
  1792. // GoodTypeId: it.GoodTypeId,
  1793. // GoodId: it.ID,
  1794. // Count: 1,
  1795. // Ctime: time.Now().Unix(),
  1796. // Creater: adminUserInfo.AdminUser.Id,
  1797. // Status:1,
  1798. //
  1799. // }
  1800. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1801. // fmt.Println("",errcode)
  1802. // }
  1803. // }
  1804. // }
  1805. //
  1806. // }
  1807. //
  1808. // for _, item := range splitIrrigation {
  1809. // for _,it := range mation{
  1810. // if(item == it.SpecificationName){
  1811. // //查询最近一次的透析器
  1812. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1813. // if errcode == gorm.ErrRecordNotFound{
  1814. // //插入数据
  1815. // prepare := models.DialysisBeforePrepare{
  1816. // UserOrgId: adminUserInfo.Org.Id,
  1817. // PatientId: id,
  1818. // RecordDate: recordDate.Unix(),
  1819. // GoodTypeId: it.GoodTypeId,
  1820. // GoodId: it.ID,
  1821. // Count: 1,
  1822. // Ctime: time.Now().Unix(),
  1823. // Creater: adminUserInfo.AdminUser.Id,
  1824. // Status:1,
  1825. //
  1826. // }
  1827. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1828. // fmt.Println(errcode)
  1829. // }
  1830. // }
  1831. // }
  1832. // }
  1833. //}
  1834. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1835. if dialysisPrescription.ID == 0 { //新增
  1836. if appRole.UserType == 2 || appRole.UserType == 1 {
  1837. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1838. }
  1839. prescription.Creater = adminUserInfo.AdminUser.Id
  1840. //针对河间咸得
  1841. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1842. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1843. prescription.DisplaceLiquiPart = 0
  1844. prescription.DisplaceLiquiValue = 0
  1845. }
  1846. }
  1847. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1848. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1849. }
  1850. err := service.AddSigleRecord(&prescription)
  1851. //记录日志
  1852. byterequest, _ := json.Marshal(prescription)
  1853. prescriptionLog := models.XtDialysisPrescriptionLog{
  1854. UserOrgId: prescription.UserOrgId,
  1855. Ctime: time.Now().Unix(),
  1856. Mtime: 0,
  1857. ErrLog: string(byterequest),
  1858. AdminUserId: adminUserInfo.AdminUser.Id,
  1859. RecordDate: prescription.RecordDate,
  1860. PatientId: prescription.PatientId,
  1861. Source: "手机端新增保存处方",
  1862. Status: 1,
  1863. }
  1864. service.CreatePrescriptionLog(prescriptionLog)
  1865. finish := models.XtDialysisFinish{
  1866. IsFinish: 1,
  1867. UserOrgId: adminUserInfo.Org.Id,
  1868. Status: 1,
  1869. Ctime: time.Now().Unix(),
  1870. Mtime: 0,
  1871. Module: 1,
  1872. RecordDate: recordDate.Unix(),
  1873. Sourse: 1,
  1874. PatientId: id,
  1875. }
  1876. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1877. if dialysisFinish.ID == 0 {
  1878. service.CreateDialysisFinish(finish)
  1879. }
  1880. //长沙南雅医院,自动生成抗凝剂的临时处方
  1881. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1882. if prescribing_number == 0 {
  1883. prescribing_number = 1
  1884. }
  1885. if prescribing_number == 0 && id == 14682 {
  1886. prescribing_number = 2
  1887. }
  1888. if prescribing_number == 0 && id == 18560 {
  1889. prescribing_number = 2
  1890. }
  1891. advice := models.DoctorAdvice{
  1892. UserOrgId: adminUserInfo.Org.Id,
  1893. PatientId: id,
  1894. GroupNo: 0,
  1895. AdviceType: 2,
  1896. RecordDate: recordDate.Unix(),
  1897. AdviceDate: recordDate.Unix(),
  1898. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1899. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1900. AdviceDesc: "",
  1901. ReminderDate: 0,
  1902. SingleDose: anticoagulant_zongliang,
  1903. SingleDoseUnit: "iu",
  1904. DrugSpec: 0,
  1905. DrugSpecUnit: "",
  1906. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1907. PrescribingNumberUnit: "支",
  1908. DeliveryWay: "静脉注射",
  1909. ExecutionFrequency: "上机前",
  1910. AdviceDoctor: 0,
  1911. Status: 1,
  1912. CreatedTime: time.Now().Unix(),
  1913. UpdatedTime: time.Now().Unix(),
  1914. IsPrescription: 1,
  1915. ExecutionState: 2,
  1916. StopState: 2,
  1917. IsSettle: 2,
  1918. }
  1919. // 查询排班信息
  1920. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1921. if schedulePatient.ID > 0 {
  1922. if schedulePatient.ScheduleType == 1 {
  1923. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1924. }
  1925. if schedulePatient.ScheduleType == 2 {
  1926. advice.StartTime = recordDate.Unix() + 9*60*60
  1927. }
  1928. }
  1929. // 抗凝剂名称
  1930. switch anticoagulant {
  1931. case 1:
  1932. advice.AdviceName = "无肝素"
  1933. break
  1934. case 2:
  1935. advice.AdviceName = "普通肝素"
  1936. break
  1937. case 3:
  1938. advice.AdviceName = "低分子肝素"
  1939. break
  1940. case 4:
  1941. advice.AdviceName = "阿加曲班"
  1942. break
  1943. case 5:
  1944. advice.AdviceName = "枸橼酸钠"
  1945. break
  1946. case 6:
  1947. advice.AdviceName = "低分子肝素钙"
  1948. break
  1949. case 7:
  1950. advice.AdviceName = "低分子肝素钠"
  1951. break
  1952. case 8:
  1953. advice.AdviceName = "依诺肝素"
  1954. break
  1955. case 9:
  1956. advice.AdviceName = "达肝素"
  1957. break
  1958. case 10:
  1959. advice.AdviceName = "体外抗凝"
  1960. break
  1961. case 11:
  1962. advice.AdviceName = "那曲肝素"
  1963. break
  1964. case 12:
  1965. advice.AdviceName = "无抗凝剂"
  1966. break
  1967. }
  1968. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1969. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  1970. advice.AdviceDoctor = appRole.AdminUserId
  1971. }
  1972. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1973. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  1974. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1975. advice.AdviceName = "低分子肝素钠注射液"
  1976. // 修改患者临时医嘱里的抗凝剂医嘱
  1977. advice.ID = advicePrescription.ID
  1978. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1979. } else {
  1980. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1981. advice.AdviceName = "低分子肝素钠注射液"
  1982. // 新增患者临时医嘱里的抗凝剂医嘱
  1983. service.CreateDoctorAdvice(&advice)
  1984. }
  1985. }
  1986. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1987. redis := service.RedisClient()
  1988. defer redis.Close()
  1989. //清空key 值
  1990. redis.Set(key, "", time.Second)
  1991. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1992. redis.Set(keyOne, "", time.Second)
  1993. }
  1994. //获取key,清空redis
  1995. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1996. redis := service.RedisClient()
  1997. //清空key 值
  1998. redis.Set(key, "", time.Second)
  1999. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2000. //清空key 值
  2001. redis.Set(keyOne, "", time.Second)
  2002. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2003. //清空key 值
  2004. redis.Set(keyTwo, "", time.Second)
  2005. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2006. redis.Set(keySix, "", time.Second)
  2007. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2008. redis.Set(keySeven, "", time.Second)
  2009. if err == nil {
  2010. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2011. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2012. //清空key 值
  2013. redis.Set(keyThree, "", time.Second)
  2014. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2015. //清空key 值
  2016. redis.Set(keyFour, "", time.Second)
  2017. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2018. redis.Set(keyFive, "", time.Second)
  2019. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2020. redis.Set(keySix, "", time.Second)
  2021. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2022. redis.Set(keySeven, "", time.Second)
  2023. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2024. //清空key 值
  2025. redis.Set(keyOne, "", time.Second)
  2026. if updateErr != nil {
  2027. utils.ErrorLog("%v", updateErr)
  2028. }
  2029. defer redis.Close()
  2030. c.ServeSuccessJSON(map[string]interface{}{
  2031. "prescription": prescription,
  2032. })
  2033. }
  2034. } else { //修改
  2035. //if mode_id > 0 {
  2036. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2037. //}
  2038. //if template.TemplateId == 1 {
  2039. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2040. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2041. // if getPermissionErr != nil {
  2042. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2043. // return
  2044. // } else if headNursePermission == nil {
  2045. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2046. // return
  2047. // }
  2048. // }
  2049. //}
  2050. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2051. prescription.Modifier = adminUserInfo.AdminUser.Id
  2052. if appRole.UserType == 2 || appRole.UserType == 1 {
  2053. prescription_doctor := adminUserInfo.AdminUser.Id
  2054. prescription.PrescriptionDoctor = prescription_doctor
  2055. } else {
  2056. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2057. }
  2058. if dialysisPrescription.Creater == 0 { //体重称
  2059. prescription.Creater = adminUserInfo.AdminUser.Id
  2060. } else {
  2061. prescription.Creater = dialysisPrescription.Creater
  2062. if adminUserInfo.Org.Id == 9882 {
  2063. if appRole.UserType == 2 || appRole.UserType == 1 {
  2064. prescription_doctor := adminUserInfo.AdminUser.Id
  2065. prescription.PrescriptionDoctor = prescription_doctor
  2066. prescription.Creater = prescription_doctor
  2067. }
  2068. }
  2069. }
  2070. prescription.ID = dialysisPrescription.ID
  2071. service.UpDateDialysisPrescription(&prescription)
  2072. //记录日志
  2073. byterequest, _ := json.Marshal(prescription)
  2074. prescriptionLog := models.XtDialysisPrescriptionLog{
  2075. UserOrgId: prescription.UserOrgId,
  2076. Ctime: time.Now().Unix(),
  2077. Mtime: 0,
  2078. ErrLog: string(byterequest),
  2079. AdminUserId: adminUserInfo.AdminUser.Id,
  2080. RecordDate: prescription.RecordDate,
  2081. PatientId: prescription.PatientId,
  2082. Source: "手机端修改处方",
  2083. Status: 1,
  2084. }
  2085. service.CreatePrescriptionLog(prescriptionLog)
  2086. finish := models.XtDialysisFinish{
  2087. IsFinish: 1,
  2088. UserOrgId: adminUserInfo.Org.Id,
  2089. Status: 1,
  2090. Ctime: time.Now().Unix(),
  2091. Mtime: 0,
  2092. Module: 1,
  2093. RecordDate: recordDate.Unix(),
  2094. Sourse: 1,
  2095. PatientId: id,
  2096. }
  2097. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2098. if dialysisFinish.ID == 0 {
  2099. service.CreateDialysisFinish(finish)
  2100. }
  2101. //修改处方
  2102. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2103. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2104. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2105. if advicePrescription.ID > 0 {
  2106. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2107. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2108. redis := service.RedisClient()
  2109. defer redis.Close()
  2110. //清空key 值
  2111. redis.Set(key, "", time.Second)
  2112. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2113. redis.Set(keyOne, "", time.Second)
  2114. }
  2115. }
  2116. //获取key,清空redis
  2117. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2118. redis := service.RedisClient()
  2119. //清空key 值
  2120. redis.Set(key, "", time.Second)
  2121. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2122. //清空key 值
  2123. redis.Set(keyOne, "", time.Second)
  2124. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2125. redis.Set(keySix, "", time.Second)
  2126. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2127. redis.Set(keySeven, "", time.Second)
  2128. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2129. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2130. //清空key 值
  2131. redis.Set(keyTwoOne, "", time.Second)
  2132. defer redis.Close()
  2133. if updateErr != nil {
  2134. utils.ErrorLog("%v", updateErr)
  2135. }
  2136. c.ServeSuccessJSON(map[string]interface{}{
  2137. "prescription": prescription,
  2138. })
  2139. }
  2140. }
  2141. func (c *DialysisAPIController) Finish() {
  2142. id, _ := c.GetInt64("patient", 0)
  2143. recordDateStr := c.GetString("record_date")
  2144. nurseID, _ := c.GetInt64("nurse")
  2145. end_time := c.GetString("end_time")
  2146. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2147. internal_fistula := c.GetString("blood_access_internal_fistula")
  2148. catheter := c.GetString("catheter")
  2149. cruor := c.GetString("cruor")
  2150. mission := c.GetString("mission")
  2151. condenser := c.GetString("condenser")
  2152. if id <= 0 || nurseID <= 0 {
  2153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2154. return
  2155. }
  2156. adminUserInfo := c.GetMobileAdminUserInfo()
  2157. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2158. if patient.ID == 0 {
  2159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2160. return
  2161. }
  2162. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2163. if getNurseErr != nil {
  2164. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2166. return
  2167. } else if nurse == nil {
  2168. c.ErrorLog("护士不存在")
  2169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2170. return
  2171. }
  2172. if len(recordDateStr) == 0 {
  2173. recordDateStr = time.Now().Format("2006-01-02")
  2174. }
  2175. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2176. if parseDateErr != nil {
  2177. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2179. return
  2180. }
  2181. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2182. if parseEndDateErr != nil {
  2183. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2185. return
  2186. }
  2187. // 查询信息规挡的设置天数
  2188. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2189. if infor.ID > 0 && infor.WeekDay > 0 {
  2190. var cha_time int64
  2191. timeNowStr := time.Now().Format("2006-01-02")
  2192. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2193. //今日的日期减去设置的日期
  2194. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2195. if cha_time >= recordDate.Unix() {
  2196. //查询审核是否允许
  2197. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2198. //申请状态不允许的情况 拒绝修改
  2199. if infor.ApplicationStatus != 1 {
  2200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2201. return
  2202. }
  2203. }
  2204. }
  2205. //now := time.Now()
  2206. //year, month, day := now.Date()
  2207. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2208. //todayTimeStamp := today_time.Unix()
  2209. // 获取当天的第一条透析纪录
  2210. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2211. if getMonitorRecordsErr != nil {
  2212. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2214. return
  2215. }
  2216. // 获取当前的最后一条透析纪录
  2217. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2218. if getMonitorRecordsErr != nil {
  2219. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2221. return
  2222. }
  2223. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2224. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2225. if getAADErr != nil {
  2226. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2228. return
  2229. }
  2230. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2231. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2232. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2233. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2234. if assessmentAfterDislysis != nil {
  2235. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2236. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2237. } else {
  2238. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2239. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2240. tempassessmentAfterDislysis.Status = 1
  2241. tempassessmentAfterDislysis.PatientId = id
  2242. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2243. }
  2244. //长沙南雅
  2245. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2246. //获取最后一条透析处方数据
  2247. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2248. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2249. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2250. }
  2251. if dialysisOrder.Stage == 1 {
  2252. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2253. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2254. fmt.Println(value)
  2255. a, b := math.Modf(value)
  2256. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2257. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2258. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2259. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2260. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2261. }
  2262. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2263. //var num1 int64
  2264. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2265. //fmt.Println(num1)
  2266. //sub := float64(num1 / 3600)
  2267. //fmt.Println(sub)
  2268. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2269. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2270. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2271. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2272. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2273. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2274. if adminUserInfo.Org.Id != 10375 {
  2275. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2276. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2277. }
  2278. if adminUserInfo.Org.Id != 10445 {
  2279. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2280. }
  2281. //北方营口医院
  2282. if adminUserInfo.Org.Id == 10445 {
  2283. //获取最后一条透析处方数据
  2284. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2285. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2286. } else {
  2287. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2288. }
  2289. //新化博翔
  2290. if adminUserInfo.Org.Id == 10447 {
  2291. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2292. }
  2293. //阳春
  2294. if adminUserInfo.Org.Id == 10485 {
  2295. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2296. }
  2297. if adminUserInfo.Org.Id == 10551 {
  2298. //获取最后一条透析处方数据
  2299. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2300. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2301. }
  2302. if adminUserInfo.Org.Id == 10580 {
  2303. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2304. }
  2305. if adminUserInfo.Org.Id == 10612 {
  2306. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2307. }
  2308. //孝康
  2309. if adminUserInfo.Org.Id == 10693 {
  2310. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2311. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2312. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2313. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2314. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2315. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2316. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2317. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2318. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2319. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2320. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2321. }
  2322. if adminUserInfo.Org.Id == 10697 {
  2323. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2324. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2325. lastWeightAfter.LastAfterWeight = floatAfeter
  2326. }
  2327. }
  2328. 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 {
  2329. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2330. if evaluation.SystolicBloodPressure == 0 {
  2331. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2332. if adminUserInfo.Org.Id == 10693 {
  2333. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2334. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2335. }
  2336. pre := models.PredialysisEvaluation{
  2337. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2338. }
  2339. fmt.Println("prew", pre)
  2340. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2341. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2342. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2343. redis := service.RedisClient()
  2344. redis.Set(key, "", time.Second)
  2345. redis.Set(keyOne, "", time.Second)
  2346. defer redis.Close()
  2347. fmt.Println(getNurseErr)
  2348. }
  2349. if evaluation.DiastolicBloodPressure == 0 {
  2350. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2351. if adminUserInfo.Org.Id == 10693 {
  2352. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2353. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2354. }
  2355. pres := models.PredialysisEvaluation{
  2356. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2357. }
  2358. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2359. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2360. redis := service.RedisClient()
  2361. redis.Set(key, "", time.Second)
  2362. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2363. redis.Set(keyOne, "", time.Second)
  2364. defer redis.Close()
  2365. fmt.Println(getNurseErr)
  2366. }
  2367. if evaluation.PulseFrequency == 0 {
  2368. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2369. if adminUserInfo.Org.Id == 10693 {
  2370. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2371. evaluation.PulseFrequency = pulseFrequency
  2372. }
  2373. press := models.PredialysisEvaluation{
  2374. PulseFrequency: evaluation.PulseFrequency,
  2375. }
  2376. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2377. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2378. redis := service.RedisClient()
  2379. redis.Set(key, "", time.Second)
  2380. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2381. redis.Set(keyOne, "", time.Second)
  2382. defer redis.Close()
  2383. fmt.Println(getNurseErr)
  2384. }
  2385. if evaluation.Temperature == 0 {
  2386. evaluation.Temperature = fmonitorRecords.Temperature
  2387. press := models.PredialysisEvaluation{
  2388. Temperature: evaluation.Temperature,
  2389. }
  2390. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2391. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2392. redis := service.RedisClient()
  2393. redis.Set(key, "", time.Second)
  2394. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2395. redis.Set(keyOne, "", time.Second)
  2396. defer redis.Close()
  2397. fmt.Println(getNurseErr)
  2398. }
  2399. }
  2400. if adminUserInfo.Org.Id == 9583 {
  2401. //获取透析处方的最后一条数据
  2402. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2403. if diaerr != nil {
  2404. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2406. return
  2407. }
  2408. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2409. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2410. }
  2411. }
  2412. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2413. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2414. }
  2415. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2416. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2417. }
  2418. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2419. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2420. }
  2421. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2422. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2423. }
  2424. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2425. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2426. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2427. }
  2428. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2429. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2430. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2431. }
  2432. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2433. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2434. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2435. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2436. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2437. }
  2438. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2439. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2440. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2441. }
  2442. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2443. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2444. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2445. }
  2446. if lastAssessmentAfterDislysis != nil {
  2447. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2448. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2449. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2450. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2451. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2452. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2453. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2454. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2455. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2456. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2457. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2458. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2459. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2460. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2461. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2462. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2463. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2464. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2465. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2466. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2467. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2468. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2469. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2470. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2471. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2472. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2473. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2474. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2475. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2476. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2477. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2478. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2479. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2480. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2481. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2482. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2483. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2484. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2485. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2486. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2487. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2488. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2489. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2490. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2491. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2492. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2493. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2494. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2495. if tempassessmentAfterDislysis.PatientId == 18695 {
  2496. tempassessmentAfterDislysis.ActualDisplacement = 0
  2497. }
  2498. if adminUserInfo.Org.Id != 10375 {
  2499. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2500. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2501. }
  2502. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2503. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2504. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2505. }
  2506. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2507. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2508. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2509. }
  2510. }
  2511. finish := models.XtDialysisFinish{
  2512. IsFinish: 1,
  2513. UserOrgId: adminUserInfo.Org.Id,
  2514. Status: 1,
  2515. Ctime: time.Now().Unix(),
  2516. Mtime: 0,
  2517. Module: 9,
  2518. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2519. Sourse: 1,
  2520. PatientId: tempassessmentAfterDislysis.PatientId,
  2521. }
  2522. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2523. if dialysisFinish.ID == 0 {
  2524. service.CreateDialysisFinish(finish)
  2525. }
  2526. //孝康
  2527. if adminUserInfo.Org.Id == 10693 {
  2528. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2529. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2530. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2531. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2532. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2533. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2534. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2535. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2536. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2537. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2538. }
  2539. if adminUserInfo.Org.Id == 10697 {
  2540. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2541. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2542. lastWeightAfter.LastAfterWeight = floatAfeter
  2543. }
  2544. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2545. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2546. redis := service.RedisClient()
  2547. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2548. redis.Set(keyOne, "", time.Second)
  2549. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2550. redis.Set(keyTwo, "", time.Second)
  2551. defer redis.Close()
  2552. //清空key 值
  2553. redis.Set(key, "", time.Second)
  2554. if err != nil {
  2555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2556. return
  2557. }
  2558. if dialysisOrder == nil {
  2559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2560. return
  2561. }
  2562. if dialysisOrder.Stage == 2 {
  2563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2564. return
  2565. }
  2566. if dialysisOrder.Stage == 1 {
  2567. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2568. finish := models.XtDialysisFinish{
  2569. IsFinish: 1,
  2570. UserOrgId: adminUserInfo.Org.Id,
  2571. Status: 1,
  2572. Ctime: time.Now().Unix(),
  2573. Mtime: 0,
  2574. Module: 8,
  2575. RecordDate: recordDate.Unix(),
  2576. Sourse: 1,
  2577. PatientId: id,
  2578. }
  2579. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2580. if dialysisFinish.ID == 0 {
  2581. service.CreateDialysisFinish(finish)
  2582. }
  2583. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2584. redis := service.RedisClient()
  2585. defer redis.Close()
  2586. //清空key 值
  2587. redis.Set(key, "", time.Second)
  2588. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2589. redis.Set(keyOne, "", time.Second)
  2590. //结束时候透析次数加1
  2591. service.UpdateSolutionByPatientId(id)
  2592. //下机完自动消毒,针对长沙南雅
  2593. if dialysisOrder.Stage == 1 {
  2594. 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 {
  2595. //根据床位号获取设备型号
  2596. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2597. //查询使用消毒最后一条消毒记录
  2598. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2599. fmt.Println("err", err)
  2600. if err == gorm.ErrRecordNotFound {
  2601. //查找排班
  2602. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2603. //查询改设备是否有消毒计划
  2604. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2605. //根据床位号获取设备id
  2606. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2607. //查询病人信息
  2608. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2609. var con = ""
  2610. if patients.IsInfectious == 0 {
  2611. con = ""
  2612. }
  2613. if patients.IsInfectious == 1 {
  2614. con = "无"
  2615. }
  2616. if patients.IsInfectious == 2 {
  2617. con = "有"
  2618. }
  2619. if errcode == nil {
  2620. var end_time int64
  2621. end_time = endDate.Unix() + plan.DisinfecTime*60
  2622. //新增消毒
  2623. information := models.DeviceInformation{
  2624. Date: dialysisOrder.DialysisDate,
  2625. Zone: dialysisOrder.ZoneId,
  2626. Class: dialysisOrder.SchedualType,
  2627. BedNumber: dialysisOrder.BedID,
  2628. PatientId: dialysisOrder.PatientId,
  2629. DialysisMode: scheduleByPatient.ModeId,
  2630. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2631. Disinfection: 1,
  2632. DialysisConcentration: 1,
  2633. DisinfectionStatus: 1,
  2634. Move: 1,
  2635. UserOrgId: dialysisOrder.UserOrgId,
  2636. DisinfectType: plan.Way,
  2637. DisinfectantType: plan.MachineDisinfectant,
  2638. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2639. Disinfectant: plan.Disinfectant,
  2640. Ctime: time.Now().Unix(),
  2641. Status: 1,
  2642. SignName: nurseID,
  2643. EquimentId: addmacher.ID,
  2644. DisinfectionResidue: 2,
  2645. Bed: addmacher.BedNumber,
  2646. StartTime: dialysisOrder.StartTime,
  2647. EndTime: dialysisOrder.EndTime,
  2648. Contagion: con,
  2649. WeightLoss: 0,
  2650. Hyperfiltratio: 0,
  2651. DialysisHour: "",
  2652. MachineRun: 1,
  2653. DisinfecStartime: endDate.Unix(),
  2654. DisinfecEndtime: end_time,
  2655. }
  2656. err := service.CreateInformationTwo(&information)
  2657. fmt.Println("报错", err)
  2658. }
  2659. }
  2660. }
  2661. }
  2662. dialysisOrder.Stage = 2
  2663. dialysisOrder.FinishNurse = nurseID
  2664. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2665. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2666. dialysisOrder.EndTime = endDate.Unix()
  2667. // 长沙南雅需求
  2668. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2669. //获取最后1条监测的数据
  2670. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2671. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2672. var accumulatedBloodVolume float64
  2673. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2674. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2675. fmt.Println(err)
  2676. // 查询未执行的医嘱
  2677. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2678. for _, item := range doctorAdvice {
  2679. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2680. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2681. redis := service.RedisClient()
  2682. //清空key 值
  2683. redis.Set(key, "", time.Second)
  2684. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2685. redis.Set(keyTwo, "", time.Second)
  2686. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2687. redis.Set(keyThree, "", time.Second)
  2688. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2689. theTime := toTime.Format("2006-01-02")
  2690. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2691. redis.Set(keyFour, "", time.Second)
  2692. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2693. redis.Set(keyFive, "", time.Second)
  2694. defer redis.Close()
  2695. }
  2696. }
  2697. go func() {
  2698. ssoDomain := beego.AppConfig.String("call_domain")
  2699. api := ssoDomain + "/index/downpatient"
  2700. values := make(url.Values)
  2701. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2702. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2703. values.Set("patient_id", strconv.FormatInt(id, 10))
  2704. http.PostForm(api, values)
  2705. }()
  2706. if err == nil {
  2707. c.ServeSuccessJSON(map[string]interface{}{
  2708. "dialysisOrder": dialysisOrder,
  2709. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2710. })
  2711. } else {
  2712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2713. }
  2714. }
  2715. }
  2716. func (c *DialysisAPIController) GetAllZone() {
  2717. adminUserInfo := c.GetMobileAdminUserInfo()
  2718. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2719. if err == nil {
  2720. c.ServeSuccessJSON(map[string]interface{}{
  2721. "zone": zone,
  2722. })
  2723. }
  2724. }
  2725. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2726. adminUserInfo := c.GetMobileAdminUserInfo()
  2727. page, _ := c.GetInt64("page", 1)
  2728. limit, _ := c.GetInt64("limit", 10)
  2729. schedulType, _ := c.GetInt64("schedul_type", 0)
  2730. startTime, _ := c.GetInt64("schedul_time", 0)
  2731. partitionType, _ := c.GetInt64("partition_type", 0)
  2732. keywords := c.GetString("keywords")
  2733. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2734. if err == nil {
  2735. c.ServeSuccessJSON(map[string]interface{}{
  2736. "schedule": dialysisSchedule,
  2737. })
  2738. }
  2739. return
  2740. }
  2741. // /m/api/dialysis/start [post]
  2742. // @param patient_id:int
  2743. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2744. // @param nurse:int 上机护士
  2745. // @param bed:int 床位号
  2746. func (this *DialysisAPIController) StartDialysis() {
  2747. patientID, _ := this.GetInt64("patient_id")
  2748. recordDateStr := this.GetString("record_date")
  2749. nurseID, _ := this.GetInt64("start_nurse")
  2750. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2751. blood_drawing, _ := this.GetInt64("blood_drawing")
  2752. schedual_type, _ := this.GetInt64("schedual_type")
  2753. bedID, _ := this.GetInt64("bed")
  2754. start_time := this.GetString("start_time")
  2755. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2756. change_nurse, _ := this.GetInt64("change_nurse")
  2757. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2758. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2759. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2760. puncture_needle := this.GetString("puncture_needle")
  2761. puncture_way := this.GetString("puncture_way")
  2762. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2763. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2764. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2765. zone_id, _ := this.GetInt64("zone_id")
  2766. elecsign := this.GetString("url")
  2767. nuclein_date_str := this.GetString("nuclein_date_str")
  2768. schedule_remark := this.GetString("schedule_remark")
  2769. order_remark := this.GetString("order_remark")
  2770. catheter_operation := this.GetString("catheter_operation")
  2771. blood_flow_volume := this.GetString("blood_flow_volume")
  2772. dialysis_strainer := this.GetString("dialysis_strainer")
  2773. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2774. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2775. return
  2776. }
  2777. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2778. if parseStartDateErr != nil {
  2779. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2780. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2781. return
  2782. }
  2783. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2784. if parseErr != nil {
  2785. this.ErrorLog("时间解析失败:%v", parseErr)
  2786. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2787. return
  2788. }
  2789. adminUserInfo := this.GetMobileAdminUserInfo()
  2790. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2791. if getPatientErr != nil {
  2792. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2793. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2794. return
  2795. } else if patient == nil {
  2796. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2797. return
  2798. }
  2799. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2800. if getNurseErr != nil {
  2801. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2802. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2803. return
  2804. } else if nurse == nil {
  2805. this.ErrorLog("护士不存在")
  2806. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2807. return
  2808. }
  2809. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2810. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2811. if getDeviceNumberErr != nil {
  2812. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2813. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2814. return
  2815. } else if deviceNumber == nil {
  2816. this.ErrorLog("床位号不存在")
  2817. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2818. return
  2819. }
  2820. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2821. if getRecordErr != nil {
  2822. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2823. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2824. return
  2825. } else if dialysisRecord != nil {
  2826. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2827. return
  2828. }
  2829. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2830. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2831. timeLayout := "2006-01-02 15:04:05"
  2832. loc, _ := time.LoadLocation("Local")
  2833. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2834. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2835. schedulestartTime := theStartTime.Unix()
  2836. scheduleendTime := theEndTime.Unix()
  2837. var theNucleinDate int64
  2838. timeLayoutOne := "2006-01-02"
  2839. if len(nuclein_date_str) > 0 {
  2840. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2841. if err != nil {
  2842. utils.ErrorLog(err.Error())
  2843. }
  2844. theNucleinDate = theTime.Unix()
  2845. }
  2846. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2847. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2848. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2849. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2850. //查询该床位是否有人用了
  2851. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2852. if err == gorm.ErrRecordNotFound { //空床位
  2853. // 修改了床位逻辑
  2854. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2855. if daySchedule.ID > 0 {
  2856. daySchedule.PartitionId = deviceNumber.ZoneID
  2857. daySchedule.BedId = bedID
  2858. daySchedule.ScheduleType = schedual_type
  2859. daySchedule.UpdatedTime = time.Now().Unix()
  2860. xtSchedule := models.Schedule{
  2861. PartitionId: deviceNumber.ZoneID,
  2862. BedId: bedID,
  2863. ScheduleType: schedual_type,
  2864. UpdatedTime: time.Now().Unix(),
  2865. }
  2866. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2867. if err != nil {
  2868. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2869. return
  2870. }
  2871. }
  2872. } else if err == nil {
  2873. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2874. if order.ID > 0 { //该机位被其他人占用了
  2875. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2876. return
  2877. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2878. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2879. if daySchedule.ID > 0 {
  2880. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2881. if err != nil {
  2882. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2883. return
  2884. }
  2885. }
  2886. }
  2887. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2888. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2889. return
  2890. }
  2891. //else if order.ID == 0 { //该床位没被占用
  2892. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2893. // if daySchedule.ID > 0 {
  2894. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2895. // //daySchedule.BedId = bedID
  2896. // //daySchedule.ScheduleType = schedual_type
  2897. // //daySchedule.UpdatedTime = time.Now().Unix()
  2898. // //err := service.UpdateSchedule(&daySchedule)
  2899. // xtSchedule := models.Schedule{
  2900. // PartitionId: deviceNumber.ZoneID,
  2901. // BedId: bedID,
  2902. // ScheduleType: schedual_type,
  2903. // UpdatedTime: time.Now().Unix(),
  2904. // }
  2905. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2906. // if err != nil {
  2907. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2908. // return
  2909. // }
  2910. // }
  2911. //}
  2912. //}
  2913. } else if err != nil {
  2914. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2915. return
  2916. }
  2917. // 查询信息规挡的设置天数
  2918. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2919. if infor.ID > 0 && infor.WeekDay > 0 {
  2920. var cha_time int64
  2921. timeNowStr := time.Now().Format("2006-01-02")
  2922. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2923. //今日的日期减去设置的日期
  2924. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2925. if cha_time >= recordDate.Unix() {
  2926. //查询审核是否允许
  2927. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  2928. //申请状态不允许的情况 拒绝修改
  2929. if infor.ApplicationStatus != 1 {
  2930. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2931. return
  2932. }
  2933. }
  2934. }
  2935. dialysisRecord = &models.DialysisOrder{
  2936. DialysisDate: recordDate.Unix(),
  2937. UserOrgId: adminUserInfo.Org.Id,
  2938. PatientId: patientID,
  2939. Stage: 1,
  2940. BedID: bedID,
  2941. StartNurse: nurseID,
  2942. Status: 1,
  2943. StartTime: startDate.Unix(),
  2944. CreatedTime: time.Now().Unix(),
  2945. UpdatedTime: time.Now().Unix(),
  2946. PunctureNurse: puncture_nurse,
  2947. Creator: adminUserInfo.AdminUser.Id,
  2948. Modifier: adminUserInfo.AdminUser.Id,
  2949. SchedualType: schedual_type,
  2950. WashpipeNurse: washpipe_nurse,
  2951. ChangeNurse: change_nurse,
  2952. DifficultPunctureNurse: difficult_puncture_nurse,
  2953. NewFistulaNurse: new_fistula_nurse,
  2954. ZoneId: zone_id,
  2955. QualityNurseId: quality_nurse_id,
  2956. PunctureNeedle: puncture_needle,
  2957. PunctureWay: puncture_way,
  2958. DialysisIrrigation: dialysis_irrigation,
  2959. DialysisDialyszers: dialysis_dialyszers,
  2960. BloodAccessId: blood_access_id,
  2961. Url: elecsign,
  2962. NucleinDate: theNucleinDate,
  2963. ScheduleRemark: schedule_remark,
  2964. OrderRemark: order_remark,
  2965. CatheterOperation: catheter_operation,
  2966. BloodFlowVolume: blood_flow_volume,
  2967. BloodDrawing: blood_drawing,
  2968. DialysisStrainer: dialysis_strainer,
  2969. }
  2970. //查询该床位是否有人用了
  2971. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2972. if errorscode == gorm.ErrRecordNotFound {
  2973. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2974. finish := models.XtDialysisFinish{
  2975. IsFinish: 1,
  2976. UserOrgId: adminUserInfo.Org.Id,
  2977. Status: 1,
  2978. Ctime: time.Now().Unix(),
  2979. Mtime: 0,
  2980. Module: 6,
  2981. RecordDate: schedulestartTime,
  2982. Sourse: 1,
  2983. PatientId: patientID,
  2984. }
  2985. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  2986. if dialysisFinish.ID == 0 {
  2987. service.CreateDialysisFinish(finish)
  2988. }
  2989. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2990. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  2991. //统计该患者总次数
  2992. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  2993. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2994. }
  2995. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  2996. //统计该患者总次数
  2997. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  2998. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2999. }
  3000. redis := service.RedisClient()
  3001. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3002. redis.Set(key, "", time.Second)
  3003. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3004. //清空key 值
  3005. redis.Set(keyOne, "", time.Second)
  3006. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3007. //清空key 值
  3008. redis.Set(keyTwo, "", time.Second)
  3009. if createErr != nil {
  3010. this.ErrorLog("上机失败:%v", createErr)
  3011. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3012. return
  3013. }
  3014. }
  3015. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3016. var tempdispose string
  3017. // 只针对中能建
  3018. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3019. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3020. }
  3021. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3022. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3023. }
  3024. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3025. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3026. //}
  3027. var ultrafiltration_rate float64
  3028. var ultrafiltration_rate_one string
  3029. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3030. //后期预增脱水量
  3031. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3032. if prescription.ID > 0 {
  3033. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3034. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3035. 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
  3036. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3037. }
  3038. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3039. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3040. }
  3041. //针对医师汇
  3042. if adminUserInfo.Org.Id == 10121 {
  3043. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3044. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3045. }
  3046. //针对通道
  3047. if adminUserInfo.Org.Id == 10234 {
  3048. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3049. }
  3050. //针对监利大垸医院
  3051. if template.TemplateId == 41 {
  3052. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3053. }
  3054. //针对肇庆三鹤血液透析中心
  3055. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3056. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3057. }
  3058. if adminUserInfo.Org.Id == 10469 {
  3059. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3060. }
  3061. if adminUserInfo.Org.Id == 10667 {
  3062. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3063. }
  3064. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3065. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3066. }
  3067. // 只针对方济医院
  3068. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3069. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3070. ultrafiltration_rate = value
  3071. }
  3072. //针对
  3073. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3074. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3075. ultrafiltration_rate = ultrafiltration_rate / 1000
  3076. }
  3077. if adminUserInfo.Org.Id == 10551 {
  3078. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3079. ultrafiltration_rate = ultrafiltration_rate / 1000
  3080. }
  3081. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3082. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3083. ultrafiltration_rate = ultrafiltration_rate / 1000
  3084. }
  3085. if adminUserInfo.Org.Id == 10580 {
  3086. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3087. ultrafiltration_rate = ultrafiltration_rate / 1000
  3088. }
  3089. if adminUserInfo.Org.Id == 10629 {
  3090. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3091. ultrafiltration_rate = ultrafiltration_rate / 1000
  3092. }
  3093. if adminUserInfo.Org.Id == 10644 {
  3094. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3095. ultrafiltration_rate = ultrafiltration_rate / 1000
  3096. }
  3097. if adminUserInfo.Org.Id == 10667 {
  3098. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3099. ultrafiltration_rate = ultrafiltration_rate / 1000
  3100. }
  3101. //孝昌
  3102. if adminUserInfo.Org.Id == 10693 {
  3103. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3104. ultrafiltration_rate = ultrafiltration_rate
  3105. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3106. }
  3107. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3108. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3109. ultrafiltration_rate = ultrafiltration_rate / 1000
  3110. }
  3111. if adminUserInfo.Org.Id == 10702 {
  3112. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3113. ultrafiltration_rate = ultrafiltration_rate / 1000
  3114. }
  3115. }
  3116. }
  3117. record := models.MonitoringRecord{
  3118. UserOrgId: adminUserInfo.Org.Id,
  3119. PatientId: patientID,
  3120. DialysisOrderId: dialysisRecord.ID,
  3121. MonitoringDate: schedulestartTime,
  3122. OperateTime: startDate.Unix(),
  3123. // MonitoringTime: recordTime,
  3124. MonitoringNurse: nurseID,
  3125. Dispose: tempdispose,
  3126. UltrafiltrationRate: ultrafiltration_rate,
  3127. UltrafiltrationVolume: 0,
  3128. Status: 1,
  3129. CreatedTime: time.Now().Unix(),
  3130. UpdatedTime: time.Now().Unix(),
  3131. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3132. }
  3133. //只针对广慈医院
  3134. 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 {
  3135. // 查询病人是否有透前评估数据
  3136. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3137. //如果有数据就插入
  3138. if errcode == nil {
  3139. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3140. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3141. record.BreathingRate = befor.BreathingRate
  3142. record.PulseFrequency = befor.PulseFrequency
  3143. record.Temperature = befor.Temperature
  3144. }
  3145. }
  3146. //孝昌
  3147. if adminUserInfo.Org.Id == 10693 {
  3148. // 查询病人是否有透前评估数据
  3149. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3150. //如果有数据就插入
  3151. if errcode == nil {
  3152. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3153. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3154. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3155. record.BreathingRate = befor.BreathingRate
  3156. }
  3157. }
  3158. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3159. if newdialysisRecord.ID > 0 {
  3160. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3161. record.Temperature = 36.5
  3162. record.ArterialPressure = -100
  3163. record.DialysateTemperature = 36.5
  3164. record.Conductivity = 14
  3165. record.BreathingRate = "20"
  3166. record.VenousPressure = 80
  3167. record.TransmembranePressure = 60
  3168. record.Dispose = catheter_operation
  3169. }
  3170. //针对新化博翔
  3171. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3172. record.BloodOxygenSaturation = "99"
  3173. record.Conductivity = 14
  3174. record.DialysateTemperature = 36.5
  3175. record.BreathingRate = "20"
  3176. }
  3177. //针对兰溪人民医院的需求
  3178. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3179. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3180. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3181. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3182. record.Temperature = befor.Temperature
  3183. record.PulseFrequency = befor.PulseFrequency
  3184. record.BreathingRate = befor.BreathingRate
  3185. }
  3186. //针对乐山友谊医院的需求
  3187. if adminUserInfo.Org.Id == 10677 {
  3188. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3189. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3190. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3191. record.Temperature = befor.Temperature
  3192. record.PulseFrequency = befor.PulseFrequency
  3193. record.BreathingRate = befor.BreathingRate
  3194. }
  3195. //新化博翔
  3196. if adminUserInfo.Org.Id == 10447 {
  3197. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3198. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3199. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3200. record.BreathingRate = befor.BreathingRate
  3201. }
  3202. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3203. record.PulseFrequency = 80
  3204. record.Temperature = 36.5
  3205. }
  3206. //诊断灵山圣康
  3207. if adminUserInfo.Org.Id == 10375 {
  3208. record.Conductivity = 13.8
  3209. record.DialysateTemperature = 37
  3210. record.DialysateFlow = 500
  3211. record.BloodFlowVolume = 200
  3212. record.BreathingRate = "18"
  3213. record.SodiumConcentration = 140
  3214. }
  3215. //江成肾病医院
  3216. if adminUserInfo.Org.Id == 10517 {
  3217. record.SodiumConcentration = 138
  3218. record.DialysateTemperature = 36.5
  3219. }
  3220. if adminUserInfo.Org.Id != 10683 {
  3221. err = service.CreateMonitor(&record)
  3222. }
  3223. //记录日志
  3224. byterequest, _ := json.Marshal(record)
  3225. monitorRecordLog := models.XtMonitorRecordLog{
  3226. RecordDate: record.MonitoringDate,
  3227. PatientId: record.PatientId,
  3228. Module: 1,
  3229. AdminUserId: adminUserInfo.AdminUser.Id,
  3230. Ctime: time.Now().Unix(),
  3231. Mtime: 0,
  3232. Status: 1,
  3233. UserOrgId: record.UserOrgId,
  3234. ErrLog: string(byterequest),
  3235. Source: "执行上机时新增监测",
  3236. }
  3237. service.CreateMonitorRecordLog(monitorRecordLog)
  3238. finish := models.XtDialysisFinish{
  3239. IsFinish: 1,
  3240. UserOrgId: adminUserInfo.Org.Id,
  3241. Status: 1,
  3242. Ctime: time.Now().Unix(),
  3243. Mtime: 0,
  3244. Module: 7,
  3245. RecordDate: schedulestartTime,
  3246. Sourse: 1,
  3247. PatientId: patientID,
  3248. }
  3249. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3250. if dialysisFinish.ID == 0 {
  3251. service.CreateDialysisFinish(finish)
  3252. }
  3253. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3254. redis := service.RedisClient()
  3255. //清空key 值
  3256. redis.Set(key, "", time.Second)
  3257. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3258. redis.Set(keyOne, "", time.Second)
  3259. defer redis.Close()
  3260. if err != nil {
  3261. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3262. return
  3263. }
  3264. }
  3265. go func() {
  3266. ssoDomain := beego.AppConfig.String("call_domain")
  3267. api := ssoDomain + "/index/uppatient"
  3268. values := make(url.Values)
  3269. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3270. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3271. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3272. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3273. http.PostForm(api, values)
  3274. }()
  3275. this.ServeSuccessJSON(map[string]interface{}{
  3276. "dialysis_order": newdialysisRecord,
  3277. "monitor": record,
  3278. })
  3279. return
  3280. }
  3281. func (c *DialysisAPIController) PostSolution() {
  3282. id, _ := c.GetInt64("patient", 0)
  3283. recordDateStr := c.GetString("record_date")
  3284. if id <= 0 {
  3285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3286. return
  3287. }
  3288. adminUserInfo := c.GetMobileAdminUserInfo()
  3289. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3290. if patient.ID == 0 {
  3291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3292. return
  3293. }
  3294. if len(recordDateStr) == 0 {
  3295. recordDateStr = time.Now().Format("2006-01-02")
  3296. }
  3297. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3298. if parseDateErr != nil {
  3299. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3301. return
  3302. }
  3303. mode_id, _ := c.GetInt64("mode_id", 0)
  3304. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3305. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3306. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3307. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3308. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3309. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3310. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3311. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3312. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3313. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3314. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3315. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3316. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3317. kalium, _ := c.GetFloat("kalium", 0)
  3318. sodium, _ := c.GetFloat("sodium", 0)
  3319. calcium, _ := c.GetFloat("calcium", 0)
  3320. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3321. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3322. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3323. glucose, _ := c.GetFloat("glucose", 0)
  3324. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3325. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3326. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3327. conductivity, _ := c.GetFloat("conductivity", 0)
  3328. remark := c.GetString("remark")
  3329. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3330. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3331. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3332. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3333. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3334. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3335. special_medicine_other := c.GetString("special_medicine_other")
  3336. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3337. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3338. blood_access, _ := c.GetInt64("blood_access", 0)
  3339. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3340. body_fluid_other := c.GetString("body_fluid_other")
  3341. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3342. niprocart, _ := c.GetInt64("niprocart", 0)
  3343. jms, _ := c.GetInt64("jms", 0)
  3344. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3345. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3346. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3347. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3348. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3349. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3350. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3351. injector, _ := c.GetInt64("injector", 0)
  3352. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3353. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3354. safe_package, _ := c.GetInt64("package", 0)
  3355. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3356. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3357. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3358. blood := c.GetString("blood")
  3359. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3360. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3361. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3362. displace_speed := c.GetString("displace_speed")
  3363. illness, _ := c.GetInt64("illness")
  3364. amylaceum := c.GetString("amylaceum")
  3365. single_time := c.GetString("single_time")
  3366. single_water := c.GetString("single_water")
  3367. replacement_flow := c.GetString("replacement_flow")
  3368. plasma_separator := c.GetString("plasma_separator")
  3369. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3370. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3371. oxygen_flow := c.GetString("oxygen_flow")
  3372. oxygen_time := c.GetString("oxygen_time")
  3373. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3374. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3375. puncture_needle := c.GetString("puncture_needle")
  3376. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3377. epo := c.GetString("epo")
  3378. epo_count, _ := c.GetFloat("epo_count", 0)
  3379. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3380. pre_impulse := c.GetString("pre_impulse")
  3381. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3382. admin_user_id, _ := c.GetInt64("admin_user_id")
  3383. is_water := c.GetString("is_water")
  3384. add_amount, _ := c.GetFloat("add_amount")
  3385. reduce_amount, _ := c.GetFloat("reduce_amount")
  3386. prescribing_number, _ := c.GetFloat("prescribing_number")
  3387. treatment_remark := c.GetString("treatment_remark")
  3388. prescription_sodium := c.GetString("prescription_sodium")
  3389. start_sodium := c.GetString("start_sodium")
  3390. sodium_curve := c.GetString("sodium_curve")
  3391. var is_war int64
  3392. if is_water == "是" {
  3393. is_war = 1
  3394. }
  3395. if is_water == "否" {
  3396. is_war = 2
  3397. }
  3398. if is_water == "请选择" {
  3399. is_war = 0
  3400. }
  3401. drhy_water := c.GetString("drhy_water")
  3402. dry_water_hour := c.GetString("dry_water_hour")
  3403. water_machine := c.GetString("water_machine")
  3404. dialysis_remark := c.GetString("dialysis_remark")
  3405. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3406. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3407. prescription_water, _ := c.GetFloat("prescription_water")
  3408. dialysis_strainer := c.GetString("dialysis_strainer")
  3409. chaptalization := c.GetString("chaptalization")
  3410. washing_time := c.GetString("washing_time")
  3411. warsh_count := c.GetString("warsh_count")
  3412. blood_access_part_id := c.GetString("blood_access_part_id")
  3413. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3414. dialyzate := c.GetString("dialyzate")
  3415. if mode_id > 0 {
  3416. var str string
  3417. //查找该机构用的是什么透析器
  3418. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3419. if filedConfig.ID > 0 {
  3420. str = dialyzerPerfusionApparatus
  3421. } else {
  3422. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3423. }
  3424. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3425. }
  3426. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3427. //
  3428. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3429. // if appRole.UserType == 3 {
  3430. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3431. // if getPermissionErr != nil {
  3432. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3433. // return
  3434. // } else if headNursePermission == nil {
  3435. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3436. // return
  3437. // }
  3438. // }
  3439. //}
  3440. // 查询信息规挡的设置天数
  3441. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3442. if infor.ID > 0 && infor.WeekDay > 0 {
  3443. var cha_time int64
  3444. timeNowStr := time.Now().Format("2006-01-02")
  3445. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3446. //今日的日期减去设置的日期
  3447. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3448. if cha_time >= recordDate.Unix() {
  3449. //查询审核是否允许
  3450. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3451. //申请状态不允许的情况 拒绝修改
  3452. if infor.ApplicationStatus != 1 {
  3453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3454. return
  3455. }
  3456. }
  3457. }
  3458. prescription := models.DialysisPrescription{
  3459. UserOrgId: adminUserInfo.Org.Id,
  3460. PatientId: id,
  3461. RecordDate: recordDate.Unix(),
  3462. ModeId: mode_id,
  3463. DialysisDuration: dialysis_duration,
  3464. Dialyzer: dialyzer,
  3465. PerfusionApparatus: perfusion_apparatus,
  3466. BloodFlowVolume: blood_flow_volume,
  3467. DewaterAmount: dewater_amount,
  3468. DisplaceLiqui: displace_liqui,
  3469. ReplacementWay: replacement_way,
  3470. Anticoagulant: anticoagulant,
  3471. AnticoagulantShouji: anticoagulant_shouji,
  3472. AnticoagulantWeichi: anticoagulant_weichi,
  3473. AnticoagulantZongliang: anticoagulant_zongliang,
  3474. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3475. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3476. Kalium: kalium,
  3477. Sodium: sodium,
  3478. Calcium: calcium,
  3479. Bicarbonate: bicarbonate,
  3480. Glucose: glucose,
  3481. // DryWeight: dry_weight,
  3482. DialysateFlow: dialysate_flow,
  3483. DialysateTemperature: dialysate_temperature,
  3484. Conductivity: conductivity,
  3485. Remark: remark,
  3486. Status: 1,
  3487. CreatedTime: time.Now().Unix(),
  3488. UpdatedTime: time.Now().Unix(),
  3489. DialysisDurationMinute: dialysisDurationMinute,
  3490. DialysisDurationHour: dialysisDurationHour,
  3491. TargetUltrafiltration: targetUltrafiltration,
  3492. DialysateFormulation: dialysateFormulation,
  3493. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3494. BodyFluid: body_fluid,
  3495. SpecialMedicine: special_medicine,
  3496. SpecialMedicineOther: special_medicine_other,
  3497. DisplaceLiquiPart: displace_liqui_part,
  3498. DisplaceLiquiValue: displace_liqui_value,
  3499. BloodAccess: blood_access,
  3500. Ultrafiltration: ultrafiltration,
  3501. BodyFluidOther: body_fluid_other,
  3502. ReplacementTotal: replacement_total,
  3503. Niprocart: niprocart,
  3504. Jms: jms,
  3505. FistulaNeedleSet: fistula_needle_set,
  3506. FistulaNeedleSet16: fistula_needle_set_16,
  3507. Hemoperfusion: hemoperfusion,
  3508. DialyserSterilised: dialyser_sterilised,
  3509. Filtryzer: filtryzer,
  3510. TargetKtv: target_ktv,
  3511. Dialyzers: dialyzers,
  3512. Injector: injector,
  3513. Bloodlines: bloodlines,
  3514. TubingHemodialysis: tubing_hemodialysis,
  3515. Package: safe_package,
  3516. ALiquid: a_liquid,
  3517. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3518. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3519. Blood: blood,
  3520. DialysisDialyszers: dialysis_dialyszers,
  3521. DialysisIrrigation: dialysis_irrigation,
  3522. AntioxidantCommodityName: antioxidant_commodity_name,
  3523. DisplaceSpeed: displace_speed,
  3524. Illness: illness,
  3525. Amylaceum: amylaceum,
  3526. SingleWater: single_water,
  3527. SingleTime: single_time,
  3528. ReplacementFlow: replacement_flow,
  3529. PlasmaSeparator: plasma_separator,
  3530. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3531. OxygenUptake: oxygen_uptake,
  3532. OxygenTime: oxygen_time,
  3533. OxygenFlow: oxygen_flow,
  3534. HemodialysisPipelines: hemodialysis_pipelines,
  3535. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3536. PunctureNeedle: puncture_needle,
  3537. PunctureNeedleCount: puncture_needle_count,
  3538. Epo: epo,
  3539. EpoCount: epo_count,
  3540. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3541. PreImpulse: impulse,
  3542. AdminUserId: admin_user_id,
  3543. IsWater: is_war,
  3544. DrhyWater: drhy_water,
  3545. DryWaterHour: dry_water_hour,
  3546. WaterMachine: water_machine,
  3547. AddAmount: add_amount,
  3548. ReduceAmount: reduce_amount,
  3549. DialysisRemark: dialysis_remark,
  3550. PrescribingNumber: prescribing_number,
  3551. PrescriptionSodium: prescription_sodium,
  3552. StartSodium: start_sodium,
  3553. SodiumCurve: sodium_curve,
  3554. TreatmentRemark: treatment_remark,
  3555. DialysisFluidFlow: dialysis_fluid_flow,
  3556. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3557. PrescriptionWater: prescription_water,
  3558. DialysisStrainer: dialysis_strainer,
  3559. Chaptalization: chaptalization,
  3560. WashingTime: washing_time,
  3561. WarshCount: warsh_count,
  3562. BloodAccessPartId: blood_access_part_id,
  3563. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3564. Dialyzate: dialyzate,
  3565. }
  3566. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3567. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3568. //
  3569. if appRole.UserType == 2 || appRole.UserType == 1 {
  3570. prescription_doctor = adminUserInfo.AdminUser.Id
  3571. prescription.PrescriptionDoctor = prescription_doctor
  3572. }
  3573. if dialysisPrescription.ID == 0 { //新增
  3574. prescription.Creater = adminUserInfo.AdminUser.Id
  3575. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3576. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3577. }
  3578. } else { //修改
  3579. if dialysisPrescription.Creater == 0 {
  3580. prescription.Creater = adminUserInfo.AdminUser.Id
  3581. } else {
  3582. prescription.Creater = dialysisPrescription.Creater
  3583. if adminUserInfo.Org.Id == 9882 {
  3584. if appRole.UserType == 2 || appRole.UserType == 1 {
  3585. prescription.Creater = adminUserInfo.AdminUser.Id
  3586. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3587. }
  3588. }
  3589. }
  3590. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3591. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3592. }
  3593. //if/**/
  3594. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3595. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3596. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3597. // if getPermissionErr != nil {
  3598. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3599. // return
  3600. // } else if headNursePermission == nil {
  3601. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3602. // return
  3603. // }
  3604. //}
  3605. //prescription.Creater = dialysisPrescription.Creater
  3606. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3607. prescription.Modifier = adminUserInfo.AdminUser.Id
  3608. prescription.ID = dialysisPrescription.ID
  3609. }
  3610. solution := models.DialysisSolution{
  3611. RegistrarsId: adminUserInfo.AdminUser.Id,
  3612. UserOrgId: adminUserInfo.Org.Id,
  3613. Doctor: prescription_doctor,
  3614. PatientId: id,
  3615. ModeId: mode_id,
  3616. DialysisDuration: dialysis_duration,
  3617. PerfusionApparatus: perfusion_apparatus,
  3618. BloodFlowVolume: blood_flow_volume,
  3619. Dewater: dewater_amount,
  3620. DisplaceLiqui: displace_liqui,
  3621. ReplacementWay: replacement_way,
  3622. Anticoagulant: anticoagulant,
  3623. AnticoagulantShouji: anticoagulant_shouji,
  3624. AnticoagulantWeichi: anticoagulant_weichi,
  3625. AnticoagulantZongliang: anticoagulant_zongliang,
  3626. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3627. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3628. Kalium: kalium,
  3629. Sodium: sodium,
  3630. Calcium: calcium,
  3631. Bicarbonate: bicarbonate,
  3632. Glucose: glucose,
  3633. // DryWeight: dry_weight,
  3634. DialysateFlow: dialysate_flow,
  3635. DialysateTemperature: dialysate_temperature,
  3636. Conductivity: conductivity,
  3637. Remark: remark,
  3638. Status: 1,
  3639. CreatedTime: time.Now().Unix(),
  3640. UpdatedTime: time.Now().Unix(),
  3641. DialysisDurationMinute: dialysisDurationMinute,
  3642. DialysisDurationHour: dialysisDurationHour,
  3643. TargetUltrafiltration: targetUltrafiltration,
  3644. DialysateFormulation: dialysateFormulation,
  3645. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3646. BodyFluid: body_fluid,
  3647. SpecialMedicine: special_medicine,
  3648. SpecialMedicineOther: special_medicine_other,
  3649. DisplaceLiquiPart: displace_liqui_part,
  3650. DisplaceLiquiValue: displace_liqui_value,
  3651. BloodAccess: blood_access,
  3652. Ultrafiltration: ultrafiltration,
  3653. BodyFluidOther: body_fluid_other,
  3654. ReplacementTotal: replacement_total,
  3655. TargetKtv: target_ktv,
  3656. DialysisDialyszers: dialysis_dialyszers,
  3657. DialysisIrrigation: dialysis_irrigation,
  3658. HemodialysisPipelines: hemodialysis_pipelines,
  3659. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3660. PunctureNeedle: puncture_needle,
  3661. PunctureNeedleCount: puncture_needle_count,
  3662. Epo: epo,
  3663. EpoCount: epo_count,
  3664. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3665. PreImpulse: impulse,
  3666. SolutionStatus: 1,
  3667. DialysisRemark: dialysis_remark,
  3668. PrescribingNumber: prescribing_number,
  3669. PrescriptionSodium: prescription_sodium,
  3670. StartSodium: start_sodium,
  3671. SodiumCurve: sodium_curve,
  3672. TreatmentRemark: treatment_remark,
  3673. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3674. DialysisFluidFlow: dialysis_fluid_flow,
  3675. PrescriptionWater: prescription_water,
  3676. DialysisStrainer: dialysis_strainer,
  3677. Chaptalization: chaptalization,
  3678. WashingTime: washing_time,
  3679. WarshCount: warsh_count,
  3680. BloodAccessPartId: blood_access_part_id,
  3681. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3682. Dialyzate: dialyzate,
  3683. }
  3684. //针对河间咸的
  3685. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3686. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3687. solution.DisplaceLiquiPart = 0
  3688. solution.DisplaceLiquiValue = 0
  3689. }
  3690. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3691. prescription.DisplaceLiquiPart = 0
  3692. prescription.DisplaceLiquiValue = 0
  3693. }
  3694. }
  3695. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3696. if solution.PrescribingNumber == 0 {
  3697. solution.PrescribingNumber = 1
  3698. }
  3699. if prescription.PrescribingNumber == 0 {
  3700. prescription.PrescribingNumber = 1
  3701. }
  3702. if solution.PrescribingNumber == 0 && id == 14682 {
  3703. solution.PrescribingNumber = 2
  3704. }
  3705. if solution.PrescribingNumber == 0 && id == 18560 {
  3706. solution.PrescribingNumber = 2
  3707. }
  3708. if prescription.PrescribingNumber == 0 && id == 14682 {
  3709. prescription.PrescribingNumber = 2
  3710. }
  3711. if prescription.PrescribingNumber == 0 && id == 18560 {
  3712. prescription.PrescribingNumber = 2
  3713. }
  3714. }
  3715. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3716. //记录日志
  3717. byterequest, _ := json.Marshal(prescription)
  3718. prescriptionLog := models.XtDialysisPrescriptionLog{
  3719. UserOrgId: prescription.UserOrgId,
  3720. Ctime: time.Now().Unix(),
  3721. Mtime: 0,
  3722. ErrLog: string(byterequest),
  3723. AdminUserId: adminUserInfo.AdminUser.Id,
  3724. RecordDate: prescription.RecordDate,
  3725. PatientId: prescription.PatientId,
  3726. Source: "手机端新增长期处方",
  3727. Status: 1,
  3728. }
  3729. service.CreatePrescriptionLog(prescriptionLog)
  3730. finish := models.XtDialysisFinish{
  3731. IsFinish: 1,
  3732. UserOrgId: adminUserInfo.Org.Id,
  3733. Status: 1,
  3734. Ctime: time.Now().Unix(),
  3735. Mtime: 0,
  3736. Module: 1,
  3737. RecordDate: recordDate.Unix(),
  3738. Sourse: 1,
  3739. PatientId: id,
  3740. }
  3741. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3742. if dialysisFinish.ID == 0 {
  3743. service.CreateDialysisFinish(finish)
  3744. }
  3745. //获取最新1条
  3746. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3747. //更新状态
  3748. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3749. //长沙南雅医院,自动生成抗凝剂的临时处方
  3750. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3751. if prescribing_number == 0 {
  3752. prescribing_number = 1
  3753. }
  3754. advice := models.DoctorAdvice{
  3755. UserOrgId: adminUserInfo.Org.Id,
  3756. PatientId: id,
  3757. GroupNo: 0,
  3758. AdviceType: 2,
  3759. RecordDate: recordDate.Unix(),
  3760. AdviceDate: recordDate.Unix(),
  3761. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3762. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3763. AdviceDesc: "",
  3764. ReminderDate: 0,
  3765. SingleDose: prescription.AnticoagulantZongliang,
  3766. SingleDoseUnit: "iu",
  3767. DrugSpec: 0,
  3768. DrugSpecUnit: "",
  3769. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3770. PrescribingNumberUnit: "支",
  3771. DeliveryWay: "静脉注射",
  3772. ExecutionFrequency: "上机前",
  3773. AdviceDoctor: 0,
  3774. Status: 1,
  3775. CreatedTime: time.Now().Unix(),
  3776. UpdatedTime: time.Now().Unix(),
  3777. IsPrescription: 1,
  3778. ExecutionState: 2,
  3779. StopState: 2,
  3780. IsSettle: 2,
  3781. }
  3782. // 查询排班信息
  3783. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3784. if schedulePatient.ID > 0 {
  3785. if schedulePatient.ScheduleType == 1 {
  3786. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3787. }
  3788. if schedulePatient.ScheduleType == 2 {
  3789. advice.StartTime = recordDate.Unix() + 9*60*60
  3790. }
  3791. }
  3792. // 抗凝剂名称
  3793. switch anticoagulant {
  3794. case 1:
  3795. advice.AdviceName = "无肝素"
  3796. break
  3797. case 2:
  3798. advice.AdviceName = "普通肝素"
  3799. break
  3800. case 3:
  3801. advice.AdviceName = "低分子肝素"
  3802. break
  3803. case 4:
  3804. advice.AdviceName = "阿加曲班"
  3805. break
  3806. case 5:
  3807. advice.AdviceName = "枸橼酸钠"
  3808. break
  3809. case 6:
  3810. advice.AdviceName = "低分子肝素钙"
  3811. break
  3812. case 7:
  3813. advice.AdviceName = "低分子肝素钠"
  3814. break
  3815. case 8:
  3816. advice.AdviceName = "依诺肝素"
  3817. break
  3818. case 9:
  3819. advice.AdviceName = "达肝素"
  3820. break
  3821. case 10:
  3822. advice.AdviceName = "体外抗凝"
  3823. break
  3824. case 11:
  3825. advice.AdviceName = "那曲肝素"
  3826. break
  3827. case 12:
  3828. advice.AdviceName = "无抗凝剂"
  3829. break
  3830. }
  3831. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3832. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3833. advice.AdviceDoctor = appRole.AdminUserId
  3834. }
  3835. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3836. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3837. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3838. advice.AdviceName = "低分子肝素钠注射液"
  3839. // 修改患者临时医嘱里的抗凝剂医嘱
  3840. advice.ID = advicePrescription.ID
  3841. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3842. } else {
  3843. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3844. advice.AdviceName = "低分子肝素钠注射液"
  3845. service.CreateDoctorAdvice(&advice)
  3846. }
  3847. }
  3848. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3849. redis := service.RedisClient()
  3850. defer redis.Close()
  3851. //清空key 值
  3852. redis.Set(key, "", time.Second)
  3853. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3854. redis.Set(keyOne, "", time.Second)
  3855. }
  3856. //获取key,清空redis
  3857. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3858. redis := service.RedisClient()
  3859. defer redis.Close()
  3860. //清空key 值
  3861. redis.Set(key, "", time.Second)
  3862. //清空长期医嘱的key
  3863. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3864. redis.Set(soulution_key, "", time.Second)
  3865. //查询最近透析准备表里是否存在 透析器 灌流器
  3866. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3867. redis.Set(keyOne, "", time.Second)
  3868. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3869. redis.Set(keyTwo, "", time.Second)
  3870. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3871. redis.Set(keyThree, "", time.Second)
  3872. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3873. redis.Set(keyFour, "", time.Second)
  3874. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3875. //
  3876. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3877. //
  3878. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3879. //if len(mation)>0{
  3880. // for _, item := range splitStr {
  3881. // for _,it := range mation{
  3882. // if(item == it.SpecificationName){
  3883. //
  3884. // //查询最近一次的透析器
  3885. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3886. //
  3887. // if errcode == gorm.ErrRecordNotFound{
  3888. // //插入数据
  3889. // prepare := models.DialysisBeforePrepare{
  3890. // UserOrgId: adminUserInfo.Org.Id,
  3891. // PatientId: id,
  3892. // RecordDate: recordDate.Unix(),
  3893. // GoodTypeId: it.GoodTypeId,
  3894. // GoodId: it.ID,
  3895. // Count: 1,
  3896. // Ctime: time.Now().Unix(),
  3897. // Creater: adminUserInfo.AdminUser.Id,
  3898. // Status:1,
  3899. //
  3900. // }
  3901. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3902. // fmt.Println("",errcode)
  3903. // }
  3904. // }
  3905. // }
  3906. //
  3907. // }
  3908. //
  3909. // for _, item := range splitIrrigation {
  3910. // for _,it := range mation{
  3911. // if(item == it.SpecificationName){
  3912. // //查询最近一次的透析器
  3913. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3914. // if errcode == gorm.ErrRecordNotFound{
  3915. // //插入数据
  3916. // prepare := models.DialysisBeforePrepare{
  3917. // UserOrgId: adminUserInfo.Org.Id,
  3918. // PatientId: id,
  3919. // RecordDate: recordDate.Unix(),
  3920. // GoodTypeId: it.GoodTypeId,
  3921. // GoodId: it.ID,
  3922. // Count: 1,
  3923. // Ctime: time.Now().Unix(),
  3924. // Creater: adminUserInfo.AdminUser.Id,
  3925. // Status:1,
  3926. //
  3927. // }
  3928. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3929. // fmt.Println(errcode)
  3930. // }
  3931. // }
  3932. // }
  3933. // }
  3934. //}
  3935. c.ServeSuccessJSON(map[string]interface{}{
  3936. "solution": &solution,
  3937. "prescription": &prescription,
  3938. })
  3939. }
  3940. func (c *DialysisAPIController) GetAcceptsAssessment() {
  3941. patient, _ := c.GetInt64("patient", 0)
  3942. adminUserInfo := c.GetMobileAdminUserInfo()
  3943. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  3944. c.ServeSuccessJSON(map[string]interface{}{
  3945. "receiveTreatmentAsses": receiveTreatmentAsses,
  3946. })
  3947. }
  3948. func (this *DialysisAPIController) PostSignInfo() {
  3949. patientID, _ := this.GetInt64("patient_id")
  3950. recordDateStr := this.GetString("date")
  3951. if patientID <= 0 {
  3952. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3953. return
  3954. }
  3955. if len(recordDateStr) == 0 {
  3956. recordDateStr = time.Now().Format("2006-01-02")
  3957. }
  3958. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3959. if parseDateErr != nil {
  3960. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3961. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3962. return
  3963. }
  3964. adminInfo := this.GetMobileAdminUserInfo()
  3965. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  3966. if err != nil {
  3967. this.ErrorLog("签名失败:%v", err)
  3968. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3969. return
  3970. }
  3971. this.ServeSuccessJSON(map[string]interface{}{
  3972. "doctor_id": adminInfo.AdminUser.Id,
  3973. })
  3974. }
  3975. func (this *DialysisAPIController) GetLastMonitorRecord() {
  3976. patientID, _ := this.GetInt64("patient_id")
  3977. adminInfo := this.GetMobileAdminUserInfo()
  3978. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  3979. this.ServeSuccessJSON(map[string]interface{}{
  3980. "monitor": record,
  3981. })
  3982. }
  3983. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  3984. thisTime := time.Now()
  3985. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3986. timeLayout := "2006-01-02 15:04:05"
  3987. loc, _ := time.LoadLocation("Local")
  3988. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3989. theAssessmentDateTime := theStartTime.Unix()
  3990. patientID, _ := this.GetInt64("patient_id")
  3991. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3992. adminInfo := this.GetMobileAdminUserInfo()
  3993. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3994. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3995. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  3996. var ultrafiltration_rate float64
  3997. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3998. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3999. fmt.Println(evaluation)
  4000. fmt.Println("prescription.ID", prescription.ID)
  4001. if prescription.ID > 0 {
  4002. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4003. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4004. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4005. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4006. record.UltrafiltrationRate = ultrafiltration_rate
  4007. }
  4008. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4009. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4010. record.UltrafiltrationRate = ultrafiltration_rate
  4011. }
  4012. if adminInfo.Org.Id == 10510 {
  4013. record.UltrafiltrationRate = 0
  4014. }
  4015. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4016. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4017. record.UltrafiltrationRate = ultrafiltration_rate
  4018. }
  4019. if template.TemplateId == 20 || template.TemplateId == 22 {
  4020. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4021. record.UltrafiltrationRate = ultrafiltration_rate
  4022. }
  4023. // 只针对方济医院
  4024. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4025. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4026. ultrafiltration_rate = value
  4027. record.UltrafiltrationRate = ultrafiltration_rate
  4028. }
  4029. if template.TemplateId == 41 || template.TemplateId == 47 {
  4030. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4031. record.UltrafiltrationRate = ultrafiltration_rate
  4032. }
  4033. if template.TemplateId == 43 {
  4034. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4035. record.UltrafiltrationRate = ultrafiltration_rate
  4036. }
  4037. if template.TemplateId == 46 || template.TemplateId == 54 {
  4038. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4039. record.UltrafiltrationRate = ultrafiltration_rate
  4040. }
  4041. 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 {
  4042. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4043. record.UltrafiltrationRate = ultrafiltration_rate
  4044. }
  4045. if adminInfo.Org.Id == 10469 {
  4046. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4047. record.UltrafiltrationRate = ultrafiltration_rate
  4048. }
  4049. if adminInfo.Org.Id == 10667 {
  4050. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4051. record.UltrafiltrationRate = ultrafiltration_rate
  4052. }
  4053. if adminInfo.Org.Id == 10471 {
  4054. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4055. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4056. }
  4057. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4058. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4059. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4060. }
  4061. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4062. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4063. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4064. }
  4065. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4066. record.UltrafiltrationRate = 0
  4067. }
  4068. //if template.TemplateId == 47 {
  4069. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4070. // record.UltrafiltrationRate = ultrafiltration_rate
  4071. //}
  4072. }
  4073. }
  4074. // record.UltrafiltrationRate = ultrafiltration_rate
  4075. record.UltrafiltrationVolume = 0
  4076. 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
  4077. if ultrafiltration_rate > 0 {
  4078. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4079. record.UltrafiltrationVolume = value
  4080. }
  4081. }
  4082. 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
  4083. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4084. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4085. record.UltrafiltrationVolume = ultrafiltration_volume
  4086. }
  4087. }
  4088. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4089. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4090. record.UltrafiltrationVolume = ultrafiltration_volume
  4091. }
  4092. //长沙南雅
  4093. 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 {
  4094. if ultrafiltration_rate > 0 {
  4095. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4096. record.UltrafiltrationVolume = ultrafiltration_volume
  4097. }
  4098. }
  4099. if adminInfo.Org.Id == 10471 {
  4100. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4101. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4102. }
  4103. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4104. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4105. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4106. }
  4107. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4108. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4109. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4110. }
  4111. //长沙南雅累计血容量自动计算
  4112. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4113. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4114. //}
  4115. if template.TemplateId == 47 || template.TemplateId == 54 {
  4116. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4117. }
  4118. if adminInfo.Org.Id == 10510 {
  4119. record.UltrafiltrationVolume = 0
  4120. }
  4121. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4122. this.ServeSuccessJSON(map[string]interface{}{
  4123. "monitor": record,
  4124. "lastMonitorRecordList": lastMonitorRecordList,
  4125. })
  4126. }
  4127. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4128. record_id, _ := this.GetInt64("id")
  4129. nurseID, _ := this.GetInt64("start_nurse")
  4130. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4131. bedID, _ := this.GetInt64("bed")
  4132. start_time := this.GetString("start_time")
  4133. schedual_type, _ := this.GetInt64("schedual_type")
  4134. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4135. change_nurse, _ := this.GetInt64("change_nurse")
  4136. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4137. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4138. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4139. patient_id, _ := this.GetInt64("patient_id")
  4140. record_date, _ := this.GetInt64("record_date")
  4141. puncture_needle := this.GetString("puncture_needle")
  4142. puncture_way := this.GetString("puncture_way")
  4143. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4144. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4145. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4146. nuclein_date_str := this.GetString("nuclein_date_str")
  4147. order_remark := this.GetString("order_remark")
  4148. schedule_remark := this.GetString("schedule_remark")
  4149. catheter_operation := this.GetString("catheter_operation")
  4150. blood_flow_volume := this.GetString("blood_flow_volume")
  4151. blood_drawing, _ := this.GetInt64("blood_drawing")
  4152. dialysis_strainer := this.GetString("dialysis_strainer")
  4153. if record_id == 0 {
  4154. this.ErrorLog("id:%v", record_id)
  4155. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4156. return
  4157. }
  4158. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4159. if parseStartDateErr != nil {
  4160. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4161. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4162. return
  4163. }
  4164. adminUserInfo := this.GetMobileAdminUserInfo()
  4165. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4166. if getNurseErr != nil {
  4167. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4169. return
  4170. } else if nurse == nil {
  4171. this.ErrorLog("护士不存在")
  4172. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4173. return
  4174. }
  4175. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4176. //if getNurseErr != nil {
  4177. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4178. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4179. // return
  4180. //} else if nurse == nil {
  4181. // this.ErrorLog("护士不存在")
  4182. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4183. // return
  4184. //}
  4185. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4186. if getDeviceNumberErr != nil {
  4187. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4189. return
  4190. } else if deviceNumber == nil {
  4191. this.ErrorLog("床位号不存在")
  4192. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4193. return
  4194. }
  4195. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4196. //
  4197. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4198. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4199. // if getPermissionErr != nil {
  4200. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4201. // return
  4202. // } else if headNursePermission == nil {
  4203. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4204. // return
  4205. // }
  4206. //}
  4207. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4208. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4209. timeLayout := "2006-01-02 15:04:05"
  4210. loc, _ := time.LoadLocation("Local")
  4211. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4212. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4213. schedulestartTime := theStartTime.Unix()
  4214. scheduleendTime := theEndTime.Unix()
  4215. var theNucleinDate int64
  4216. timeLayoutOne := "2006-01-02"
  4217. if len(nuclein_date_str) > 0 {
  4218. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4219. if err != nil {
  4220. utils.ErrorLog(err.Error())
  4221. }
  4222. theNucleinDate = theTime.Unix()
  4223. }
  4224. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4225. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4226. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4227. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4228. if err == gorm.ErrRecordNotFound { //空床位
  4229. // 修改了床位逻辑
  4230. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4231. if daySchedule.ID > 0 {
  4232. //daySchedule.BedId = bedID
  4233. //daySchedule.PartitionId = deviceNumber.ZoneID
  4234. //daySchedule.ScheduleType = schedual_type
  4235. //daySchedule.UpdatedTime = time.Now().Unix()
  4236. //err := service.UpdateSchedule(&daySchedule)
  4237. xtSchedule := models.Schedule{
  4238. PartitionId: deviceNumber.ZoneID,
  4239. BedId: bedID,
  4240. ScheduleType: schedual_type,
  4241. UpdatedTime: time.Now().Unix(),
  4242. }
  4243. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4244. if err != nil {
  4245. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4246. return
  4247. }
  4248. }
  4249. } else if err == nil {
  4250. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4251. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4252. if daySchedule.ID > 0 {
  4253. //daySchedule.BedId = bedID
  4254. //daySchedule.PartitionId = deviceNumber.ZoneID
  4255. //
  4256. //daySchedule.ScheduleType = schedual_type
  4257. //daySchedule.UpdatedTime = time.Now().Unix()
  4258. //err := service.UpdateSchedule(&daySchedule)
  4259. xtSchedule := models.Schedule{
  4260. PartitionId: deviceNumber.ZoneID,
  4261. BedId: bedID,
  4262. ScheduleType: schedual_type,
  4263. UpdatedTime: time.Now().Unix(),
  4264. }
  4265. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4266. if err != nil {
  4267. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4268. return
  4269. }
  4270. }
  4271. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4272. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4273. return
  4274. }
  4275. } else if err != nil {
  4276. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4277. return
  4278. }
  4279. }
  4280. dialysisRecord := &models.DialysisOrder{
  4281. ID: record_id,
  4282. UserOrgId: adminUserInfo.Org.Id,
  4283. BedID: bedID,
  4284. StartNurse: nurseID,
  4285. StartTime: startDate.Unix(),
  4286. PunctureNurse: puncture_nurse,
  4287. Creator: adminUserInfo.AdminUser.Id,
  4288. Modifier: adminUserInfo.AdminUser.Id,
  4289. WashpipeNurse: washpipe_nurse,
  4290. SchedualType: schedual_type,
  4291. ChangeNurse: change_nurse,
  4292. DifficultPunctureNurse: difficult_puncture_nurse,
  4293. NewFistulaNurse: new_fistula_nurse,
  4294. QualityNurseId: quality_nurse_id,
  4295. PunctureNeedle: puncture_needle,
  4296. PunctureWay: puncture_way,
  4297. DialysisDialyszers: dialysis_dialyszers,
  4298. DialysisIrrigation: dialysis_irrigation,
  4299. BloodAccessId: blood_access_id,
  4300. NucleinDate: theNucleinDate,
  4301. OrderRemark: order_remark,
  4302. ScheduleRemark: schedule_remark,
  4303. CatheterOperation: catheter_operation,
  4304. BloodFlowVolume: blood_flow_volume,
  4305. BloodDrawing: blood_drawing,
  4306. DialysisStrainer: dialysis_strainer,
  4307. }
  4308. //修改床位号需要重新消毒
  4309. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4310. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4311. //查询第一条监测
  4312. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4313. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4314. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4315. redis := service.RedisClient()
  4316. //清空key 值
  4317. redis.Set(key, "", time.Second)
  4318. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4319. redis.Set(keyOne, "", time.Second)
  4320. defer redis.Close()
  4321. }
  4322. // 查询信息规挡的设置天数
  4323. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4324. if infor.ID > 0 && infor.WeekDay > 0 {
  4325. var cha_time int64
  4326. timeNowStr := time.Now().Format("2006-01-02")
  4327. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4328. //今日的日期减去设置的日期
  4329. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4330. if cha_time >= record_date {
  4331. //查询审核是否允许
  4332. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4333. //申请状态不允许的情况 拒绝修改
  4334. if infor.ApplicationStatus != 1 {
  4335. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4336. return
  4337. }
  4338. }
  4339. }
  4340. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4341. order, _ := service.GetLastPatientOrder(record_id)
  4342. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4343. redis := service.RedisClient()
  4344. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4345. redis.Set(key, "", time.Second)
  4346. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4347. //清空key 值
  4348. redis.Set(keyOne, "", time.Second)
  4349. scheduleDateStartOne := startDate.Format("2006-01-02")
  4350. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4351. redis.Set(keyTwo, "", time.Second)
  4352. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4353. redis.Set(keyThree, "", time.Second)
  4354. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4355. redis.Set(keyFour, "", time.Second)
  4356. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4357. redis.Set(keyFive, "", time.Second)
  4358. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4359. redis.Set(keySix, "", time.Second)
  4360. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4361. redis.Set(keySeven, "", time.Second)
  4362. if updateErr != nil {
  4363. this.ErrorLog("修改上机失败:%v", updateErr)
  4364. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4365. return
  4366. }
  4367. if updateErr == nil {
  4368. if tempDialysisRecord.Stage == 2 {
  4369. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4370. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4371. fmt.Println(value)
  4372. a, b := math.Modf(value)
  4373. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4374. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4375. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4376. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4377. redis := service.RedisClient()
  4378. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4379. redis.Set(key, "", time.Second)
  4380. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4381. redis.Set(keyOne, "", time.Second)
  4382. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4383. //清空key 值
  4384. redis.Set(keySix, "", time.Second)
  4385. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4386. redis.Set(keySeven, "", time.Second)
  4387. redis.Close()
  4388. if updateAssessmentErr != nil {
  4389. utils.ErrorLog("%v", updateAssessmentErr)
  4390. }
  4391. }
  4392. }
  4393. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4394. this.ServeSuccessJSON(map[string]interface{}{
  4395. "dialysis_order": dialysisRecords,
  4396. })
  4397. }
  4398. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4399. record_id, _ := c.GetInt64("id")
  4400. nurseID, _ := c.GetInt64("nurse")
  4401. end_time := c.GetString("end_time")
  4402. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4403. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4404. catheter := c.GetString("catheter")
  4405. cruor := c.GetString("cruor")
  4406. mission := c.GetString("mission")
  4407. condenser := c.GetString("condenser")
  4408. if record_id <= 0 || nurseID <= 0 {
  4409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4410. return
  4411. }
  4412. adminUserInfo := c.GetMobileAdminUserInfo()
  4413. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4414. if getNurseErr != nil {
  4415. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4417. return
  4418. } else if nurse == nil {
  4419. c.ErrorLog("护士不存在")
  4420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4421. return
  4422. }
  4423. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4424. if parseEndDateErr != nil {
  4425. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4427. return
  4428. }
  4429. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4430. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4431. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4432. // if getPermissionErr != nil {
  4433. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4434. // return
  4435. // } else if headNursePermission == nil {
  4436. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4437. // return
  4438. // }
  4439. //}
  4440. // 查询信息规挡的设置天数
  4441. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4442. if infor.ID > 0 {
  4443. var cha_time int64
  4444. timeNowStr := time.Now().Format("2006-01-02")
  4445. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4446. //今日的日期减去设置的日期
  4447. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4448. if cha_time >= tempDialysisRecords.DialysisDate {
  4449. //查询审核是否允许
  4450. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4451. //申请状态不允许的情况 拒绝修改
  4452. if infor.ApplicationStatus != 1 {
  4453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4454. return
  4455. }
  4456. }
  4457. }
  4458. dialysisRecord := &models.DialysisOrder{
  4459. ID: record_id,
  4460. UserOrgId: adminUserInfo.Org.Id,
  4461. EndTime: endDate.Unix(),
  4462. FinishNurse: nurseID,
  4463. FinishModifier: adminUserInfo.AdminUser.Id,
  4464. PuncturePointHaematoma: puncture_point_haematoma,
  4465. BloodAccessInternalFistula: blood_access_internal_fistula,
  4466. Catheter: catheter,
  4467. Cruor: cruor,
  4468. Mission: mission,
  4469. Condenser: condenser,
  4470. }
  4471. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4472. redis := service.RedisClient()
  4473. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4474. //清空key 值
  4475. redis.Set(key, "", time.Second)
  4476. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4477. //清空key 值
  4478. redis.Set(keyOne, "", time.Second)
  4479. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4480. redis.Set(keySeven, "", time.Second)
  4481. redis.Close()
  4482. if updateErr != nil {
  4483. c.ErrorLog("修改下机失败:%v", updateErr)
  4484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4485. return
  4486. }
  4487. if updateErr == nil {
  4488. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4489. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4490. a, b := math.Modf(value)
  4491. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4492. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4493. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4494. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4495. redis := service.RedisClient()
  4496. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4497. redis.Set(keyTen, "", time.Second)
  4498. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4499. redis.Set(keyTwo, "", time.Second)
  4500. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4501. redis.Set(key, "", time.Second)
  4502. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4503. redis.Set(keyThree, "", time.Second)
  4504. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4505. redis.Set(keySeven, "", time.Second)
  4506. defer redis.Close()
  4507. if updateAssessmentErr != nil {
  4508. utils.ErrorLog("%v", updateAssessmentErr)
  4509. }
  4510. }
  4511. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4512. c.ServeSuccessJSON(map[string]interface{}{
  4513. "dialysis_order": dialysisRecords,
  4514. })
  4515. }
  4516. func (c *DialysisAPIController) GetLongAdvice() {
  4517. patient_id, _ := c.GetInt64("id")
  4518. adminUserInfo := c.GetMobileAdminUserInfo()
  4519. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4520. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4521. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4522. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4523. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4524. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4525. c.ServeSuccessJSON(map[string]interface{}{
  4526. "status": "1",
  4527. })
  4528. return
  4529. } else { //开启推送提醒
  4530. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4531. var advice_three []*models.DoctorAdvice
  4532. recordDateStr := time.Now().Format("2006-01-02")
  4533. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4534. nowtime := recordDate.Unix()
  4535. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4536. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4537. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4538. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4539. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4540. for _, advice := range advices {
  4541. if advice.FrequencyType == 3 {
  4542. t := time.Now()
  4543. week := int(t.Weekday())
  4544. fmt.Println(t.Weekday())
  4545. fmt.Println(week)
  4546. switch week {
  4547. case 1:
  4548. if strings.Index(advice.WeekDay, "周一") == -1 {
  4549. advice_three = append(advice_three, advice)
  4550. }
  4551. break
  4552. case 2:
  4553. if strings.Index(advice.WeekDay, "周二") == -1 {
  4554. advice_three = append(advice_three, advice)
  4555. }
  4556. break
  4557. case 3:
  4558. if strings.Index(advice.WeekDay, "周三") == -1 {
  4559. advice_three = append(advice_three, advice)
  4560. }
  4561. break
  4562. case 4:
  4563. if strings.Index(advice.WeekDay, "周四") == -1 {
  4564. advice_three = append(advice_three, advice)
  4565. }
  4566. break
  4567. case 5:
  4568. if strings.Index(advice.WeekDay, "周五") == -1 {
  4569. advice_three = append(advice_three, advice)
  4570. }
  4571. break
  4572. case 6:
  4573. if strings.Index(advice.WeekDay, "周六") == -1 {
  4574. advice_three = append(advice_three, advice)
  4575. }
  4576. break
  4577. case 0:
  4578. if strings.Index(advice.WeekDay, "周日") == -1 {
  4579. advice_three = append(advice_three, advice)
  4580. }
  4581. break
  4582. }
  4583. }
  4584. }
  4585. for _, advice := range advices_two {
  4586. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4587. now := p.Unix()
  4588. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4589. dayStr2 := "-" + dayStr
  4590. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4591. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4592. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4593. for _, ad := range advices {
  4594. advice_three = append(advice_three, ad)
  4595. }
  4596. }
  4597. if err == nil {
  4598. c.ServeSuccessJSON(map[string]interface{}{
  4599. "status": "2",
  4600. "advices": advices,
  4601. "advices_two": RemoveRepeatedElement(advice_three),
  4602. "is_open_remind": config.IsOpenRemind,
  4603. "his_config_open": hisConfig.IsOpen,
  4604. "is_advice_open": is_advice_open.IsAdviceOpen,
  4605. "prescription_open": prescription_open.IsOpen,
  4606. })
  4607. }
  4608. }
  4609. }
  4610. func (c *DialysisAPIController) GetLongAdviceOne() {
  4611. patient_id, _ := c.GetInt64("id")
  4612. startTime := c.GetString("schedule_date")
  4613. timeLayout := "2006-01-02"
  4614. loc, _ := time.LoadLocation("Local")
  4615. var theStartTime int64
  4616. if len(startTime) > 0 {
  4617. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4618. if err != nil {
  4619. utils.ErrorLog(err.Error())
  4620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4621. return
  4622. }
  4623. theStartTime = theTime.Unix()
  4624. }
  4625. adminUserInfo := c.GetMobileAdminUserInfo()
  4626. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4627. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4628. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4629. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4630. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4631. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4632. c.ServeSuccessJSON(map[string]interface{}{
  4633. "status": "1",
  4634. })
  4635. return
  4636. } else { //开启推送提醒
  4637. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4638. var advice_three []*models.DoctorAdvice
  4639. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4640. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4641. for _, advice := range advices {
  4642. if advice.FrequencyType == 3 {
  4643. t := time.Now()
  4644. week := int(t.Weekday())
  4645. fmt.Println(t.Weekday())
  4646. fmt.Println(week)
  4647. switch week {
  4648. case 1:
  4649. if strings.Index(advice.WeekDay, "周一") == -1 {
  4650. advice_three = append(advice_three, advice)
  4651. }
  4652. break
  4653. case 2:
  4654. if strings.Index(advice.WeekDay, "周二") == -1 {
  4655. advice_three = append(advice_three, advice)
  4656. }
  4657. break
  4658. case 3:
  4659. if strings.Index(advice.WeekDay, "周三") == -1 {
  4660. advice_three = append(advice_three, advice)
  4661. }
  4662. break
  4663. case 4:
  4664. if strings.Index(advice.WeekDay, "周四") == -1 {
  4665. advice_three = append(advice_three, advice)
  4666. }
  4667. break
  4668. case 5:
  4669. if strings.Index(advice.WeekDay, "周五") == -1 {
  4670. advice_three = append(advice_three, advice)
  4671. }
  4672. break
  4673. case 6:
  4674. if strings.Index(advice.WeekDay, "周六") == -1 {
  4675. advice_three = append(advice_three, advice)
  4676. }
  4677. break
  4678. case 0:
  4679. if strings.Index(advice.WeekDay, "周日") == -1 {
  4680. advice_three = append(advice_three, advice)
  4681. }
  4682. break
  4683. }
  4684. }
  4685. }
  4686. for _, advice := range advices_two {
  4687. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4688. now := p.Unix()
  4689. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4690. dayStr2 := "-" + dayStr
  4691. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4692. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4693. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4694. for _, ad := range advices {
  4695. advice_three = append(advice_three, ad)
  4696. }
  4697. }
  4698. if err == nil {
  4699. c.ServeSuccessJSON(map[string]interface{}{
  4700. "status": "2",
  4701. "advices": advices,
  4702. "advices_two": RemoveRepeatedElement(advice_three),
  4703. "is_open_remind": config.IsOpenRemind,
  4704. "his_config_open": hisConfig.IsOpen,
  4705. "is_advice_open": is_advice_open.IsAdviceOpen,
  4706. "prescription_open": prescription_open.IsOpen,
  4707. })
  4708. }
  4709. }
  4710. }
  4711. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4712. newArr = make([]*models.DoctorAdvice, 0)
  4713. for i := 0; i < len(arr); i++ {
  4714. repeat := false
  4715. for j := i + 1; j < len(arr); j++ {
  4716. if arr[i].ID == arr[j].ID {
  4717. repeat = true
  4718. break
  4719. }
  4720. }
  4721. if !repeat {
  4722. newArr = append(newArr, arr[i])
  4723. }
  4724. }
  4725. return
  4726. }
  4727. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4728. patient, _ := c.GetInt64("id", 0)
  4729. groupNo, _ := c.GetInt64("groupno", 0)
  4730. if patient <= 0 {
  4731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4732. return
  4733. }
  4734. adminUserInfo := c.GetMobileAdminUserInfo()
  4735. dataBody := make(map[string]interface{}, 0)
  4736. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4737. if err != nil {
  4738. utils.ErrorLog(err.Error())
  4739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4740. return
  4741. }
  4742. utils.ErrorLog("%v", dataBody)
  4743. timeLayout := "2006-01-02 15:04"
  4744. loc, _ := time.LoadLocation("Local")
  4745. timeLayout2 := "2006-01-02"
  4746. loc2, _ := time.LoadLocation("Local")
  4747. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4748. utils.ErrorLog("advice_type")
  4749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4750. return
  4751. }
  4752. adviceType := int64(2)
  4753. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4754. utils.ErrorLog("advice_date")
  4755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4756. return
  4757. }
  4758. adviceDate, _ := dataBody["advice_date"].(string)
  4759. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4760. AdviceDate := theTime.Unix()
  4761. RecordDate := theTime.Unix()
  4762. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4763. utils.ErrorLog("start_time")
  4764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4765. return
  4766. }
  4767. startTime, _ := dataBody["start_time"].(string)
  4768. if len(startTime) == 0 {
  4769. utils.ErrorLog("len(start_time) == 0")
  4770. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4771. return
  4772. }
  4773. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4774. if err != nil {
  4775. utils.ErrorLog(err.Error())
  4776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4777. return
  4778. }
  4779. StartTime := theTime.Unix()
  4780. Remark := ""
  4781. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4782. remark, _ := dataBody["remark"].(string)
  4783. Remark = remark
  4784. }
  4785. var advices []*models.GroupAdvice
  4786. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4787. utils.ErrorLog("advices")
  4788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4789. return
  4790. }
  4791. adviceNames := dataBody["advices"].([]interface{})
  4792. for _, adviceNameMap := range adviceNames {
  4793. adviceNameM := adviceNameMap.(map[string]interface{})
  4794. var advice models.GroupAdvice
  4795. advice.Remark = Remark
  4796. advice.AdviceType = adviceType
  4797. advice.StartTime = StartTime
  4798. advice.AdviceDate = AdviceDate
  4799. advice.RecordDate = RecordDate
  4800. advice.Status = 1
  4801. advice.CreatedTime = time.Now().Unix()
  4802. advice.UpdatedTime = time.Now().Unix()
  4803. advice.StopState = 2
  4804. advice.ExecutionState = 2
  4805. advice.UserOrgId = adminUserInfo.Org.Id
  4806. advice.PatientId = patient
  4807. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4808. advice.IsSettle = 2
  4809. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4810. utils.ErrorLog("advice_name")
  4811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4812. return
  4813. }
  4814. adviceName, _ := adviceNameM["advice_name"].(string)
  4815. if len(adviceName) == 0 {
  4816. utils.ErrorLog("len(advice_name) == 0")
  4817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4818. return
  4819. }
  4820. advice.AdviceName = adviceName
  4821. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4822. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4823. advice.DrugSpec = drugSpec
  4824. }
  4825. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4826. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4827. advice.AdviceDesc = adviceDesc
  4828. }
  4829. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4830. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4831. advice.DrugSpecUnit = drugSpecUnit
  4832. }
  4833. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4834. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4835. // advice.SingleDose = singleDose
  4836. //}
  4837. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4838. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4839. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4840. }
  4841. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4842. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4843. advice.SingleDoseUnit = singleDoseUnit
  4844. }
  4845. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4846. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4847. // advice.PrescribingNumber = prescribingNumber
  4848. //}
  4849. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4850. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4851. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4852. }
  4853. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4854. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4855. advice.PrescribingNumberUnit = prescribingNumberUnit
  4856. }
  4857. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4858. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4859. advice.DeliveryWay = deliveryWay
  4860. }
  4861. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4862. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4863. advice.ExecutionFrequency = executionFrequency
  4864. }
  4865. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4866. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4867. advice.FrequencyType = frequency_type
  4868. }
  4869. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4870. day_count := int64(adviceNameM["day_count"].(float64))
  4871. advice.DayCount = day_count
  4872. }
  4873. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4874. week_day, _ := adviceNameM["week_day"].(string)
  4875. advice.WeekDay = week_day
  4876. }
  4877. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4878. way := int64(adviceNameM["way"].(float64))
  4879. advice.Way = way
  4880. }
  4881. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4882. drug_id := int64(adviceNameM["drug_id"].(float64))
  4883. advice.DrugId = drug_id
  4884. }
  4885. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4886. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4887. advice.DrugNameId = drug_name_id
  4888. }
  4889. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  4890. remark, _ := adviceNameM["remark"].(string)
  4891. advice.Remark = remark
  4892. }
  4893. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  4894. groupno := int64(adviceNameM["groupno"].(float64))
  4895. advice.GroupNo = groupno
  4896. }
  4897. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4898. template_id, _ := adviceNameM["template_id"].(string)
  4899. advice.TemplateId = template_id
  4900. }
  4901. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4902. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4903. advice.ExecutionFrequency = executionFrequency
  4904. }
  4905. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4906. children := adviceNameM["child"].([]interface{})
  4907. if len(children) > 0 {
  4908. for _, childrenMap := range children {
  4909. childMap := childrenMap.(map[string]interface{})
  4910. var child models.GroupAdvice
  4911. child.Remark = Remark
  4912. child.AdviceType = adviceType
  4913. child.StartTime = StartTime
  4914. child.AdviceDate = AdviceDate
  4915. child.RecordDate = RecordDate
  4916. child.Status = 1
  4917. child.CreatedTime = time.Now().Unix()
  4918. child.UpdatedTime = time.Now().Unix()
  4919. child.StopState = 2
  4920. child.ExecutionState = 2
  4921. child.UserOrgId = adminUserInfo.Org.Id
  4922. child.PatientId = patient
  4923. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4924. child.IsSettle = 1
  4925. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4926. utils.ErrorLog("child advice_name")
  4927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4928. return
  4929. }
  4930. childAdviceName, _ := childMap["advice_name"].(string)
  4931. if len(childAdviceName) == 0 {
  4932. utils.ErrorLog("len(child advice_name) == 0")
  4933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4934. return
  4935. }
  4936. child.AdviceName = childAdviceName
  4937. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4938. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4939. child.AdviceDesc = childAdviceDesc
  4940. }
  4941. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4942. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4943. child.DrugSpec = childDrugSpec
  4944. }
  4945. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4946. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4947. child.DrugSpecUnit = childDrugSpecUnit
  4948. }
  4949. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4950. child.SingleDose = childMap["single_dose"].(float64)
  4951. }
  4952. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4953. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4954. child.SingleDoseUnit = childSingleDoseUnit
  4955. }
  4956. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4957. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4958. }
  4959. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4960. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4961. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4962. }
  4963. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  4964. groupno := int64(childMap["groupno"].(float64))
  4965. advice.GroupNo = groupno
  4966. }
  4967. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  4968. remark, _ := childMap["remark"].(string)
  4969. child.Remark = remark
  4970. }
  4971. child.DeliveryWay = advice.DeliveryWay
  4972. child.ExecutionFrequency = advice.ExecutionFrequency
  4973. advice.Children = append(advice.Children, &child)
  4974. }
  4975. }
  4976. }
  4977. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  4978. if temp_advice.ID == 0 {
  4979. advices = append(advices, &advice)
  4980. }
  4981. }
  4982. if len(advices) > 0 {
  4983. finish := models.XtDialysisFinish{
  4984. IsFinish: 1,
  4985. UserOrgId: adminUserInfo.Org.Id,
  4986. Status: 1,
  4987. Ctime: time.Now().Unix(),
  4988. Mtime: 0,
  4989. Module: 4,
  4990. RecordDate: AdviceDate,
  4991. Sourse: 1,
  4992. PatientId: patient,
  4993. }
  4994. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  4995. if dialysisFinish.ID == 0 {
  4996. service.CreateDialysisFinish(finish)
  4997. }
  4998. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  4999. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5000. for _, item := range advices {
  5001. byterequest, _ := json.Marshal(item)
  5002. adviceLog := models.XtDoctorAdviceLog{
  5003. UserOrgId: adminUserInfo.Org.Id,
  5004. PatientId: patient,
  5005. AdminUserId: adminUserInfo.AdminUser.Id,
  5006. Module: 1,
  5007. ErrLog: string(byterequest),
  5008. Status: 1,
  5009. Ctime: time.Now().Unix(),
  5010. Mtime: 0,
  5011. Source: "手机端医嘱推送",
  5012. RecordDate: item.AdviceDate,
  5013. }
  5014. service.CreateDoctorAdviceLog(adviceLog)
  5015. }
  5016. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5017. redis := service.RedisClient()
  5018. //清空key 值
  5019. redis.Set(key, "", time.Second)
  5020. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5021. redis.Set(keyOne, "", time.Second)
  5022. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5023. defer redis.Close()
  5024. redis.Set(keyThree, "", time.Second)
  5025. if err != nil {
  5026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5027. return
  5028. }
  5029. c.ServeSuccessJSON(map[string]interface{}{
  5030. "msg": "ok",
  5031. "advices": list,
  5032. })
  5033. } else {
  5034. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5035. for _, item := range advices {
  5036. byterequest, _ := json.Marshal(item)
  5037. adviceLog := models.XtDoctorAdviceLog{
  5038. UserOrgId: adminUserInfo.Org.Id,
  5039. PatientId: patient,
  5040. AdminUserId: adminUserInfo.AdminUser.Id,
  5041. Module: 1,
  5042. ErrLog: string(byterequest),
  5043. Status: 1,
  5044. Ctime: time.Now().Unix(),
  5045. Mtime: 0,
  5046. Source: "手机端医嘱推送",
  5047. RecordDate: item.AdviceDate,
  5048. }
  5049. service.CreateDoctorAdviceLog(adviceLog)
  5050. }
  5051. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5052. redis := service.RedisClient()
  5053. //清空key 值
  5054. redis.Set(key, "", time.Second)
  5055. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5056. redis.Set(keyOne, "", time.Second)
  5057. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5058. defer redis.Close()
  5059. redis.Set(keyThree, "", time.Second)
  5060. if err != nil {
  5061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5062. return
  5063. }
  5064. c.ServeSuccessJSON(map[string]interface{}{
  5065. "msg": "ok",
  5066. "advices": list,
  5067. })
  5068. }
  5069. } else {
  5070. c.ServeSuccessJSON(map[string]interface{}{
  5071. "msg": "ok",
  5072. })
  5073. }
  5074. return
  5075. }
  5076. func (c *DialysisAPIController) UploadDryWeight() {
  5077. patient_id, _ := c.GetInt64("id")
  5078. dry_weight, _ := c.GetFloat("dry_weight")
  5079. doctor_id, _ := c.GetInt64("doctor_id")
  5080. remark := c.GetString("remark")
  5081. adminUserInfo := c.GetMobileAdminUserInfo()
  5082. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5083. if err == gorm.ErrRecordNotFound {
  5084. dryWeight := &models.SgjPatientDryweight{
  5085. PatientId: patient_id,
  5086. DryWeight: dry_weight,
  5087. Remakes: remark,
  5088. Ctime: time.Now().Unix(),
  5089. Mtime: time.Now().Unix(),
  5090. Creator: doctor_id,
  5091. Status: 1,
  5092. UserOrgId: adminUserInfo.Org.Id,
  5093. AdjustedValue: "/",
  5094. UserId: adminUserInfo.AdminUser.Id,
  5095. }
  5096. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5097. redis := service.RedisClient()
  5098. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5099. redis.Set(keyOne, "", time.Second)
  5100. loc, _ := time.LoadLocation("Local")
  5101. nowTime := time.Now()
  5102. nowDay := nowTime.Format("2006-01-02")
  5103. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5104. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5105. redis.Set(key, "", time.Second)
  5106. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5107. redis.Set(keyTwo, "", time.Second)
  5108. redis.Close()
  5109. if createErr == nil {
  5110. c.ServeSuccessJSON(map[string]interface{}{
  5111. "msg": "提交成功",
  5112. "weight": dryWeight,
  5113. })
  5114. }
  5115. } else {
  5116. dryWeight := &models.SgjPatientDryweight{
  5117. PatientId: patient_id,
  5118. DryWeight: dry_weight,
  5119. Remakes: remark,
  5120. Ctime: time.Now().Unix(),
  5121. Mtime: time.Now().Unix(),
  5122. Creator: doctor_id,
  5123. Status: 1,
  5124. UserOrgId: adminUserInfo.Org.Id,
  5125. AdjustedValue: "/",
  5126. UserId: adminUserInfo.AdminUser.Id,
  5127. }
  5128. var value float64
  5129. value = dry_weight - weightAdjust.DryWeight
  5130. if value < 0 {
  5131. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5132. } else if value == 0 {
  5133. dryWeight.AdjustedValue = "/"
  5134. } else if value > 0 {
  5135. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5136. }
  5137. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5138. redis := service.RedisClient()
  5139. loc, _ := time.LoadLocation("Local")
  5140. nowTime := time.Now()
  5141. nowDay := nowTime.Format("2006-01-02")
  5142. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5143. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5144. redis.Set(keyOne, "", time.Second)
  5145. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5146. redis.Set(key, "", time.Second)
  5147. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5148. redis.Set(keyTwo, "", time.Second)
  5149. redis.Close()
  5150. if createErr == nil {
  5151. c.ServeSuccessJSON(map[string]interface{}{
  5152. "msg": "提交成功",
  5153. "weight": dryWeight,
  5154. })
  5155. }
  5156. }
  5157. }
  5158. func (c *DialysisAPIController) GetSolution() {
  5159. patient_id, _ := c.GetInt64("patient_id")
  5160. mode_id, _ := c.GetInt64("mode_id")
  5161. adminUserInfo := c.GetMobileAdminUserInfo()
  5162. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5163. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5164. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5165. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5166. if err != nil {
  5167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5168. return
  5169. }
  5170. c.ServeSuccessJSON(map[string]interface{}{
  5171. "solution": solution,
  5172. "prescription": prescription,
  5173. "system_prescription": system_prescription,
  5174. "dialysisPrescription": dialysisPrescription,
  5175. })
  5176. }
  5177. func (c *DialysisAPIController) GetSchedule() {
  5178. schedual_type, _ := c.GetInt64("schedual_type")
  5179. adminUserInfo := c.GetMobileAdminUserInfo()
  5180. scheduleTime, _ := c.GetInt64("record_date")
  5181. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5182. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5183. c.ServeSuccessJSON(map[string]interface{}{
  5184. "number": deviceNumber,
  5185. "list": list,
  5186. })
  5187. }
  5188. func (c *DialysisAPIController) GetPatientId() {
  5189. id, _ := c.GetInt64("id")
  5190. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5191. patientId, _ := service.GetPatientId(id)
  5192. //获取该患者的所有传染病
  5193. list, _ := service.GetPatientInfectious(id)
  5194. c.ServeSuccessJSON(map[string]interface{}{
  5195. "patient": patientId,
  5196. "infectioulist": list,
  5197. })
  5198. }
  5199. func (this *DialysisAPIController) GetDialysisSchedule() {
  5200. schedualDate := this.GetString("date")
  5201. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5202. if parseDateErr != nil {
  5203. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5204. return
  5205. }
  5206. adminInfo := this.GetMobileAdminUserInfo()
  5207. orgID := adminInfo.Org.Id
  5208. redis := service.RedisClient()
  5209. defer redis.Close()
  5210. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5211. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5212. if len(scheduals) > 0 {
  5213. //缓存数据
  5214. scheduals_json, err := json.Marshal(scheduals)
  5215. if err == nil {
  5216. redis.Set(key, scheduals_json, time.Second*30)
  5217. }
  5218. }
  5219. this.ServeSuccessJSON(map[string]interface{}{
  5220. "scheduals": scheduals,
  5221. })
  5222. }
  5223. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5224. change_type, _ := this.GetInt64("type", 0)
  5225. record_date := this.GetString("record_time")
  5226. patient_id, _ := this.GetInt64("patient_id", 0)
  5227. timeLayout := "2006-01-02"
  5228. loc, _ := time.LoadLocation("Local")
  5229. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5230. record_time := theAdviceRecordTime.Unix()
  5231. adminUserInfo := this.GetMobileAdminUserInfo()
  5232. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5233. if err == nil {
  5234. if len(advices) == 0 {
  5235. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5236. return
  5237. } else {
  5238. this.ServeSuccessJSON(map[string]interface{}{
  5239. "advices": advices,
  5240. "schedule": sch,
  5241. })
  5242. return
  5243. }
  5244. } else {
  5245. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5246. return
  5247. }
  5248. }
  5249. func (c *DialysisAPIController) CreateConsumables() {
  5250. record_date := c.GetString("record_time")
  5251. patient_id, _ := c.GetInt64("patient_id", 0)
  5252. active, _ := c.GetInt64("active")
  5253. adminUser := c.GetMobileAdminUserInfo()
  5254. timeLayout := "2006-01-02"
  5255. loc, _ := time.LoadLocation("Local")
  5256. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5257. record_time := theRecordTime.Unix()
  5258. // 查询信息规挡的设置天数
  5259. orgid := c.GetMobileAdminUserInfo().Org.Id
  5260. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5261. if infor.ID > 0 {
  5262. var cha_time int64
  5263. timeNowStr := time.Now().Format("2006-01-02")
  5264. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5265. //今日的日期减去设置的日期
  5266. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5267. if cha_time >= record_time {
  5268. //查询审核是否允许
  5269. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5270. //申请状态不允许的情况 拒绝修改
  5271. if infor.ApplicationStatus != 1 {
  5272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5273. return
  5274. }
  5275. }
  5276. }
  5277. dataBody := make(map[string]interface{}, 0)
  5278. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5279. if err != nil {
  5280. utils.ErrorLog(err.Error())
  5281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5282. return
  5283. }
  5284. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5285. var beforePrepares []*models.DialysisBeforePrepareGoods
  5286. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5287. var dialysisBefor []*models.DialysisBeforePrepare
  5288. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5289. goods, _ := dataBody["goods"].([]interface{})
  5290. if len(goods) > 0 {
  5291. for _, item := range goods {
  5292. items := item.(map[string]interface{})
  5293. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5294. utils.ErrorLog("good_id")
  5295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5296. return
  5297. }
  5298. good_id := int64(items["good_id"].(float64))
  5299. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5300. utils.ErrorLog("good_type_id")
  5301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5302. return
  5303. }
  5304. good_type_id := int64(items["good_type_id"].(float64))
  5305. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5306. utils.ErrorLog("count")
  5307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5308. return
  5309. }
  5310. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5311. commdity_code := items["commdity_code"].(string)
  5312. fmt.Println("commdity", commdity_code)
  5313. prepareGoods := &models.DialysisBeforePrepareGoods{
  5314. GoodTypeId: good_type_id,
  5315. GoodId: good_id,
  5316. Count: count,
  5317. StorehouseId: houseConfig.StorehouseOutInfo,
  5318. PatientId: patient_id,
  5319. }
  5320. beforePrepares = append(beforePrepares, prepareGoods)
  5321. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5322. GoodTypeId: good_type_id,
  5323. GoodId: good_id,
  5324. Count: count,
  5325. StorehouseId: houseConfig.StorehouseOutInfo,
  5326. PatientId: patient_id,
  5327. }
  5328. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5329. prepare := &models.DialysisBeforePrepare{
  5330. GoodTypeId: good_type_id,
  5331. GoodId: good_id,
  5332. Count: count,
  5333. PatientId: patient_id,
  5334. RecordDate: record_time,
  5335. UserOrgId: adminUser.Org.Id,
  5336. Status: 1,
  5337. Ctime: time.Now().Unix(),
  5338. Creater: adminUser.AdminUser.Id,
  5339. CommdityCode: commdity_code,
  5340. StorehouseId: houseConfig.StorehouseOutInfo,
  5341. }
  5342. dialysisBefor = append(dialysisBefor, prepare)
  5343. }
  5344. }
  5345. //查询是否有库存
  5346. for _, item := range dialysisBefor {
  5347. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5348. if err == gorm.ErrRecordNotFound {
  5349. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5350. c.ServeSuccessJSON(map[string]interface{}{
  5351. "message": "1",
  5352. "good_name": goodObj.GoodName,
  5353. "specification_name": goodObj.SpecificationName,
  5354. })
  5355. return
  5356. }
  5357. if err != nil {
  5358. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5359. c.ServeSuccessJSON(map[string]interface{}{
  5360. "message": "1",
  5361. "good_name": goodObj.GoodName,
  5362. "specification_name": goodObj.SpecificationName,
  5363. })
  5364. return
  5365. }
  5366. }
  5367. //新增
  5368. if active == 1 && len(goods) > 0 {
  5369. db := service.XTWriteDB()
  5370. tx := db.Begin()
  5371. // 在函数结束时处理事务回滚
  5372. defer func() {
  5373. if r := recover(); r != nil {
  5374. tx.Rollback()
  5375. } else {
  5376. tx.Commit()
  5377. }
  5378. }()
  5379. for _, item := range newBeforePrepares {
  5380. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5381. adminInfo := c.GetMobileAdminUserInfo()
  5382. var his_count int64
  5383. //查询该耗材今日出库了多少
  5384. outInfo, _ := service.GetHistoryWarehouseOutInfo(item.PatientId, adminInfo.Org.Id, record_time, item.GoodId, tx)
  5385. for _, it := range outInfo {
  5386. his_count += it.Count
  5387. }
  5388. if item.Count > his_count {
  5389. //如果当前出库数据 大于历史出库数据,那么需要出库
  5390. var cha_count int64
  5391. cha_count = item.Count - his_count
  5392. timeStr := time.Now().Format("2006-01-02")
  5393. timeArr := strings.Split(timeStr, "-")
  5394. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5395. total = total + 1
  5396. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5397. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5398. number = number + total
  5399. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5400. operation_time := time.Now().Unix()
  5401. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5402. recordDateStr := time.Now().Format("2006-01-02")
  5403. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5404. nowtime := recordDate.Unix()
  5405. //查询默认出库仓库库存
  5406. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5407. warehouseOut := models.WarehouseOut{
  5408. WarehouseOutOrderNumber: warehousing_out_order,
  5409. OperationTime: operation_time,
  5410. OrgId: adminInfo.Org.Id,
  5411. Creater: creater,
  5412. Ctime: time.Now().Unix(),
  5413. Status: 1,
  5414. WarehouseOutTime: nowtime,
  5415. Type: 1,
  5416. StorehouseId: storeConfig.StorehouseOutInfo,
  5417. IsCheck: 1,
  5418. IsSys: 1,
  5419. }
  5420. //查询是否生成出库单
  5421. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  5422. if out.ID == 0 {
  5423. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  5424. }
  5425. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  5426. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  5427. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  5428. dialyPrepareOne := models.DialysisBeforePrepare{
  5429. GoodTypeId: goodObj.GoodTypeId,
  5430. GoodId: item.GoodId,
  5431. PatientId: item.PatientId,
  5432. RecordDate: record_time,
  5433. UserOrgId: adminInfo.Org.Id,
  5434. Count: cha_count,
  5435. Ctime: time.Now().Unix(),
  5436. Creater: creater,
  5437. Status: 1,
  5438. StorehouseId: houseConfig.StorehouseOutInfo,
  5439. ProjectId: item.ProjectId,
  5440. }
  5441. //出库
  5442. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, item.PatientId, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  5443. if err == nil {
  5444. goodErrcode := models.XtGoodErrcode{
  5445. UserOrgId: adminInfo.Org.Id,
  5446. Errcode: "自动出库接口报错",
  5447. GoodId: 0,
  5448. Status: 1,
  5449. Ctime: time.Now().Unix(),
  5450. Mtime: 0,
  5451. Count: 0,
  5452. StockCount: 0,
  5453. Creater: creator,
  5454. BatchNumberId: 0,
  5455. WarehouseOutId: 0,
  5456. }
  5457. service.CreateGoodErrcode(goodErrcode)
  5458. utils.TraceLog("创建出库单失败 err = %v", err)
  5459. }
  5460. service.ModfiyAddDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  5461. }
  5462. if item.Count < his_count {
  5463. var cha_count int64
  5464. cha_count = his_count - item.Count
  5465. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.ProjectId, tx)
  5466. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5467. newPrescriptionProject := &models.HisPrescriptionProject{
  5468. ID: item.ProjectId,
  5469. ProjectId: item.GoodId,
  5470. UserOrgId: adminInfo.Org.Id,
  5471. Status: 1,
  5472. Ctime: time.Now().Unix(),
  5473. Mtime: time.Now().Unix(),
  5474. PatientId: item.PatientId,
  5475. RecordDate: record_time,
  5476. Count: strconv.FormatInt(item.Count, 10),
  5477. }
  5478. service.NewMobileHisGoodCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, cha_count, goodObj, tx)
  5479. service.NewMobileHisGoodAutoCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, cha_count, goodObj, tx)
  5480. service.ModfiyReduceDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  5481. }
  5482. if item.Count == his_count {
  5483. if his_count == 0 {
  5484. recordDateStr := time.Now().Format("2006-01-02")
  5485. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5486. nowtime := recordDate.Unix()
  5487. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  5488. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  5489. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  5490. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5491. dialyPrepareOne := models.DialysisBeforePrepare{
  5492. GoodTypeId: goodObj.GoodTypeId,
  5493. GoodId: item.GoodId,
  5494. PatientId: item.PatientId,
  5495. RecordDate: record_time,
  5496. UserOrgId: adminInfo.Org.Id,
  5497. Count: item.Count,
  5498. Ctime: time.Now().Unix(),
  5499. Creater: creater,
  5500. Status: 1,
  5501. StorehouseId: houseConfig.StorehouseOutInfo,
  5502. ProjectId: item.ProjectId,
  5503. }
  5504. //出库
  5505. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, patient_id, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  5506. service.ModfiyAddDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  5507. }
  5508. }
  5509. //查询剩余库存
  5510. goodList, _ := service.GetNewAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo, tx)
  5511. var sum_count int64
  5512. for _, item := range goodList {
  5513. sum_count += item.StockCount
  5514. }
  5515. //更新剩余库存
  5516. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id, sum_count, tx)
  5517. //耗材
  5518. service.UpdateNewGoodSumCountSeven(sum_count, item.GoodId, adminInfo.Org.Id, tx)
  5519. }
  5520. if err == nil {
  5521. c.ServeSuccessJSON(map[string]interface{}{
  5522. "msg": "保存成功",
  5523. "message": "2",
  5524. })
  5525. return
  5526. } else {
  5527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5528. return
  5529. }
  5530. }
  5531. if len(beforePrepares) > 0 && active == 2 {
  5532. db := service.XTWriteDB()
  5533. tx := db.Begin()
  5534. // 在函数结束时处理事务回滚
  5535. defer func() {
  5536. if r := recover(); r != nil {
  5537. tx.Rollback()
  5538. } else {
  5539. tx.Commit()
  5540. }
  5541. }()
  5542. for _, item := range newBeforePrepares {
  5543. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5544. adminInfo := c.GetMobileAdminUserInfo()
  5545. var his_count int64
  5546. //查询该耗材今日出库了多少
  5547. outInfo, _ := service.GetHistoryWarehouseOutInfo(item.PatientId, adminInfo.Org.Id, record_time, item.GoodId, tx)
  5548. for _, it := range outInfo {
  5549. his_count += it.Count
  5550. }
  5551. if item.Count > his_count {
  5552. //如果当前出库数据 大于历史出库数据,那么需要出库
  5553. var cha_count int64
  5554. cha_count = item.Count - his_count
  5555. timeStr := time.Now().Format("2006-01-02")
  5556. timeArr := strings.Split(timeStr, "-")
  5557. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5558. total = total + 1
  5559. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5560. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5561. number = number + total
  5562. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5563. operation_time := time.Now().Unix()
  5564. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5565. recordDateStr := time.Now().Format("2006-01-02")
  5566. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5567. nowtime := recordDate.Unix()
  5568. //查询默认出库仓库库存
  5569. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5570. warehouseOut := models.WarehouseOut{
  5571. WarehouseOutOrderNumber: warehousing_out_order,
  5572. OperationTime: operation_time,
  5573. OrgId: adminInfo.Org.Id,
  5574. Creater: creater,
  5575. Ctime: time.Now().Unix(),
  5576. Status: 1,
  5577. WarehouseOutTime: nowtime,
  5578. Type: 1,
  5579. StorehouseId: storeConfig.StorehouseOutInfo,
  5580. IsCheck: 1,
  5581. IsSys: 1,
  5582. }
  5583. //查询是否生成出库单
  5584. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  5585. if out.ID == 0 {
  5586. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  5587. }
  5588. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  5589. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  5590. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  5591. dialyPrepareOne := models.DialysisBeforePrepare{
  5592. GoodTypeId: goodObj.GoodTypeId,
  5593. GoodId: item.GoodId,
  5594. PatientId: item.PatientId,
  5595. RecordDate: record_time,
  5596. UserOrgId: adminInfo.Org.Id,
  5597. Count: cha_count,
  5598. Ctime: time.Now().Unix(),
  5599. Creater: creater,
  5600. Status: 1,
  5601. StorehouseId: houseConfig.StorehouseOutInfo,
  5602. ProjectId: item.ProjectId,
  5603. }
  5604. //出库
  5605. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, item.PatientId, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  5606. if err == nil {
  5607. goodErrcode := models.XtGoodErrcode{
  5608. UserOrgId: adminInfo.Org.Id,
  5609. Errcode: "自动出库接口报错",
  5610. GoodId: 0,
  5611. Status: 1,
  5612. Ctime: time.Now().Unix(),
  5613. Mtime: 0,
  5614. Count: 0,
  5615. StockCount: 0,
  5616. Creater: creator,
  5617. BatchNumberId: 0,
  5618. WarehouseOutId: 0,
  5619. }
  5620. service.CreateGoodErrcode(goodErrcode)
  5621. utils.TraceLog("创建出库单失败 err = %v", err)
  5622. }
  5623. service.ModfiyAddDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  5624. }
  5625. if item.Count < his_count {
  5626. var cha_count int64
  5627. cha_count = his_count - item.Count
  5628. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.ProjectId, tx)
  5629. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5630. newPrescriptionProject := &models.HisPrescriptionProject{
  5631. ID: item.ProjectId,
  5632. ProjectId: item.GoodId,
  5633. UserOrgId: adminInfo.Org.Id,
  5634. Status: 1,
  5635. Ctime: time.Now().Unix(),
  5636. Mtime: time.Now().Unix(),
  5637. PatientId: item.PatientId,
  5638. RecordDate: record_time,
  5639. Count: strconv.FormatInt(item.Count, 10),
  5640. }
  5641. service.NewMobileHisGoodCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, cha_count, goodObj, tx)
  5642. service.NewMobileHisGoodAutoCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, cha_count, goodObj, tx)
  5643. service.ModfiyReduceDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  5644. }
  5645. if item.Count == his_count {
  5646. if his_count == 0 {
  5647. recordDateStr := time.Now().Format("2006-01-02")
  5648. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5649. nowtime := recordDate.Unix()
  5650. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  5651. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  5652. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  5653. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5654. dialyPrepareOne := models.DialysisBeforePrepare{
  5655. GoodTypeId: goodObj.GoodTypeId,
  5656. GoodId: item.GoodId,
  5657. PatientId: item.PatientId,
  5658. RecordDate: record_time,
  5659. UserOrgId: adminInfo.Org.Id,
  5660. Count: item.Count,
  5661. Ctime: time.Now().Unix(),
  5662. Creater: creater,
  5663. Status: 1,
  5664. StorehouseId: houseConfig.StorehouseOutInfo,
  5665. ProjectId: item.ProjectId,
  5666. }
  5667. //出库
  5668. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, patient_id, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  5669. service.ModfiyAddDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  5670. }
  5671. }
  5672. //查询剩余库存
  5673. goodList, _ := service.GetNewAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo, tx)
  5674. var sum_count int64
  5675. for _, item := range goodList {
  5676. sum_count += item.StockCount
  5677. }
  5678. //更新剩余库存
  5679. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id, sum_count, tx)
  5680. //耗材
  5681. service.UpdateNewGoodSumCountSeven(sum_count, item.GoodId, adminInfo.Org.Id, tx)
  5682. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5683. c.ServeSuccessJSON(map[string]interface{}{
  5684. "message": "1",
  5685. "good_name": goodObj.GoodName,
  5686. "specification_name": goodObj.SpecificationName,
  5687. })
  5688. return
  5689. }
  5690. }
  5691. var errs error
  5692. if errs == nil {
  5693. c.ServeSuccessJSON(map[string]interface{}{
  5694. "msg": "提交成功",
  5695. "message": "2",
  5696. "good_name": "",
  5697. "specification_name": "",
  5698. })
  5699. return
  5700. } else {
  5701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5702. return
  5703. }
  5704. }
  5705. }
  5706. func (c *DialysisAPIController) CreateStockOutInfo() {
  5707. patient_id, _ := c.GetInt64("patient_id", 0)
  5708. record_date := c.GetString("record_time")
  5709. if patient_id <= 0 {
  5710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5711. return
  5712. }
  5713. adminInfo := c.GetMobileAdminUserInfo()
  5714. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5715. timeLayout := "2006-01-02"
  5716. loc, _ := time.LoadLocation("Local")
  5717. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5718. record_time := theRecordTime.Unix()
  5719. // 查询信息规挡的设置天数
  5720. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5721. if infor.ID > 0 && infor.WeekDay > 0 {
  5722. var cha_time int64
  5723. timeNowStr := time.Now().Format("2006-01-02")
  5724. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5725. //今日的日期减去设置的日期
  5726. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5727. if cha_time >= record_time {
  5728. //查询审核是否允许
  5729. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5730. //申请状态不允许的情况 拒绝修改
  5731. if infor.ApplicationStatus != 1 {
  5732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5733. return
  5734. }
  5735. }
  5736. }
  5737. //创建步骤表
  5738. finish := models.XtDialysisFinish{
  5739. IsFinish: 1,
  5740. UserOrgId: adminInfo.Org.Id,
  5741. Status: 1,
  5742. Ctime: time.Now().Unix(),
  5743. Mtime: 0,
  5744. Module: 11,
  5745. RecordDate: record_time,
  5746. Sourse: 1,
  5747. PatientId: patient_id,
  5748. }
  5749. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5750. if dialysisFinish.ID == 0 {
  5751. service.CreateDialysisFinish(finish)
  5752. }
  5753. dataBody := make(map[string]interface{}, 0)
  5754. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5755. if err != nil {
  5756. utils.ErrorLog(err.Error())
  5757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5758. return
  5759. }
  5760. var consumables []*models.DialysisBeforePrepare
  5761. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5762. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5763. goods, _ := dataBody["goods"].([]interface{})
  5764. if len(goods) > 0 {
  5765. for _, item := range goods {
  5766. items := item.(map[string]interface{})
  5767. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5768. utils.ErrorLog("good_id")
  5769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5770. return
  5771. }
  5772. good_id := int64(items["good_id"].(float64))
  5773. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5774. utils.ErrorLog("good_type_id")
  5775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5776. return
  5777. }
  5778. good_type_id := int64(items["good_type_id"].(float64))
  5779. if items["new_count"] == nil || reflect.TypeOf(items["new_count"]).String() != "float64" {
  5780. utils.ErrorLog("new_count")
  5781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5782. return
  5783. }
  5784. count := int64(items["new_count"].(float64))
  5785. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  5786. utils.ErrorLog("project_id")
  5787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5788. return
  5789. }
  5790. project_id := int64(items["project_id"].(float64))
  5791. prepare := &models.DialysisBeforePrepare{
  5792. GoodTypeId: good_type_id,
  5793. GoodId: good_id,
  5794. Count: count,
  5795. PatientId: patient_id,
  5796. RecordDate: record_time,
  5797. UserOrgId: adminInfo.Org.Id,
  5798. Status: 1,
  5799. Ctime: time.Now().Unix(),
  5800. Creater: adminInfo.AdminUser.Id,
  5801. StorehouseId: houseConfig.StorehouseOutInfo,
  5802. ProjectId: project_id,
  5803. }
  5804. consumables = append(consumables, prepare)
  5805. }
  5806. }
  5807. }
  5808. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5809. if record.IsOpen == 1 {
  5810. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5811. //查询是否有库存
  5812. for _, item := range consumables {
  5813. good, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5814. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, good.GoodTypeId, houseConfig.StorehouseOutInfo)
  5815. if item.Count > warehouse.Count {
  5816. goodErrcode := models.XtGoodErrcode{
  5817. UserOrgId: item.UserOrgId,
  5818. Errcode: "自动出库库存不足",
  5819. GoodId: item.ProjectId,
  5820. Status: 1,
  5821. Ctime: time.Now().Unix(),
  5822. Mtime: 0,
  5823. Count: 0,
  5824. StockCount: 0,
  5825. Creater: creator,
  5826. BatchNumberId: warehouse.ID,
  5827. WarehouseOutId: 0,
  5828. }
  5829. service.CreateGoodErrcode(goodErrcode)
  5830. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5831. c.ServeSuccessJSON(map[string]interface{}{
  5832. "message": "1",
  5833. "good_name": goodObj.GoodName,
  5834. "specification_name": goodObj.SpecificationName,
  5835. })
  5836. return
  5837. }
  5838. }
  5839. //查询是否有出库单
  5840. _, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5841. if err == gorm.ErrRecordNotFound {
  5842. //没有记录,则创建出库单
  5843. timeStr := time.Now().Format("2006-01-02")
  5844. timeArr := strings.Split(timeStr, "-")
  5845. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5846. total = total + 1
  5847. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5848. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5849. number = number + total
  5850. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5851. creater := adminInfo.AdminUser.Id
  5852. warehouseOut := models.WarehouseOut{
  5853. WarehouseOutOrderNumber: warehousing_out_order,
  5854. OperationTime: time.Now().Unix(),
  5855. OrgId: adminInfo.Org.Id,
  5856. Creater: creater,
  5857. Ctime: time.Now().Unix(),
  5858. Status: 1,
  5859. WarehouseOutTime: record_time,
  5860. Dealer: 0,
  5861. Manufacturer: 0,
  5862. Type: 1,
  5863. IsSys: 1,
  5864. StorehouseId: houseConfig.StorehouseOutInfo,
  5865. IsCheck: 1,
  5866. }
  5867. err := service.AddSigleWarehouseOut(&warehouseOut)
  5868. if err != nil {
  5869. goodErrcode := models.XtGoodErrcode{
  5870. UserOrgId: adminInfo.Org.Id,
  5871. Errcode: "创建出库单失败",
  5872. GoodId: 0,
  5873. Status: 1,
  5874. Ctime: time.Now().Unix(),
  5875. Mtime: 0,
  5876. Count: 0,
  5877. StockCount: 0,
  5878. Creater: creator,
  5879. BatchNumberId: 0,
  5880. WarehouseOutId: 0,
  5881. }
  5882. service.CreateGoodErrcode(goodErrcode)
  5883. utils.TraceLog("创建出库单失败 err = %v", err)
  5884. } else {
  5885. db := service.XTWriteDB()
  5886. tx := db.Begin()
  5887. // 在函数结束时处理事务回滚
  5888. defer func() {
  5889. if r := recover(); r != nil {
  5890. tx.Rollback()
  5891. } else {
  5892. tx.Commit()
  5893. }
  5894. }()
  5895. for _, item := range consumables {
  5896. //出库
  5897. if item.Count > 0 {
  5898. timeStr := time.Now().Format("2006-01-02")
  5899. timeArr := strings.Split(timeStr, "-")
  5900. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5901. total = total + 1
  5902. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5903. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5904. number = number + total
  5905. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5906. operation_time := time.Now().Unix()
  5907. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5908. recordDateStr := time.Now().Format("2006-01-02")
  5909. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5910. nowtime := recordDate.Unix()
  5911. //查询默认出库仓库库存
  5912. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5913. warehouseOut := models.WarehouseOut{
  5914. WarehouseOutOrderNumber: warehousing_out_order,
  5915. OperationTime: operation_time,
  5916. OrgId: adminInfo.Org.Id,
  5917. Creater: creater,
  5918. Ctime: time.Now().Unix(),
  5919. Status: 1,
  5920. WarehouseOutTime: nowtime,
  5921. Type: 1,
  5922. StorehouseId: storeConfig.StorehouseOutInfo,
  5923. IsCheck: 1,
  5924. IsSys: 1,
  5925. }
  5926. //查询是否生成出库单
  5927. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  5928. if out.ID == 0 {
  5929. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  5930. }
  5931. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  5932. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  5933. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  5934. dialyPrepareOne := models.DialysisBeforePrepare{
  5935. GoodTypeId: goodObj.GoodTypeId,
  5936. GoodId: item.GoodId,
  5937. PatientId: patient_id,
  5938. RecordDate: record_time,
  5939. UserOrgId: adminInfo.Org.Id,
  5940. Count: item.Count,
  5941. Ctime: time.Now().Unix(),
  5942. Creater: creater,
  5943. Status: 1,
  5944. StorehouseId: houseConfig.StorehouseOutInfo,
  5945. ProjectId: item.ProjectId,
  5946. }
  5947. //出库
  5948. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, item.PatientId, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  5949. if err == nil {
  5950. goodErrcode := models.XtGoodErrcode{
  5951. UserOrgId: adminInfo.Org.Id,
  5952. Errcode: "自动出库接口报错",
  5953. GoodId: 0,
  5954. Status: 1,
  5955. Ctime: time.Now().Unix(),
  5956. Mtime: 0,
  5957. Count: 0,
  5958. StockCount: 0,
  5959. Creater: creator,
  5960. BatchNumberId: 0,
  5961. WarehouseOutId: 0,
  5962. }
  5963. service.CreateGoodErrcode(goodErrcode)
  5964. utils.TraceLog("创建出库单失败 err = %v", err)
  5965. }
  5966. //添加
  5967. service.ModfiyAddDialysisAuto(item.PatientId, record_time, item.Count, item.GoodId, tx)
  5968. }
  5969. //退库
  5970. if item.Count < 0 {
  5971. count := math.Abs(float64(item.Count))
  5972. item.Count = int64(count)
  5973. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  5974. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5975. newPrescriptionProject := &models.HisPrescriptionProject{
  5976. ID: item.ProjectId,
  5977. ProjectId: item.GoodId,
  5978. UserOrgId: adminInfo.Org.Id,
  5979. Status: 1,
  5980. Ctime: time.Now().Unix(),
  5981. Mtime: time.Now().Unix(),
  5982. PatientId: patient_id,
  5983. RecordDate: record_time,
  5984. }
  5985. fmt.Println("item.Count---------------------------------------", item.Count)
  5986. service.NewMobileHisGoodCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, item.Count, goodObj, tx)
  5987. service.NewMobileHisGoodAutoCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, item.Count, goodObj, tx)
  5988. //减少
  5989. service.ModfiyReduceDialysisAuto(item.PatientId, record_time, item.Count, item.GoodId, tx)
  5990. }
  5991. //查询剩余库存
  5992. goodList, _ := service.GetNewAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo, tx)
  5993. var sum_count int64
  5994. for _, item := range goodList {
  5995. sum_count += item.StockCount
  5996. }
  5997. //更新剩余库存
  5998. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id, sum_count, tx)
  5999. //耗材
  6000. service.UpdateNewGoodSumCountSeven(sum_count, item.GoodId, adminInfo.Org.Id, tx)
  6001. }
  6002. }
  6003. //
  6004. } else if err == nil {
  6005. for _, item := range consumables {
  6006. db := service.XTWriteDB()
  6007. tx := db.Begin()
  6008. // 在函数结束时处理事务回滚
  6009. defer func() {
  6010. if r := recover(); r != nil {
  6011. tx.Rollback()
  6012. } else {
  6013. tx.Commit()
  6014. }
  6015. }()
  6016. //出库
  6017. if item.Count > 0 {
  6018. timeStr := time.Now().Format("2006-01-02")
  6019. timeArr := strings.Split(timeStr, "-")
  6020. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6021. total = total + 1
  6022. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6023. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6024. number = number + total
  6025. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6026. operation_time := time.Now().Unix()
  6027. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6028. recordDateStr := time.Now().Format("2006-01-02")
  6029. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6030. nowtime := recordDate.Unix()
  6031. //查询默认出库仓库库存
  6032. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6033. warehouseOut := models.WarehouseOut{
  6034. WarehouseOutOrderNumber: warehousing_out_order,
  6035. OperationTime: operation_time,
  6036. OrgId: adminInfo.Org.Id,
  6037. Creater: creater,
  6038. Ctime: time.Now().Unix(),
  6039. Status: 1,
  6040. WarehouseOutTime: nowtime,
  6041. Type: 1,
  6042. StorehouseId: storeConfig.StorehouseOutInfo,
  6043. IsCheck: 1,
  6044. IsSys: 1,
  6045. }
  6046. //查询是否生成出库单
  6047. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  6048. if out.ID == 0 {
  6049. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  6050. }
  6051. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  6052. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  6053. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  6054. dialyPrepareOne := models.DialysisBeforePrepare{
  6055. GoodTypeId: goodObj.GoodTypeId,
  6056. GoodId: item.GoodId,
  6057. PatientId: patient_id,
  6058. RecordDate: record_time,
  6059. UserOrgId: adminInfo.Org.Id,
  6060. Count: item.Count,
  6061. Ctime: time.Now().Unix(),
  6062. Creater: creater,
  6063. Status: 1,
  6064. StorehouseId: houseConfig.StorehouseOutInfo,
  6065. ProjectId: item.ProjectId,
  6066. }
  6067. //出库
  6068. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, item.PatientId, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  6069. if err == nil {
  6070. goodErrcode := models.XtGoodErrcode{
  6071. UserOrgId: adminInfo.Org.Id,
  6072. Errcode: "自动出库接口报错",
  6073. GoodId: 0,
  6074. Status: 1,
  6075. Ctime: time.Now().Unix(),
  6076. Mtime: 0,
  6077. Count: 0,
  6078. StockCount: 0,
  6079. Creater: creator,
  6080. BatchNumberId: 0,
  6081. WarehouseOutId: 0,
  6082. }
  6083. service.CreateGoodErrcode(goodErrcode)
  6084. utils.TraceLog("创建出库单失败 err = %v", err)
  6085. }
  6086. //减少
  6087. service.ModfiyAddDialysisAuto(item.PatientId, record_time, item.Count, item.GoodId, tx)
  6088. }
  6089. //退库
  6090. if item.Count < 0 {
  6091. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  6092. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6093. count := math.Abs(float64(item.Count))
  6094. item.Count = int64(count)
  6095. fmt.Println("item.Count---------------------------------------", item.Count)
  6096. fmt.Println("item.GoodId-----------------------------------", item.GoodId)
  6097. newPrescriptionProject := &models.HisPrescriptionProject{
  6098. ID: item.ProjectId,
  6099. ProjectId: item.GoodId,
  6100. UserOrgId: adminInfo.Org.Id,
  6101. Status: 1,
  6102. Ctime: time.Now().Unix(),
  6103. Mtime: time.Now().Unix(),
  6104. PatientId: item.PatientId,
  6105. RecordDate: record_time,
  6106. Count: strconv.FormatInt(item.Count, 10),
  6107. }
  6108. service.NewMobileHisGoodCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, item.Count, goodObj, tx)
  6109. service.NewMobileHisGoodAutoCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, item.Count, goodObj, tx)
  6110. //减少
  6111. service.ModfiyReduceDialysisAuto(item.PatientId, record_time, item.Count, item.GoodId, tx)
  6112. }
  6113. //查询剩余库存
  6114. goodList, _ := service.GetNewAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo, tx)
  6115. var sum_count int64
  6116. for _, item := range goodList {
  6117. sum_count += item.StockCount
  6118. }
  6119. //更新剩余库存
  6120. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id, sum_count, tx)
  6121. //耗材
  6122. service.UpdateNewGoodSumCountSeven(sum_count, item.GoodId, adminInfo.Org.Id, tx)
  6123. }
  6124. }
  6125. c.ServeSuccessJSON(map[string]interface{}{
  6126. "msg": "提交成功",
  6127. "message": "2",
  6128. "good_name": "",
  6129. "specification_name": "",
  6130. })
  6131. return
  6132. } else {
  6133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6134. return
  6135. }
  6136. }
  6137. func (c *DialysisAPIController) EditConsumables() {
  6138. patient_id, _ := c.GetInt64("patient_id", 0)
  6139. record_date := c.GetString("record_time")
  6140. if patient_id <= 0 {
  6141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6142. return
  6143. }
  6144. adminInfo := c.GetMobileAdminUserInfo()
  6145. timeLayout := "2006-01-02"
  6146. loc, _ := time.LoadLocation("Local")
  6147. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6148. record_time := theRecordTime.Unix()
  6149. // 查询信息规挡的设置天数
  6150. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6151. if infor.ID > 0 && infor.WeekDay > 0 {
  6152. var cha_time int64
  6153. timeNowStr := time.Now().Format("2006-01-02")
  6154. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6155. //今日的日期减去设置的日期
  6156. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6157. if cha_time >= record_time {
  6158. //查询审核是否允许
  6159. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6160. //申请状态不允许的情况 拒绝修改
  6161. if infor.ApplicationStatus != 1 {
  6162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6163. return
  6164. }
  6165. }
  6166. }
  6167. dataBody := make(map[string]interface{}, 0)
  6168. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6169. if err != nil {
  6170. utils.ErrorLog(err.Error())
  6171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6172. return
  6173. }
  6174. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6175. var beforePrepares []*models.DialysisBeforePrepareGoods
  6176. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6177. //判断是否开启自动出库
  6178. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6179. fmt.Println("record.IsOpen====================================", record)
  6180. if record.IsOpen == 1 {
  6181. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6182. goods, _ := dataBody["goods"].([]interface{})
  6183. if len(goods) > 0 {
  6184. for _, item := range goods {
  6185. items := item.(map[string]interface{})
  6186. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6187. utils.ErrorLog("good_id")
  6188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6189. return
  6190. }
  6191. good_id := int64(items["good_id"].(float64))
  6192. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6193. utils.ErrorLog("good_type_id")
  6194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6195. return
  6196. }
  6197. good_type_id := int64(items["good_type_id"].(float64))
  6198. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6199. utils.ErrorLog("count")
  6200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6201. return
  6202. }
  6203. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6204. commdity_code := items["commdity_code"].(string)
  6205. fmt.Println(commdity_code)
  6206. prepareGoods := &models.DialysisBeforePrepareGoods{
  6207. GoodTypeId: good_type_id,
  6208. GoodId: good_id,
  6209. Count: count,
  6210. StorehouseId: houseConfig.StorehouseOutInfo,
  6211. PatientId: patient_id,
  6212. }
  6213. beforePrepares = append(beforePrepares, prepareGoods)
  6214. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6215. GoodTypeId: good_type_id,
  6216. GoodId: good_id,
  6217. Count: count,
  6218. StorehouseId: houseConfig.StorehouseOutInfo,
  6219. PatientId: patient_id,
  6220. }
  6221. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6222. }
  6223. db := service.XTWriteDB()
  6224. tx := db.Begin()
  6225. // 在函数结束时处理事务回滚
  6226. defer func() {
  6227. if r := recover(); r != nil {
  6228. tx.Rollback()
  6229. } else {
  6230. tx.Commit()
  6231. }
  6232. }()
  6233. for _, item := range newBeforePrepares {
  6234. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6235. var his_count int64
  6236. //查询该耗材今日出库了多少
  6237. outInfo, _ := service.GetHistoryWarehouseOutInfo(item.PatientId, adminInfo.Org.Id, record_time, item.GoodId, tx)
  6238. fmt.Println("outInfo---------------------------------------", outInfo)
  6239. for _, it := range outInfo {
  6240. his_count += it.Count
  6241. }
  6242. if item.Count > his_count {
  6243. //如果当前出库数据 大于历史出库数据,那么需要出库
  6244. var cha_count int64
  6245. cha_count = item.Count - his_count
  6246. timeStr := time.Now().Format("2006-01-02")
  6247. timeArr := strings.Split(timeStr, "-")
  6248. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6249. total = total + 1
  6250. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6251. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6252. number = number + total
  6253. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6254. operation_time := time.Now().Unix()
  6255. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6256. recordDateStr := time.Now().Format("2006-01-02")
  6257. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6258. nowtime := recordDate.Unix()
  6259. //查询默认出库仓库库存
  6260. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6261. warehouseOut := models.WarehouseOut{
  6262. WarehouseOutOrderNumber: warehousing_out_order,
  6263. OperationTime: operation_time,
  6264. OrgId: adminInfo.Org.Id,
  6265. Creater: creater,
  6266. Ctime: time.Now().Unix(),
  6267. Status: 1,
  6268. WarehouseOutTime: nowtime,
  6269. Type: 1,
  6270. StorehouseId: storeConfig.StorehouseOutInfo,
  6271. IsCheck: 1,
  6272. IsSys: 1,
  6273. }
  6274. //查询是否生成出库单
  6275. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  6276. if out.ID == 0 {
  6277. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  6278. }
  6279. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  6280. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  6281. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  6282. dialyPrepareOne := models.DialysisBeforePrepare{
  6283. GoodTypeId: goodObj.GoodTypeId,
  6284. GoodId: item.GoodId,
  6285. PatientId: item.PatientId,
  6286. RecordDate: record_time,
  6287. UserOrgId: adminInfo.Org.Id,
  6288. Count: cha_count,
  6289. Ctime: time.Now().Unix(),
  6290. Creater: creater,
  6291. Status: 1,
  6292. StorehouseId: houseConfig.StorehouseOutInfo,
  6293. ProjectId: item.ProjectId,
  6294. }
  6295. //出库
  6296. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, item.PatientId, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  6297. if err == nil {
  6298. goodErrcode := models.XtGoodErrcode{
  6299. UserOrgId: adminInfo.Org.Id,
  6300. Errcode: "自动出库接口报错",
  6301. GoodId: 0,
  6302. Status: 1,
  6303. Ctime: time.Now().Unix(),
  6304. Mtime: 0,
  6305. Count: 0,
  6306. StockCount: 0,
  6307. Creater: creator,
  6308. BatchNumberId: 0,
  6309. WarehouseOutId: 0,
  6310. }
  6311. service.CreateGoodErrcode(goodErrcode)
  6312. utils.TraceLog("创建出库单失败 err = %v", err)
  6313. }
  6314. service.ModfiyAddDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  6315. }
  6316. if item.Count < his_count {
  6317. var cha_count int64
  6318. cha_count = his_count - item.Count
  6319. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  6320. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6321. newPrescriptionProject := &models.HisPrescriptionProject{
  6322. ID: item.ProjectId,
  6323. ProjectId: item.GoodId,
  6324. UserOrgId: adminInfo.Org.Id,
  6325. Status: 1,
  6326. Ctime: time.Now().Unix(),
  6327. Mtime: time.Now().Unix(),
  6328. PatientId: item.PatientId,
  6329. RecordDate: record_time,
  6330. }
  6331. service.NewMobileHisGoodCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, cha_count, goodObj, tx)
  6332. service.NewMobileHisGoodAutoCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, cha_count, goodObj, tx)
  6333. service.ModfiyReduceDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  6334. }
  6335. if item.Count == his_count {
  6336. if his_count == 0 {
  6337. recordDateStr := time.Now().Format("2006-01-02")
  6338. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6339. nowtime := recordDate.Unix()
  6340. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  6341. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  6342. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  6343. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6344. dialyPrepareOne := models.DialysisBeforePrepare{
  6345. GoodTypeId: goodObj.GoodTypeId,
  6346. GoodId: item.GoodId,
  6347. PatientId: item.PatientId,
  6348. RecordDate: record_time,
  6349. UserOrgId: adminInfo.Org.Id,
  6350. Count: item.Count,
  6351. Ctime: time.Now().Unix(),
  6352. Creater: creater,
  6353. Status: 1,
  6354. StorehouseId: houseConfig.StorehouseOutInfo,
  6355. ProjectId: item.ProjectId,
  6356. }
  6357. //出库
  6358. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, patient_id, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  6359. service.ModfiyAddDialysisAuto(item.PatientId, item.RecordDate, item.Count, item.GoodId, tx)
  6360. }
  6361. }
  6362. //查询剩余库存
  6363. goodList, _ := service.GetNewAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo, tx)
  6364. var sum_count int64
  6365. for _, item := range goodList {
  6366. sum_count += item.StockCount
  6367. }
  6368. //更新剩余库存
  6369. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id, sum_count, tx)
  6370. //耗材
  6371. service.UpdateNewGoodSumCountSeven(sum_count, item.GoodId, adminInfo.Org.Id, tx)
  6372. }
  6373. }
  6374. }
  6375. //更新自动出库的地方
  6376. var errs error
  6377. if errs == nil {
  6378. c.ServeSuccessJSON(map[string]interface{}{
  6379. "msg": "修改成功",
  6380. "message": "2",
  6381. "good_name": "",
  6382. "specification_name": "",
  6383. })
  6384. return
  6385. } else {
  6386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6387. return
  6388. }
  6389. }
  6390. }
  6391. func (c *DialysisAPIController) GetDialysisGoods() {
  6392. schedualDate := c.GetString("schedule_date")
  6393. schedule_type, _ := c.GetInt64("schedule_type")
  6394. partition_id, _ := c.GetInt64("partition_id")
  6395. page, _ := c.GetInt("page")
  6396. patient_id, _ := c.GetInt64("patient_id")
  6397. schedualEndDate := int64(0)
  6398. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6399. if parseDateErr != nil && len(schedualDate) != 0 {
  6400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6401. return
  6402. }
  6403. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  6404. if parseDateErr != nil && len(schedualDate) != 0 {
  6405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6406. return
  6407. }
  6408. schedualEndDate = endDate.Unix()
  6409. adminUser := c.GetMobileAdminUserInfo()
  6410. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  6411. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  6412. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6413. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6414. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  6415. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  6416. //获取当天该病人的透析处方
  6417. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6418. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6419. if err == gorm.ErrRecordNotFound {
  6420. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6421. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6422. if patient_id != 0 {
  6423. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6424. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6425. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6426. //获取患者总的出库数据
  6427. item.LastAutomaticReduceDetail = goodUser
  6428. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6429. item.Project = project
  6430. for _, it := range item.AutomaticReduceDetail {
  6431. var total int64
  6432. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  6433. for _, its := range auto {
  6434. total += its.Count
  6435. }
  6436. it.Count = total
  6437. }
  6438. }
  6439. }
  6440. c.ServeSuccessJSON(map[string]interface{}{
  6441. "dialysis_goods": dialysisGoods,
  6442. "good_type": goodTypes,
  6443. "total": total,
  6444. "prescribe": prescribe,
  6445. "good_info": good_info,
  6446. "warehouseOutList": warehouseOutList,
  6447. "config": config,
  6448. "outConfig": outConfig,
  6449. "settleConfig": settleConfig,
  6450. })
  6451. return
  6452. } else if err == nil {
  6453. //获取当天排班的每个患者的库存使用情况
  6454. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6455. //获取患者总的出库数据
  6456. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6457. if patient_id != 0 {
  6458. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6459. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6460. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6461. item.Project = project
  6462. item.LastAutomaticReduceDetail = goodUser
  6463. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6464. for _, it := range item.AutomaticReduceDetail {
  6465. var total int64
  6466. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  6467. for _, its := range auto {
  6468. total += its.Count
  6469. }
  6470. it.Count = total
  6471. }
  6472. }
  6473. }
  6474. if err == nil {
  6475. c.ServeSuccessJSON(map[string]interface{}{
  6476. "dialysis_goods": dialysisGoods,
  6477. "good_type": goodTypes,
  6478. "total": total,
  6479. "prescribe": prescribe,
  6480. "good_info": good_info,
  6481. "project": project,
  6482. "warehouseOutList": warehouseOutList,
  6483. "config": config,
  6484. "outConfig": outConfig,
  6485. "settleConfig": settleConfig,
  6486. })
  6487. return
  6488. } else {
  6489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6490. return
  6491. }
  6492. } else if err != nil {
  6493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6494. return
  6495. }
  6496. }
  6497. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  6498. start_time := c.GetString("start_time")
  6499. end_time := c.GetString("end_time")
  6500. timeLayout := "2006-01-02"
  6501. loc, _ := time.LoadLocation("Local")
  6502. var theStartTime int64
  6503. if len(start_time) > 0 {
  6504. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6505. if err != nil {
  6506. utils.ErrorLog(err.Error())
  6507. }
  6508. theStartTime = theTime.Unix()
  6509. }
  6510. var theEndtTime int64
  6511. if len(end_time) > 0 {
  6512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6513. if err != nil {
  6514. utils.ErrorLog(err.Error())
  6515. }
  6516. theEndtTime = theTime.Unix()
  6517. }
  6518. adminUser := c.GetMobileAdminUserInfo()
  6519. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  6520. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  6521. if err == nil {
  6522. c.ServeSuccessJSON(map[string]interface{}{
  6523. "stock_out": outInfo,
  6524. "stockCount": stockCount,
  6525. })
  6526. return
  6527. } else {
  6528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6529. return
  6530. }
  6531. }
  6532. func (c *DialysisAPIController) GetStockInGoodInfo() {
  6533. patient_id, _ := c.GetInt64("patient_id", 0)
  6534. record_time := c.GetString("record_time")
  6535. adminUser := c.GetMobileAdminUserInfo()
  6536. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  6537. if parseDateErr != nil && len(record_time) != 0 {
  6538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6539. return
  6540. }
  6541. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  6542. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6543. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  6544. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  6545. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6546. //获取今日患者的透析处方参数
  6547. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6548. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  6549. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6550. c.ServeSuccessJSON(map[string]interface{}{
  6551. "good_type": goodTypes,
  6552. "good_user": goodUser,
  6553. "good_info": good_info,
  6554. "last_good_user": lastGoodUserDetial,
  6555. "project": project,
  6556. "prescription": prescribe,
  6557. "outInfo": outInfo,
  6558. "configs": configs,
  6559. })
  6560. return
  6561. }
  6562. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  6563. patient_id, _ := c.GetInt64("patient_id", 0)
  6564. record_date := c.GetString("record_time")
  6565. timeLayout := "2006-01-02"
  6566. loc, _ := time.LoadLocation("Local")
  6567. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6568. record_time := theRecordTime.Unix()
  6569. adminInfo := c.GetMobileAdminUserInfo()
  6570. dataBody := make(map[string]interface{}, 0)
  6571. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6572. if err != nil {
  6573. utils.ErrorLog(err.Error())
  6574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6575. return
  6576. }
  6577. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6578. var beforePrepares []*models.DialysisBeforePrepareGoods
  6579. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6580. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6581. goods, _ := dataBody["goods"].([]interface{})
  6582. if len(goods) > 0 {
  6583. for _, item := range goods {
  6584. items := item.(map[string]interface{})
  6585. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6586. utils.ErrorLog("good_id")
  6587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6588. return
  6589. }
  6590. good_id := int64(items["good_id"].(float64))
  6591. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6592. utils.ErrorLog("good_type_id")
  6593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6594. return
  6595. }
  6596. good_type_id := int64(items["good_type_id"].(float64))
  6597. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6598. utils.ErrorLog("count")
  6599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6600. return
  6601. }
  6602. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6603. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  6604. utils.ErrorLog("project_id")
  6605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6606. return
  6607. }
  6608. project_id := int64(items["project_id"].(float64))
  6609. new_count := int64(items["new_count"].(float64))
  6610. old_count := int64(items["old_count"].(float64))
  6611. prepare := &models.DialysisBeforePrepareGoods{
  6612. GoodId: good_id,
  6613. GoodTypeId: good_type_id,
  6614. Count: count,
  6615. ProjectId: project_id,
  6616. StorehouseId: houseConfig.StorehouseOutInfo,
  6617. NewCount: new_count,
  6618. OldCount: old_count,
  6619. PatientId: patient_id,
  6620. }
  6621. beforePrepares = append(beforePrepares, prepare)
  6622. newPrepare := &models.NewDialysisBeforePrepareGoods{
  6623. GoodId: good_id,
  6624. GoodTypeId: good_type_id,
  6625. Count: count,
  6626. ProjectId: project_id,
  6627. StorehouseId: houseConfig.StorehouseOutInfo,
  6628. NewCount: new_count,
  6629. OldCount: old_count,
  6630. PatientId: patient_id,
  6631. RecordDate: record_time,
  6632. }
  6633. newBeforePrepares = append(newBeforePrepares, newPrepare)
  6634. }
  6635. }
  6636. }
  6637. //查询是否有库存
  6638. for _, item := range beforePrepares {
  6639. if item.NewCount > 0 {
  6640. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6641. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  6642. if item.Count > warehouse.Count {
  6643. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6644. c.ServeSuccessJSON(map[string]interface{}{
  6645. "message": "1",
  6646. "good_name": goodObj.GoodName,
  6647. "specification_name": goodObj.SpecificationName,
  6648. })
  6649. return
  6650. }
  6651. }
  6652. }
  6653. // 查询信息规挡的设置天数
  6654. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6655. if infor.ID > 0 && infor.WeekDay > 0 {
  6656. var cha_time int64
  6657. timeNowStr := time.Now().Format("2006-01-02")
  6658. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6659. //今日的日期减去设置的日期
  6660. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6661. if cha_time >= record_time {
  6662. //查询审核是否允许
  6663. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6664. //申请状态不允许的情况 拒绝修改
  6665. if infor.ApplicationStatus != 1 {
  6666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6667. return
  6668. }
  6669. }
  6670. }
  6671. db := service.XTWriteDB()
  6672. tx := db.Begin()
  6673. // 在函数结束时处理事务回滚
  6674. defer func() {
  6675. if r := recover(); r != nil {
  6676. tx.Rollback()
  6677. } else {
  6678. tx.Commit()
  6679. }
  6680. }()
  6681. for _, item := range beforePrepares {
  6682. var his_count int64
  6683. //查询该耗材今日出库了多少
  6684. outInfo, _ := service.GetHistoryWarehouseOutInfo(patient_id, adminInfo.Org.Id, record_time, item.GoodId, tx)
  6685. for _, it := range outInfo {
  6686. his_count += it.Count
  6687. }
  6688. //如果当前出库数据 大于历史出库数据,那么需要出库
  6689. if item.Count > his_count {
  6690. var cha_count int64
  6691. cha_count = item.Count - his_count
  6692. timeStr := time.Now().Format("2006-01-02")
  6693. timeArr := strings.Split(timeStr, "-")
  6694. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6695. total = total + 1
  6696. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6697. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6698. number = number + total
  6699. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6700. operation_time := time.Now().Unix()
  6701. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6702. recordDateStr := time.Now().Format("2006-01-02")
  6703. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6704. nowtime := recordDate.Unix()
  6705. //查询默认出库仓库库存
  6706. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6707. warehouseOut := models.WarehouseOut{
  6708. WarehouseOutOrderNumber: warehousing_out_order,
  6709. OperationTime: operation_time,
  6710. OrgId: adminInfo.Org.Id,
  6711. Creater: creater,
  6712. Ctime: time.Now().Unix(),
  6713. Status: 1,
  6714. WarehouseOutTime: nowtime,
  6715. Type: 1,
  6716. StorehouseId: storeConfig.StorehouseOutInfo,
  6717. IsCheck: 1,
  6718. IsSys: 1,
  6719. }
  6720. //查询是否生成出库单
  6721. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  6722. if out.ID == 0 {
  6723. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  6724. }
  6725. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  6726. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  6727. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  6728. dialyPrepareOne := models.DialysisBeforePrepare{
  6729. GoodTypeId: goodObj.GoodTypeId,
  6730. GoodId: item.GoodId,
  6731. PatientId: item.PatientId,
  6732. RecordDate: record_time,
  6733. UserOrgId: adminInfo.Org.Id,
  6734. Count: cha_count,
  6735. Ctime: time.Now().Unix(),
  6736. Creater: creater,
  6737. Status: 1,
  6738. StorehouseId: houseConfig.StorehouseOutInfo,
  6739. ProjectId: item.ProjectId,
  6740. }
  6741. //出库
  6742. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, patient_id, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  6743. }
  6744. //如果当前出库数据 大于历史出库数据,则需要退库
  6745. if item.Count < his_count {
  6746. var cha_count int64
  6747. cha_count = his_count - item.Count
  6748. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.ProjectId, tx)
  6749. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6750. newPrescriptionProject := &models.HisPrescriptionProject{
  6751. ID: item.ProjectId,
  6752. ProjectId: item.GoodId,
  6753. UserOrgId: adminInfo.Org.Id,
  6754. Status: 1,
  6755. Ctime: time.Now().Unix(),
  6756. Mtime: time.Now().Unix(),
  6757. PatientId: item.PatientId,
  6758. RecordDate: record_time,
  6759. Count: strconv.FormatInt(item.Count, 10),
  6760. }
  6761. service.NewMobileHisGoodCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, cha_count, goodObj, tx)
  6762. service.NewMobileHisGoodAutoCancelInfo(adminInfo.Org.Id, creater, newPrescriptionProject, cha_count, goodObj, tx)
  6763. }
  6764. if item.Count == his_count {
  6765. if his_count == 0 {
  6766. recordDateStr := time.Now().Format("2006-01-02")
  6767. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6768. nowtime := recordDate.Unix()
  6769. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.Org.Id, nowtime, tx)
  6770. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(item.GoodId, tx)
  6771. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  6772. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6773. dialyPrepareOne := models.DialysisBeforePrepare{
  6774. GoodTypeId: goodObj.GoodTypeId,
  6775. GoodId: item.GoodId,
  6776. PatientId: item.PatientId,
  6777. RecordDate: record_time,
  6778. UserOrgId: adminInfo.Org.Id,
  6779. Count: item.Count,
  6780. Ctime: time.Now().Unix(),
  6781. Creater: creater,
  6782. Status: 1,
  6783. StorehouseId: houseConfig.StorehouseOutInfo,
  6784. ProjectId: item.ProjectId,
  6785. }
  6786. //出库
  6787. service.ConsumableNewHisPrescriptionDelivery(adminInfo.Org.Id, patient_id, record_time, &dialyPrepareOne, &lastOut, creater, tx)
  6788. }
  6789. }
  6790. houseConfig, _ := service.GetNewAllStoreHouseConfig(adminInfo.Org.Id, tx)
  6791. //查询剩余库存
  6792. goodList, _ := service.GetNewAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo, tx)
  6793. var sum_count int64
  6794. for _, item := range goodList {
  6795. sum_count += item.StockCount
  6796. }
  6797. //更新剩余库存
  6798. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminInfo.Org.Id, sum_count, tx)
  6799. //耗材
  6800. service.UpdateNewGoodSumCountSeven(sum_count, item.GoodId, adminInfo.Org.Id, tx)
  6801. //查询总共出库了多少支
  6802. autoGoodInfo, _ := service.GetDialysisAutoGoodInfo(patient_id, record_time, adminInfo.Org.Id, tx, item.GoodId)
  6803. if len(autoGoodInfo) > 0 {
  6804. var out_count int64
  6805. for _, item := range autoGoodInfo {
  6806. out_count += item.Count
  6807. }
  6808. dialysisBeforePrepare := models.DialysisBeforePrepare{
  6809. UserOrgId: adminInfo.Org.Id,
  6810. PatientId: patient_id,
  6811. RecordDate: record_time,
  6812. GoodId: item.GoodId,
  6813. GoodTypeId: item.GoodTypeId,
  6814. Count: out_count,
  6815. Ctime: time.Now().Unix(),
  6816. Mtime: time.Now().Unix(),
  6817. Creater: adminInfo.AdminUser.Id,
  6818. Modifier: adminInfo.AdminUser.Id,
  6819. Status: 1,
  6820. CommdityCode: "",
  6821. NewCount: 0,
  6822. Children: nil,
  6823. ProjectId: item.ProjectId,
  6824. StorehouseId: houseConfig.StorehouseOutInfo,
  6825. }
  6826. service.CreateDialysisPrepare(dialysisBeforePrepare, tx)
  6827. }
  6828. }
  6829. finish := models.XtDialysisFinish{
  6830. IsFinish: 1,
  6831. UserOrgId: adminInfo.Org.Id,
  6832. Status: 1,
  6833. Ctime: time.Now().Unix(),
  6834. Mtime: 0,
  6835. Module: 11,
  6836. RecordDate: record_time,
  6837. Sourse: 1,
  6838. PatientId: patient_id,
  6839. }
  6840. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6841. if dialysisFinish.ID == 0 {
  6842. service.CreateDialysisFinish(finish)
  6843. }
  6844. //更新自动出库的地方
  6845. var errs error
  6846. if errs == nil {
  6847. c.ServeSuccessJSON(map[string]interface{}{
  6848. "msg": "修改成功",
  6849. "message": "2",
  6850. "good_name": "",
  6851. "specification_name": "",
  6852. })
  6853. return
  6854. } else {
  6855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6856. return
  6857. }
  6858. }
  6859. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  6860. newArr = make([]*models.DialysisBeforePrepare, 0)
  6861. for i := 0; i < len(arr); i++ {
  6862. repeat := false
  6863. for j := i + 1; j < len(arr); j++ {
  6864. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  6865. repeat = true
  6866. break
  6867. }
  6868. }
  6869. if !repeat {
  6870. newArr = append(newArr, arr[i])
  6871. }
  6872. }
  6873. return
  6874. }
  6875. func (c *DialysisAPIController) GetAllDrug() {
  6876. patient_id, _ := c.GetInt64("patient_id", 0)
  6877. adminInfo := c.GetMobileAdminUserInfo()
  6878. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6879. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  6880. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  6881. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  6882. c.ServeSuccessJSON(map[string]interface{}{
  6883. "base_drug_config": drugStockConfig,
  6884. "private_drug_config": privateDrugConfig,
  6885. "base_drug_list": drugList,
  6886. "private_drug_list": privateDrugList,
  6887. })
  6888. }
  6889. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  6890. newArr = make([]*models.DialysisBeforePrepare, 0)
  6891. for i := 0; i < len(arr); i++ {
  6892. repeat := false
  6893. for j := i + 1; j < len(arr); j++ {
  6894. if arr[i].GoodId == arr[j].GoodId {
  6895. repeat = true
  6896. break
  6897. }
  6898. }
  6899. if !repeat {
  6900. newArr = append(newArr, arr[i])
  6901. }
  6902. }
  6903. return
  6904. }
  6905. func (c *DialysisAPIController) GetDepartment() {
  6906. adminInfo := c.GetMobileAdminUserInfo()
  6907. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  6908. if err == nil {
  6909. c.ServeSuccessJSON(map[string]interface{}{
  6910. "departments": departments,
  6911. })
  6912. } else {
  6913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6914. return
  6915. }
  6916. }
  6917. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  6918. types, _ := c.GetInt("type", 0)
  6919. start_time := c.GetString("start_time")
  6920. end_time := c.GetString("end_time")
  6921. orgId := c.GetMobileAdminUserInfo().Org.Id
  6922. timeLayout := "2006-01-02"
  6923. loc, _ := time.LoadLocation("Local")
  6924. var startTime int64
  6925. if len(start_time) > 0 {
  6926. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6927. if err != nil {
  6928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6929. return
  6930. }
  6931. startTime = theTime.Unix()
  6932. }
  6933. var endTime int64
  6934. if len(end_time) > 0 {
  6935. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6936. if err != nil {
  6937. utils.ErrorLog(err.Error())
  6938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6939. return
  6940. }
  6941. endTime = theTime.Unix()
  6942. }
  6943. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  6944. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  6945. if err != nil {
  6946. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6947. } else {
  6948. c.ServeSuccessJSON(map[string]interface{}{
  6949. "list": list,
  6950. "type": types,
  6951. "stockTotal": stockTotal,
  6952. })
  6953. }
  6954. }
  6955. func (c *DialysisAPIController) GetPrescriptionList() {
  6956. start_time := c.GetString("start_time")
  6957. end_time := c.GetString("end_time")
  6958. schedule_type, _ := c.GetInt64("schedule_type")
  6959. partion_id, _ := c.GetInt64("partion_id")
  6960. orgId := c.GetMobileAdminUserInfo().Org.Id
  6961. timeLayout := "2006-01-02"
  6962. loc, _ := time.LoadLocation("Local")
  6963. var startTime int64
  6964. if len(start_time) > 0 {
  6965. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6966. if err != nil {
  6967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6968. return
  6969. }
  6970. startTime = theTime.Unix()
  6971. }
  6972. var endTime int64
  6973. if len(end_time) > 0 {
  6974. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6975. if err != nil {
  6976. utils.ErrorLog(err.Error())
  6977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6978. return
  6979. }
  6980. endTime = theTime.Unix()
  6981. }
  6982. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  6983. fmt.Println("schedulelist22222222", schedulelist)
  6984. c.ServeSuccessJSON(map[string]interface{}{
  6985. "list": schedulelist,
  6986. })
  6987. return
  6988. }
  6989. func (c *DialysisAPIController) BatchDeleteMonitor() {
  6990. ids := c.GetString("ids")
  6991. //patient_id, _ := c.GetInt64("patient_id")
  6992. //monitoring_date, _ := c.GetInt64("monitoring_date")
  6993. idArray := strings.Split(ids, ",")
  6994. err := service.BatchDeleteMonitor(idArray)
  6995. fmt.Print("err", err)
  6996. //orgid := c.GetMobileAdminUserInfo().Org.Id
  6997. //redis := service.RedisClient()
  6998. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  6999. //redis.Set(key, "", time.Second)
  7000. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7001. //redis.Set(keyOne, "", time.Second)
  7002. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7003. //redis.Close()
  7004. c.ServeSuccessJSON(map[string]interface{}{
  7005. "msg": "批量删除成功",
  7006. })
  7007. return
  7008. }
  7009. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7010. id, _ := c.GetInt64("id")
  7011. timeLayout := "2006-01-02"
  7012. loc, _ := time.LoadLocation("Local")
  7013. //start_time := time.Now().Format("2006-01-02")
  7014. start_time := c.GetString("start_time")
  7015. end_time := c.GetString("end_time")
  7016. var startdateunix int64
  7017. if len(start_time) > 0 {
  7018. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7019. if err != nil {
  7020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7021. return
  7022. }
  7023. startdateunix = theTime.Unix()
  7024. }
  7025. var enddateunix int64
  7026. if len(end_time) > 0 {
  7027. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7028. if err != nil {
  7029. utils.ErrorLog(err.Error())
  7030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7031. return
  7032. }
  7033. enddateunix = theTime.Unix()
  7034. }
  7035. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7036. //nowTime := time.Now()
  7037. //endTime := nowTime.AddDate(-30, 0, 0)
  7038. //endTimes := endTime.Format("2006-01-02")
  7039. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7040. org_id := c.GetMobileAdminUserInfo().Org.Id
  7041. //if org_id == 10579 {
  7042. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7043. // c.ServeSuccessJSON(map[string]interface{}{
  7044. // "list": list,
  7045. // })
  7046. // return
  7047. //} else {
  7048. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7049. // c.ServeSuccessJSON(map[string]interface{}{
  7050. // "list": list,
  7051. // })
  7052. // return
  7053. //}
  7054. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  7055. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7056. c.ServeSuccessJSON(map[string]interface{}{
  7057. "list": list,
  7058. })
  7059. return
  7060. } else {
  7061. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7062. c.ServeSuccessJSON(map[string]interface{}{
  7063. "list": list,
  7064. })
  7065. }
  7066. return
  7067. }
  7068. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7069. dataBody := make(map[string]interface{}, 0)
  7070. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7071. ids := c.GetString("ids")
  7072. idArray := strings.Split(ids, ",")
  7073. origin, _ := c.GetInt64("origin")
  7074. if origin == 1 {
  7075. err = service.BatchDeleteAdvice(idArray)
  7076. fmt.Print("err", err)
  7077. c.ServeSuccessJSON(map[string]interface{}{
  7078. "msg": "批量删除成功",
  7079. })
  7080. return
  7081. }
  7082. if origin == 2 {
  7083. service.BatchDeleteHisAdvice(idArray)
  7084. }
  7085. }
  7086. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7087. good_id, _ := c.GetInt64("good_id")
  7088. count, _ := c.GetInt64("count")
  7089. record_time, _ := c.GetInt64("record_time")
  7090. patient_id, _ := c.GetInt64("patient_id")
  7091. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7092. c.ServeSuccessJSON(map[string]interface{}{
  7093. "detail": detail,
  7094. })
  7095. return
  7096. }
  7097. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7098. good_id, _ := c.GetInt64("good_id")
  7099. record_time, _ := c.GetInt64("record_time")
  7100. patient_id, _ := c.GetInt64("patient_id")
  7101. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7102. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7103. fmt.Print("err", err)
  7104. c.ServeSuccessJSON(map[string]interface{}{
  7105. "msg": "批量删除成功",
  7106. })
  7107. return
  7108. }
  7109. func (c *DialysisAPIController) BatchAdviceCheck() {
  7110. ids := c.GetString("ids")
  7111. idArray := strings.Split(ids, ",")
  7112. creator, _ := c.GetInt64("creator")
  7113. origin, _ := c.GetInt64("origin")
  7114. if origin == 1 {
  7115. err := service.BatchAdviceCheck(idArray, creator)
  7116. fmt.Println(err)
  7117. list, _ := service.GetAdviceExecutionById(idArray)
  7118. c.ServeSuccessJSON(map[string]interface{}{
  7119. "list": list,
  7120. })
  7121. return
  7122. }
  7123. if origin == 2 {
  7124. service.BatchHisAdviceCheck(idArray, creator)
  7125. list, _ := service.GetHisAdviceExecutionById(idArray)
  7126. c.ServeSuccessJSON(map[string]interface{}{
  7127. "list": list,
  7128. })
  7129. return
  7130. }
  7131. }
  7132. func (c *DialysisAPIController) BatchAdviceExecution() {
  7133. ids := c.GetString("ids")
  7134. idArray := strings.Split(ids, ",")
  7135. executionTime := c.GetString("execution_time")
  7136. creator, _ := c.GetInt64("creator")
  7137. timeLayout := "2006-01-02 15:04:05"
  7138. loc, _ := time.LoadLocation("Local")
  7139. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7140. orgin, _ := c.GetInt64("origin")
  7141. if orgin == 1 {
  7142. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7143. list, _ := service.GetAdviceExecutionById(idArray)
  7144. fmt.Println(err)
  7145. c.ServeSuccessJSON(map[string]interface{}{
  7146. "list": list,
  7147. })
  7148. return
  7149. }
  7150. if orgin == 2 {
  7151. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7152. list, _ := service.GetHisAdviceExecutionById(idArray)
  7153. fmt.Println(err)
  7154. c.ServeSuccessJSON(map[string]interface{}{
  7155. "list": list,
  7156. })
  7157. return
  7158. }
  7159. }
  7160. func (c *DialysisAPIController) UpdateStockGoods() {
  7161. good_id, _ := c.GetInt64("good_id")
  7162. record_time, _ := c.GetInt64("record_time")
  7163. patient_id, _ := c.GetInt64("patient_id")
  7164. count, _ := c.GetInt64("count")
  7165. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7166. fmt.Print("err", err)
  7167. c.ServeSuccessJSON(map[string]interface{}{
  7168. "msg": "更新成功",
  7169. })
  7170. return
  7171. }
  7172. // 当前数据比上一次出库数据少
  7173. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7174. //查询该患者当天已经出库的耗材信息
  7175. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7176. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7177. for i := len(goods_yc) - 1; i >= 0; i-- {
  7178. goods_yc_temp := goods_yc[i]
  7179. for j := len(goods) - 1; j >= 0; j-- {
  7180. goods_temp := goods[j]
  7181. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7182. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7183. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7184. if goods_yc_temp.Count == goods_temp.Count {
  7185. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7186. goods = append(goods[:j], goods[j+1:]...)
  7187. break
  7188. }
  7189. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7190. if goods_yc_temp.Count > goods_temp.Count {
  7191. temp_count := goods_yc_temp.Count - goods_temp.Count
  7192. goods_yc[i].Count = temp_count
  7193. goods = append(goods[:j], goods[j+1:]...)
  7194. break
  7195. }
  7196. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7197. if goods_yc_temp.Count < goods_temp.Count {
  7198. temp_count := goods_temp.Count - goods_yc_temp.Count
  7199. goods[j].Count = temp_count
  7200. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7201. break
  7202. }
  7203. }
  7204. }
  7205. }
  7206. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7207. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7208. //退库
  7209. if len(goods_yc) > 0 {
  7210. for _, good_yc := range goods_yc {
  7211. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7212. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7213. }
  7214. }
  7215. return nil
  7216. }
  7217. // 耗材出库删除
  7218. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7219. // 先根据相关信息查询当天该耗材的出库信息
  7220. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7221. if err != nil {
  7222. return err
  7223. }
  7224. var delete_count int64 = 0
  7225. delete_count = warehouseOutInfos.Count - count
  7226. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7227. // 在出库记录表里记录退库详情
  7228. warehouseOutInfo := &models.WarehouseOutInfo{
  7229. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7230. WarehouseOutId: warehouseOut.ID,
  7231. Status: 1,
  7232. Ctime: time.Now().Unix(),
  7233. OrgId: orgID,
  7234. Type: 1,
  7235. IsSys: 1,
  7236. SysRecordTime: record_time,
  7237. GoodTypeId: good_yc.GoodTypeId,
  7238. GoodId: good_yc.GoodId,
  7239. PatientId: good_yc.PatientId,
  7240. ConsumableType: 2,
  7241. StorehouseId: houseConfig.StorehouseOutInfo,
  7242. IsCheck: 1,
  7243. }
  7244. warehouseOutInfo.Count = count
  7245. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7246. warehouseOutInfo.Price = stockInInfo.Price
  7247. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7248. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7249. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7250. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7251. warehouseOutInfo.Number = warehouseOutInfos.Number
  7252. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7253. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7254. //查找当天是否存在出库记录
  7255. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7256. if errcod == gorm.ErrRecordNotFound {
  7257. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7258. //插入详情明细表
  7259. stockFlow := models.VmStockFlow{
  7260. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7261. WarehouseOutId: warehouseOut.ID,
  7262. GoodId: good_yc.GoodId,
  7263. Number: warehouseOutInfos.Number,
  7264. ProductDate: stockInInfo.ProductDate,
  7265. ExpireDate: stockInInfo.ExpiryDate,
  7266. Count: count,
  7267. Price: stockInInfo.Price,
  7268. Status: 1,
  7269. Ctime: time.Now().Unix(),
  7270. UserOrgId: good_yc.OrgId,
  7271. Manufacturer: stockInInfo.Manufacturer,
  7272. Dealer: stockInInfo.Dealer,
  7273. LicenseNumber: stockInInfo.LicenseNumber,
  7274. IsEdit: 2,
  7275. Creator: creater,
  7276. SystemTime: record_time,
  7277. ConsumableType: 3,
  7278. WarehousingDetailId: 0,
  7279. IsSys: 1,
  7280. UpdateCreator: creater,
  7281. PatientId: patient_id,
  7282. StorehouseId: houseConfig.StorehouseOutInfo,
  7283. }
  7284. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7285. if errflow == gorm.ErrRecordNotFound {
  7286. //创建流水表
  7287. err := service.CreateStockFlowOne(stockFlow)
  7288. fmt.Println("err", err)
  7289. } else if errflow == nil {
  7290. //插入详情明细表
  7291. stockFlow := models.VmStockFlow{
  7292. ID: exsit.ID,
  7293. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7294. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7295. WarehouseOutId: warehouseOut.ID,
  7296. GoodId: good_yc.GoodId,
  7297. Number: warehouseOutInfos.Number,
  7298. ProductDate: stockInInfo.ProductDate,
  7299. ExpireDate: stockInInfo.ExpiryDate,
  7300. Count: exsit.Count - delete_count,
  7301. Price: stockInInfo.Price,
  7302. Status: 1,
  7303. Ctime: time.Now().Unix(),
  7304. UserOrgId: good_yc.OrgId,
  7305. Manufacturer: stockInInfo.Manufacturer,
  7306. Dealer: stockInInfo.Dealer,
  7307. LicenseNumber: stockInInfo.LicenseNumber,
  7308. IsEdit: 2,
  7309. Creator: creater,
  7310. SystemTime: record_time,
  7311. ConsumableType: 3,
  7312. WarehousingDetailId: 0,
  7313. IsSys: 1,
  7314. UpdateCreator: creater,
  7315. PatientId: patient_id,
  7316. StorehouseId: houseConfig.StorehouseOutInfo,
  7317. }
  7318. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7319. }
  7320. if errOne != nil {
  7321. return errOne
  7322. }
  7323. } else if errcod == nil {
  7324. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7325. //插入详情明细表
  7326. stockFlow := models.VmStockFlow{
  7327. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7328. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7329. WarehouseOutId: warehouseOut.ID,
  7330. GoodId: good_yc.GoodId,
  7331. Number: warehouseOutInfos.Number,
  7332. ProductDate: stockInInfo.ProductDate,
  7333. ExpireDate: stockInInfo.ExpiryDate,
  7334. Count: count,
  7335. Price: stockInInfo.Price,
  7336. Status: 1,
  7337. Ctime: time.Now().Unix(),
  7338. UserOrgId: good_yc.OrgId,
  7339. Manufacturer: stockInInfo.Manufacturer,
  7340. Dealer: stockInInfo.Dealer,
  7341. LicenseNumber: stockInInfo.LicenseNumber,
  7342. IsEdit: 2,
  7343. Creator: creater,
  7344. SystemTime: record_time,
  7345. ConsumableType: 3,
  7346. WarehousingDetailId: 0,
  7347. IsSys: 1,
  7348. UpdateCreator: creater,
  7349. PatientId: patient_id,
  7350. ReturnCount: delete_count,
  7351. StorehouseId: houseConfig.StorehouseOutInfo,
  7352. }
  7353. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7354. if errflows == gorm.ErrRecordNotFound {
  7355. //创建流水表
  7356. service.CreateStockFlowOne(stockFlow)
  7357. } else if errflows == nil {
  7358. stockFlow := models.VmStockFlow{
  7359. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7360. ID: exsit.ID,
  7361. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7362. WarehouseOutId: warehouseOut.ID,
  7363. GoodId: good_yc.GoodId,
  7364. Number: warehouseOutInfos.Number,
  7365. ProductDate: stockInInfo.ProductDate,
  7366. ExpireDate: stockInInfo.ExpiryDate,
  7367. Count: exsit.Count - delete_count,
  7368. Price: stockInInfo.Price,
  7369. Status: 1,
  7370. Ctime: time.Now().Unix(),
  7371. UserOrgId: good_yc.OrgId,
  7372. Manufacturer: stockInInfo.Manufacturer,
  7373. Dealer: stockInInfo.Dealer,
  7374. LicenseNumber: stockInInfo.LicenseNumber,
  7375. IsEdit: 2,
  7376. Creator: creater,
  7377. SystemTime: record_time,
  7378. ConsumableType: 3,
  7379. WarehousingDetailId: 0,
  7380. IsSys: 1,
  7381. UpdateCreator: creater,
  7382. PatientId: patient_id,
  7383. ReturnCount: delete_count,
  7384. StorehouseId: houseConfig.StorehouseOutInfo,
  7385. }
  7386. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7387. }
  7388. }
  7389. //更改自动出库的表格
  7390. details := models.BloodAutomaticReduceDetail{
  7391. WarehouseOutId: warehouseOutInfo.ID,
  7392. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7393. PatientId: patient_id,
  7394. Ctime: time.Now().Unix(),
  7395. Mtime: time.Now().Unix(),
  7396. Status: 1,
  7397. RecordTime: record_time,
  7398. OrgId: orgID,
  7399. GoodId: good_yc.GoodId,
  7400. GoodTypeId: good_yc.GoodTypeId,
  7401. Count: count,
  7402. StorehouseId: houseConfig.StorehouseOutInfo,
  7403. }
  7404. //查询当天耗材是否已经存在数据
  7405. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7406. if errcode == gorm.ErrRecordNotFound {
  7407. errTwo := service.CreateAutoReduceRecord(&details)
  7408. if errTwo != nil {
  7409. return errTwo
  7410. }
  7411. } else if errcode == nil {
  7412. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7413. service.CreateAutoReduceRecord(&details)
  7414. }
  7415. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7416. //增加出库库存数量
  7417. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7418. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7419. fmt.Println("errOne", errOne)
  7420. // 删除出库完成后,要增加对应批次的库存数量
  7421. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7422. if errThree != nil {
  7423. return errThree
  7424. }
  7425. if good_yc.Count == 0 {
  7426. return nil
  7427. } else {
  7428. return errors.New("退库和出库数据不匹配")
  7429. }
  7430. }
  7431. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  7432. //查询该患者当天已经出库的耗材信息
  7433. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7434. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7435. for i := len(goods_yc) - 1; i >= 0; i-- {
  7436. goods_yc_temp := goods_yc[i]
  7437. for j := len(goods) - 1; j >= 0; j-- {
  7438. goods_temp := goods[j]
  7439. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7440. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7441. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7442. if goods_yc_temp.Count == goods_temp.Count {
  7443. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7444. goods = append(goods[:j], goods[j+1:]...)
  7445. break
  7446. }
  7447. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7448. if goods_yc_temp.Count > goods_temp.Count {
  7449. temp_count := goods_yc_temp.Count - goods_temp.Count
  7450. goods_yc[i].Count = temp_count
  7451. goods = append(goods[:j], goods[j+1:]...)
  7452. break
  7453. }
  7454. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7455. if goods_yc_temp.Count < goods_temp.Count {
  7456. temp_count := goods_temp.Count - goods_yc_temp.Count
  7457. goods[j].Count = temp_count
  7458. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7459. break
  7460. }
  7461. }
  7462. }
  7463. }
  7464. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7465. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7466. fmt.Println("剩余需要出库的", len(goods))
  7467. if len(goods) > 0 {
  7468. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  7469. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7470. if err == gorm.ErrRecordNotFound {
  7471. //没有记录,则创建出库单
  7472. timeStr := time.Now().Format("2006-01-02")
  7473. timeArr := strings.Split(timeStr, "-")
  7474. total, _ := service.FindAllWarehouseOut(orgID)
  7475. total = total + 1
  7476. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7477. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7478. number = number + total
  7479. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7480. warehouseOut := models.WarehouseOut{
  7481. WarehouseOutOrderNumber: warehousing_out_order,
  7482. OperationTime: time.Now().Unix(),
  7483. OrgId: orgID,
  7484. Creater: creater,
  7485. Ctime: time.Now().Unix(),
  7486. Status: 1,
  7487. WarehouseOutTime: record_time,
  7488. Dealer: 0,
  7489. Manufacturer: 0,
  7490. Type: 1,
  7491. IsSys: 1,
  7492. StorehouseId: houseConfig.StorehouseOutInfo,
  7493. IsCheck: 1,
  7494. }
  7495. err := service.AddSigleWarehouseOut(&warehouseOut)
  7496. if err != nil {
  7497. utils.TraceLog("创建出库单失败 err = %v", err)
  7498. return err
  7499. } else {
  7500. out = warehouseOut
  7501. }
  7502. }
  7503. for _, item := range goods {
  7504. var newCount int64 = 0
  7505. for _, it := range goodOne {
  7506. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  7507. newCount = it.Count
  7508. }
  7509. }
  7510. prepare := models.DialysisBeforePrepare{
  7511. GoodTypeId: item.GoodTypeId,
  7512. GoodId: item.GoodId,
  7513. Count: item.Count,
  7514. StorehouseId: houseConfig.StorehouseOutInfo,
  7515. }
  7516. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  7517. //增加出库数量
  7518. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  7519. }
  7520. }
  7521. if len(goods_yc) > 0 {
  7522. for _, good_yc := range goods_yc {
  7523. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7524. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  7525. }
  7526. }
  7527. return nil
  7528. }
  7529. // 耗材出库删除
  7530. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  7531. // 先根据相关信息查询当天该耗材的出库信息
  7532. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  7533. if err != nil {
  7534. return err
  7535. }
  7536. var delete_count int64 = 0
  7537. for _, ware := range warehouseOutInfos {
  7538. // 判断当前出库的数据和删除出库数量
  7539. if good_yc.Count <= ware.Count {
  7540. delete_count = good_yc.Count
  7541. } else {
  7542. delete_count = ware.Count
  7543. }
  7544. warehouseOutInfo := &models.WarehouseOutInfo{
  7545. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7546. WarehouseOutId: warehouseOut.ID,
  7547. Status: 1,
  7548. Ctime: time.Now().Unix(),
  7549. Remark: "",
  7550. OrgId: orgID,
  7551. Type: 1,
  7552. Manufacturer: 0,
  7553. Dealer: 0,
  7554. IsSys: 0,
  7555. SysRecordTime: record_time,
  7556. GoodTypeId: good_yc.GoodTypeId,
  7557. GoodId: good_yc.GoodId,
  7558. StorehouseId: warehouseOut.StorehouseId,
  7559. IsCheck: 1,
  7560. }
  7561. warehouseOutInfo.Count = delete_count
  7562. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7563. warehouseOutInfo.Price = stockInInfo.Price
  7564. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7565. if errOne != nil {
  7566. return errOne
  7567. }
  7568. // 删除出库完成后,要改变流水库存(有疑问)
  7569. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7570. fmt.Println("errOne", errOne)
  7571. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  7572. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7573. //扣减出库数量
  7574. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  7575. if errThree != nil {
  7576. return errThree
  7577. }
  7578. }
  7579. if good_yc.Count == 0 {
  7580. return nil
  7581. } else {
  7582. return errors.New("退库和出库数据不匹配")
  7583. }
  7584. }
  7585. func (this *DialysisAPIController) GetMobileScheduleList() {
  7586. limit, _ := this.GetInt64("limit")
  7587. page, _ := this.GetInt64("page")
  7588. type_options_visible, _ := this.GetInt64("type_options_visible")
  7589. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  7590. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  7591. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  7592. }
  7593. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  7594. newArr = make([]*models.HisPrescriptionProject, 0)
  7595. for i := 0; i < len(arr); i++ {
  7596. repeat := false
  7597. for j := i + 1; j < len(arr); j++ {
  7598. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  7599. repeat = true
  7600. break
  7601. }
  7602. }
  7603. if !repeat {
  7604. newArr = append(newArr, arr[i])
  7605. }
  7606. }
  7607. return
  7608. }
  7609. func (this *DialysisAPIController) GetRoleList() {
  7610. admin_user_id, _ := this.GetInt64("admin_user_id")
  7611. orgid := this.GetMobileAdminUserInfo().Org.Id
  7612. list, err := service.GetRoleList(orgid, admin_user_id)
  7613. fmt.Println(err)
  7614. this.ServeSuccessJSON(map[string]interface{}{
  7615. "list": list,
  7616. })
  7617. return
  7618. }
  7619. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7620. // 先根据相关信息查询当天该耗材的出库信息
  7621. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7622. if err != nil {
  7623. return err
  7624. }
  7625. var delete_count int64 = 0
  7626. delete_count = warehouseOutInfos.Count - count
  7627. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7628. // 删除出库完成后,要增加对应批次的库存数量
  7629. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7630. if errThree != nil {
  7631. return errThree
  7632. }
  7633. //增加退库数量
  7634. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7635. //扣减出库数量
  7636. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  7637. //查询剩余库存
  7638. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  7639. var sum_count int64
  7640. for _, item := range goodList {
  7641. sum_count += item.StockCount
  7642. }
  7643. // 在出库记录表里记录退库详情
  7644. warehouseOutInfo := &models.WarehouseOutInfo{
  7645. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7646. WarehouseOutId: warehouseOut.ID,
  7647. Status: 1,
  7648. Ctime: time.Now().Unix(),
  7649. OrgId: orgID,
  7650. Type: 1,
  7651. IsSys: 1,
  7652. SysRecordTime: record_time,
  7653. GoodTypeId: good_yc.GoodTypeId,
  7654. GoodId: good_yc.GoodId,
  7655. PatientId: good_yc.PatientId,
  7656. ConsumableType: 2,
  7657. StorehouseId: houseConfig.StorehouseOutInfo,
  7658. IsCheck: 1,
  7659. OverCount: sum_count,
  7660. }
  7661. warehouseOutInfo.Count = count
  7662. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7663. warehouseOutInfo.Price = stockInInfo.Price
  7664. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7665. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7666. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7667. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7668. warehouseOutInfo.Number = warehouseOutInfos.Number
  7669. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7670. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7671. //查找当天是否存在出库记录
  7672. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7673. if errcod == gorm.ErrRecordNotFound {
  7674. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7675. //插入详情明细表
  7676. if errOne != nil {
  7677. return errOne
  7678. }
  7679. //插入详情明细表
  7680. stockFlow := models.VmStockFlow{
  7681. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7682. WarehouseOutId: warehouseOut.ID,
  7683. GoodId: good_yc.GoodId,
  7684. Number: warehouseOutInfos.Number,
  7685. ProductDate: stockInInfo.ProductDate,
  7686. ExpireDate: stockInInfo.ExpiryDate,
  7687. Count: count,
  7688. Price: stockInInfo.Price,
  7689. Status: 1,
  7690. Ctime: record_time,
  7691. UserOrgId: good_yc.OrgId,
  7692. Manufacturer: stockInInfo.Manufacturer,
  7693. Dealer: stockInInfo.Dealer,
  7694. LicenseNumber: stockInInfo.LicenseNumber,
  7695. IsEdit: 2,
  7696. Creator: creater,
  7697. SystemTime: record_time,
  7698. ConsumableType: 3,
  7699. WarehousingDetailId: 0,
  7700. IsSys: 1,
  7701. UpdateCreator: creater,
  7702. PatientId: patient_id,
  7703. StorehouseId: houseConfig.StorehouseOutInfo,
  7704. OverCount: sum_count,
  7705. ProjectId: good_yc.ProjectId,
  7706. }
  7707. err := service.CreateStockFlowOne(stockFlow)
  7708. fmt.Println("err", err)
  7709. } else if errcod == nil {
  7710. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7711. }
  7712. //创建退库单
  7713. operation_time := time.Now().Unix()
  7714. //创建退库单
  7715. timeStr := time.Now().Format("2006-01-02")
  7716. timeArr := strings.Split(timeStr, "-")
  7717. total, _ := service.FindAllCancelStockTotal(orgID)
  7718. total = total + 1
  7719. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7720. cancelStock := models.CancelStock{
  7721. OrderNumber: orderNumber,
  7722. OperaTime: operation_time,
  7723. OrgId: orgID,
  7724. Creater: warehouseOut.Creater,
  7725. Ctime: time.Now().Unix(),
  7726. Status: 1,
  7727. ReturnTime: record_time,
  7728. Type: 1,
  7729. StorehouseId: stockInInfo.StorehouseId,
  7730. IsCheck: 1,
  7731. }
  7732. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  7733. if msgerrkonde == gorm.ErrRecordNotFound {
  7734. service.AddSigleCancelStock(&cancelStock)
  7735. }
  7736. cancel, _ := service.GetLastCancelStockById(orgID)
  7737. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  7738. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  7739. cancelStockInfo := models.CancelStockInfo{
  7740. GoodId: stockInInfo.GoodId,
  7741. CancelStockId: cancel.ID,
  7742. GoodTypeId: stockInInfo.GoodTypeId,
  7743. Count: delete_count,
  7744. Price: stockInInfo.PackingPrice,
  7745. Total: 0,
  7746. ProductDate: stockInInfo.ProductDate,
  7747. ExpiryDate: stockInInfo.ExpiryDate,
  7748. Ctime: record_time,
  7749. Status: 1,
  7750. OrgId: orgID,
  7751. OrderNumber: cancel.OrderNumber,
  7752. Type: 0,
  7753. Dealer: deaerler.DealerName,
  7754. Manufacturer: manufacturer.ManufacturerName,
  7755. Number: stockInInfo.Number,
  7756. RegisterAccount: "",
  7757. Remark: "",
  7758. WarehouseInfoId: stockInInfo.ID,
  7759. PatientId: patient_id,
  7760. RecordDate: record_time,
  7761. StorehouseId: stockInInfo.StorehouseId,
  7762. IsCheck: 1,
  7763. }
  7764. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7765. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  7766. flow := models.VmStockFlow{
  7767. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  7768. GoodId: good_yc.GoodId,
  7769. Number: warehouseOutInfos.Number,
  7770. LicenseNumber: stockInInfo.LicenseNumber,
  7771. Count: delete_count,
  7772. UserOrgId: orgID,
  7773. PatientId: patient_id,
  7774. SystemTime: record_time,
  7775. ConsumableType: 7,
  7776. IsSys: 0,
  7777. WarehousingOrder: "",
  7778. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  7779. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7780. IsEdit: 0,
  7781. CancelStockId: cancel.ID,
  7782. CancelOrderNumber: cancel.OrderNumber,
  7783. Manufacturer: manufacturer.ID,
  7784. Dealer: 0,
  7785. Creator: warehouseOut.Creater,
  7786. UpdateCreator: 0,
  7787. Status: 1,
  7788. Ctime: record_time,
  7789. Mtime: 0,
  7790. Price: stockInInfo.Price,
  7791. WarehousingDetailId: stockInInfo.ID,
  7792. WarehouseOutDetailId: warehouseOutInfos.ID,
  7793. CancelOutDetailId: cancelInfo.ID,
  7794. ProductDate: stockInInfo.ProductDate,
  7795. ExpireDate: stockInInfo.ExpiryDate,
  7796. StorehouseId: houseConfig.StorehouseOutInfo,
  7797. OverCount: sum_count,
  7798. }
  7799. service.CreateStockFlowOne(flow)
  7800. //更改自动出库的表格
  7801. details := models.BloodAutomaticReduceDetail{
  7802. WarehouseOutId: warehouseOutInfo.ID,
  7803. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7804. PatientId: patient_id,
  7805. Ctime: time.Now().Unix(),
  7806. Mtime: time.Now().Unix(),
  7807. Status: 1,
  7808. RecordTime: record_time,
  7809. OrgId: orgID,
  7810. GoodId: good_yc.GoodId,
  7811. GoodTypeId: good_yc.GoodTypeId,
  7812. Count: count,
  7813. StorehouseId: houseConfig.StorehouseOutInfo,
  7814. }
  7815. //查询当天耗材是否已经存在数据
  7816. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7817. if errcode == gorm.ErrRecordNotFound {
  7818. errTwo := service.CreateAutoReduceRecord(&details)
  7819. if errTwo != nil {
  7820. return errTwo
  7821. }
  7822. } else if errcode == nil {
  7823. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7824. service.CreateAutoReduceRecord(&details)
  7825. }
  7826. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7827. //增加出库库存数量
  7828. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  7829. if good_yc.Count == 0 {
  7830. return nil
  7831. } else {
  7832. return errors.New("退库和出库数据不匹配")
  7833. }
  7834. }
  7835. func (this *DialysisAPIController) SavePatientSign() {
  7836. adminUserInfo := this.GetMobileAdminUserInfo()
  7837. patient_id, _ := this.GetInt64("patient_id")
  7838. dialysis_date, _ := this.GetInt64("dialysis_date")
  7839. orgid := adminUserInfo.Org.Id
  7840. var esdata models.DialysisOrder
  7841. var err error
  7842. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  7843. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7844. return
  7845. }
  7846. esdata.Hash = esdata.Hash
  7847. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  7848. order := models.DialysisOrder{
  7849. Hash: esdata.Hash,
  7850. Url: esdata.Url,
  7851. }
  7852. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  7853. redis := service.RedisClient()
  7854. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  7855. redis.Set(key, "", time.Second)
  7856. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  7857. //清空key 值
  7858. redis.Set(keyOne, "", time.Second)
  7859. //scheduleDateStartOne := startDate.Format("2006-01-02")
  7860. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  7861. //redis.Set(keyTwo, "", time.Second)
  7862. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  7863. redis.Set(keyThree, "", time.Second)
  7864. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  7865. redis.Set(keyFour, "", time.Second)
  7866. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  7867. redis.Set(keyFive, "", time.Second)
  7868. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  7869. redis.Set(keySix, "", time.Second)
  7870. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  7871. redis.Set(keySeven, "", time.Second)
  7872. if err != nil {
  7873. fmt.Println(err)
  7874. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  7875. return
  7876. }
  7877. this.ServeSuccessJSON(map[string]interface{}{
  7878. "electronic_signature": esdata,
  7879. })
  7880. }
  7881. func (this *DialysisAPIController) GetPatientSign() {
  7882. patient_id, _ := this.GetInt64("patient_id")
  7883. dialysis_date, _ := this.GetInt64("dialysis_date")
  7884. adminUserInfo := this.GetMobileAdminUserInfo()
  7885. orgId := adminUserInfo.Org.Id
  7886. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  7887. if err != nil {
  7888. fmt.Println(err)
  7889. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  7890. return
  7891. }
  7892. this.ServeSuccessJSON(map[string]interface{}{
  7893. "dialysisOrder": dialysisOrder,
  7894. })
  7895. }
  7896. func (this *DialysisAPIController) GetScheduleByPatient() {
  7897. patient_id, _ := this.GetInt64("patient_id")
  7898. schedule_date, _ := this.GetInt64("schedule_date")
  7899. orgid := this.GetMobileAdminUserInfo().Org.Id
  7900. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  7901. this.ServeSuccessJSON(map[string]interface{}{
  7902. "schedule": schedule,
  7903. })
  7904. }
  7905. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  7906. org_id := this.GetMobileAdminUserInfo().Org.Id
  7907. patient_id, _ := this.GetInt64("patient_id")
  7908. schedule_date, _ := this.GetInt64("schedule_date")
  7909. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  7910. this.ServeSuccessJSON(map[string]interface{}{
  7911. "order": order,
  7912. })
  7913. }
  7914. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  7915. org_id := this.GetMobileAdminUserInfo().Org.Id
  7916. schedule_date := this.GetString("schedule_date")
  7917. schedule_type, _ := this.GetInt64("schedule_type")
  7918. timeLayout := "2006-01-02"
  7919. loc, _ := time.LoadLocation("Local")
  7920. var startdateunix int64
  7921. if len(schedule_date) > 0 {
  7922. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  7923. if err != nil {
  7924. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7925. return
  7926. }
  7927. startdateunix = theTime.Unix()
  7928. }
  7929. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  7930. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  7931. devices, _ := service.GetAllDevicetByListSix(org_id)
  7932. for key, item := range scheduals {
  7933. // 床位信息
  7934. for _, device := range devices {
  7935. if item.BedId == device.ID {
  7936. scheduals[key].DeviceNumber = device
  7937. break
  7938. }
  7939. }
  7940. }
  7941. this.ServeSuccessJSON(map[string]interface{}{
  7942. "list": list,
  7943. "scheduals": scheduals,
  7944. })
  7945. }
  7946. func (this *DialysisAPIController) SavePatientPicture() {
  7947. patient_id, _ := this.GetInt64("patient_id")
  7948. dialysis_date, _ := this.GetInt64("schedule_date")
  7949. avatar := this.GetString("avatar")
  7950. fmt.Println("patient_id", patient_id)
  7951. orgId := this.GetMobileAdminUserInfo().Org.Id
  7952. order := models.DialysisOrder{
  7953. Url: avatar,
  7954. }
  7955. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  7956. redis := service.RedisClient()
  7957. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  7958. redis.Set(key, "", time.Second)
  7959. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  7960. //清空key 值
  7961. redis.Set(keyOne, "", time.Second)
  7962. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  7963. redis.Set(keyThree, "", time.Second)
  7964. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  7965. redis.Set(keyFour, "", time.Second)
  7966. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  7967. redis.Set(keyFive, "", time.Second)
  7968. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  7969. redis.Set(keySix, "", time.Second)
  7970. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  7971. redis.Set(keySeven, "", time.Second)
  7972. if err != nil {
  7973. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  7974. return
  7975. }
  7976. this.ServeSuccessJSON(map[string]interface{}{
  7977. "order": order,
  7978. })
  7979. }
  7980. func (this *DialysisAPIController) ExectionMobileAdvice() {
  7981. ids := this.GetString("ids")
  7982. idSplit := strings.Split(ids, ",")
  7983. orgId := this.GetMobileAdminUserInfo().Org.Id
  7984. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  7985. execution_time := this.GetString("exce_time")
  7986. timeLayout2 := "2006-01-02 15:04:05"
  7987. loc, _ := time.LoadLocation("Local")
  7988. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  7989. if errs != nil {
  7990. utils.ErrorLog(errs.Error())
  7991. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7992. return
  7993. }
  7994. //his客户
  7995. if config.IsOpen == 1 {
  7996. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  7997. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  7998. for _, item := range list {
  7999. for _, it := range adviceList {
  8000. if item.DrugId == it.DrugId {
  8001. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8002. }
  8003. }
  8004. }
  8005. for _, item := range list {
  8006. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8007. var sum_out_count int64
  8008. for _, itemThree := range item.ChildDoctorAdvice {
  8009. var prescribing_number int64
  8010. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8011. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8012. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8013. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8014. }
  8015. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8016. prescribing_number = parseIntPrescribingNumber
  8017. }
  8018. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8019. prescribing_number = parseIntPrescribingNumber
  8020. }
  8021. sum_out_count += prescribing_number
  8022. }
  8023. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8024. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8025. //库存不足
  8026. if sum_out_count > drugStockOut.FlushCount {
  8027. this.ServeSuccessJSON(map[string]interface{}{
  8028. "msg": "2",
  8029. "drug": medical,
  8030. "ids": ids,
  8031. })
  8032. return
  8033. }
  8034. }
  8035. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8036. //执行医嘱
  8037. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8038. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8039. for _, item := range advices {
  8040. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8041. redis := service.RedisClient()
  8042. //清空key 值
  8043. redis.Set(key, "", time.Second)
  8044. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8045. redis.Set(keyTwo, "", time.Second)
  8046. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8047. redis.Set(keyThree, "", time.Second)
  8048. recordDate := theTime.Format("2006-01-02")
  8049. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8050. redis.Set(keyFour, "", time.Second)
  8051. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8052. redis.Set(keyFive, "", time.Second)
  8053. defer redis.Close()
  8054. }
  8055. if errs == nil {
  8056. //药品管理信息
  8057. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8058. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8059. if drugStockConfig.IsOpen == 1 {
  8060. for _, item := range advices {
  8061. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8062. config, _ := service.GetDrugOpenConfigOne(orgId)
  8063. if config.IsOpen != 1 {
  8064. //查询该药品是否有库存
  8065. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8066. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8067. if medical.IsUse == 2 {
  8068. if config.IsOpen != 1 {
  8069. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8070. service.HisDrugsDelivery(orgId, creater, &advice)
  8071. if orgId == 3877 || orgId == 10265 {
  8072. //查询该药品是否有出库记录
  8073. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8074. if len(flowMap) == 0 {
  8075. errs := service.UpdateHisAdviceById(advice.ID)
  8076. if errs != nil {
  8077. drugError := models.XtDrugError{
  8078. UserOrgId: orgId,
  8079. DrugId: item.DrugId,
  8080. RecordDate: item.AdviceDate,
  8081. PatientId: item.PatientId,
  8082. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8083. Status: 1,
  8084. Ctime: time.Now().Unix(),
  8085. Mtime: 0,
  8086. SumCount: 0,
  8087. Prescribingnumber: advice.PrescribingNumber,
  8088. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8089. }
  8090. service.CreateDrugError(drugError)
  8091. }
  8092. this.ServeSuccessJSON(map[string]interface{}{
  8093. "msg": "2",
  8094. "drug": medical,
  8095. "ids": ids,
  8096. })
  8097. return
  8098. }
  8099. }
  8100. }
  8101. if pharmacyConfig.IsOpen != 1 {
  8102. service.HisDrugsDelivery(orgId, creater, &advice)
  8103. if orgId == 3877 || orgId == 10265 {
  8104. //查询该药品是否有出库记录
  8105. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8106. if len(flowMap) == 0 {
  8107. errs := service.UpdateHisAdviceById(advice.ID)
  8108. if errs != nil {
  8109. drugError := models.XtDrugError{
  8110. UserOrgId: orgId,
  8111. DrugId: item.DrugId,
  8112. RecordDate: item.AdviceDate,
  8113. PatientId: item.PatientId,
  8114. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8115. Status: 1,
  8116. Ctime: time.Now().Unix(),
  8117. Mtime: 0,
  8118. SumCount: 0,
  8119. Prescribingnumber: advice.PrescribingNumber,
  8120. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8121. }
  8122. service.CreateDrugError(drugError)
  8123. }
  8124. this.ServeSuccessJSON(map[string]interface{}{
  8125. "msg": "2",
  8126. "drug": medical,
  8127. "ids": ids,
  8128. })
  8129. return
  8130. }
  8131. }
  8132. }
  8133. //更新字典里面的库存
  8134. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8135. var sum_count int64
  8136. for _, its := range stockInfo {
  8137. if its.MaxUnit == medical.MaxUnit {
  8138. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8139. }
  8140. sum_count += its.StockMaxNumber + its.StockMinNumber
  8141. }
  8142. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8143. //剩余库存
  8144. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8145. }
  8146. }
  8147. }
  8148. }
  8149. }
  8150. this.ServeSuccessJSON(map[string]interface{}{
  8151. "msg": "1",
  8152. "ids": ids,
  8153. })
  8154. return
  8155. } else {
  8156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8157. }
  8158. }
  8159. //血透客户
  8160. if config.IsOpen == 2 || config.IsOpen == 0 {
  8161. //药品管理信息
  8162. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8163. if drugStockConfig.IsOpen == 1 {
  8164. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8165. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8166. for _, item := range list {
  8167. for _, it := range adviceList {
  8168. if item.DrugId == it.DrugId {
  8169. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8170. }
  8171. }
  8172. }
  8173. for _, item := range list {
  8174. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8175. var sum_out_count int64
  8176. for _, itemThree := range item.ChildDoctorAdvice {
  8177. var prescribing_number int64
  8178. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8179. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8180. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8181. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8182. }
  8183. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8184. prescribing_number = parseIntPrescribingNumber
  8185. }
  8186. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8187. prescribing_number = parseIntPrescribingNumber
  8188. }
  8189. sum_out_count += prescribing_number
  8190. }
  8191. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8192. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8193. //库存不足
  8194. if sum_out_count > drugStockOut.FlushCount {
  8195. this.ServeSuccessJSON(map[string]interface{}{
  8196. "msg": "2",
  8197. "drug": medical,
  8198. "ids": ids,
  8199. })
  8200. return
  8201. }
  8202. }
  8203. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8204. //执行医嘱
  8205. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8206. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8207. for _, item := range advices {
  8208. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8209. redis := service.RedisClient()
  8210. //清空key 值
  8211. redis.Set(key, "", time.Second)
  8212. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8213. redis.Set(keyTwo, "", time.Second)
  8214. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8215. redis.Set(keyThree, "", time.Second)
  8216. recordDate := theTime.Format("2006-01-02")
  8217. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8218. redis.Set(keyFour, "", time.Second)
  8219. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8220. redis.Set(keyFive, "", time.Second)
  8221. defer redis.Close()
  8222. }
  8223. if errs == nil {
  8224. for _, item := range advices {
  8225. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8226. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8227. //查询是否出库按钮开启
  8228. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8229. if adviceSetting.IsAdviceOpen == 1 {
  8230. //查询是否出库按钮开启
  8231. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8232. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8233. if prescriptionConfig.IsOpen == 1 {
  8234. if medical.IsUse == 2 {
  8235. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8236. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8237. }
  8238. if pharmacyConfig.IsOpen != 1 {
  8239. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8240. }
  8241. //更新字典里面的库存
  8242. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8243. var sum_count int64
  8244. for _, its := range stockInfo {
  8245. if its.MaxUnit == medical.MaxUnit {
  8246. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8247. }
  8248. sum_count += its.StockMaxNumber + its.StockMinNumber
  8249. }
  8250. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8251. //剩余库存
  8252. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8253. }
  8254. }
  8255. } else {
  8256. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8257. if medical.IsUse == 2 {
  8258. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8259. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8260. }
  8261. if pharmacyConfig.IsOpen != 1 {
  8262. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8263. }
  8264. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8265. var sum_count int64
  8266. for _, its := range stockInfo {
  8267. if its.MaxUnit == medical.MaxUnit {
  8268. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8269. }
  8270. sum_count += its.StockMaxNumber + its.StockMinNumber
  8271. }
  8272. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8273. //剩余库存
  8274. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8275. }
  8276. }
  8277. }
  8278. }
  8279. this.ServeSuccessJSON(map[string]interface{}{
  8280. "msg": "1",
  8281. "ids": ids,
  8282. })
  8283. return
  8284. } else {
  8285. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8286. //执行医嘱
  8287. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8288. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8289. for _, item := range advices {
  8290. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8291. redis := service.RedisClient()
  8292. //清空key 值
  8293. redis.Set(key, "", time.Second)
  8294. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8295. redis.Set(keyTwo, "", time.Second)
  8296. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8297. redis.Set(keyThree, "", time.Second)
  8298. recordDate := theTime.Format("2006-01-02")
  8299. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8300. redis.Set(keyFour, "", time.Second)
  8301. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8302. redis.Set(keyFive, "", time.Second)
  8303. defer redis.Close()
  8304. }
  8305. this.ServeSuccessJSON(map[string]interface{}{
  8306. "msg": "1",
  8307. "ids": ids,
  8308. })
  8309. return
  8310. }
  8311. }
  8312. }
  8313. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8314. ids := this.GetString("ids")
  8315. idSplit := strings.Split(ids, ",")
  8316. orgId := this.GetMobileAdminUserInfo().Org.Id
  8317. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8318. if config.IsOpen == 1 {
  8319. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8320. this.ServeSuccessJSON(map[string]interface{}{
  8321. "msg": "1",
  8322. "ids": ids,
  8323. })
  8324. return
  8325. }
  8326. if config.IsOpen == 0 || config.IsOpen == 2 {
  8327. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8328. this.ServeSuccessJSON(map[string]interface{}{
  8329. "msg": "1",
  8330. "ids": ids,
  8331. })
  8332. return
  8333. }
  8334. }
  8335. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8336. ids := this.GetString("ids")
  8337. idSplit := strings.Split(ids, ",")
  8338. orgId := this.GetMobileAdminUserInfo().Org.Id
  8339. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8340. //his
  8341. if config.IsOpen == 1 {
  8342. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8343. theTime := time.Now()
  8344. advices := models.HisDoctorAdviceThirty{
  8345. CheckTime: theTime.Unix(),
  8346. Checker: checker,
  8347. UpdatedTime: time.Now().Unix(),
  8348. }
  8349. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8350. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8351. for _, item := range list {
  8352. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8353. redis := service.RedisClient()
  8354. //清空key 值
  8355. redis.Set(key, "", time.Second)
  8356. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8357. redis.Set(keyTwo, "", time.Second)
  8358. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8359. redis.Set(keyThree, "", time.Second)
  8360. recordDate := theTime.Format("2006-01-02")
  8361. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8362. redis.Set(keyFour, "", time.Second)
  8363. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8364. redis.Set(keyFive, "", time.Second)
  8365. defer redis.Close()
  8366. }
  8367. this.ServeSuccessJSON(map[string]interface{}{
  8368. "msg": "1",
  8369. "ids": ids,
  8370. })
  8371. return
  8372. }
  8373. //血透
  8374. if config.IsOpen == 0 || config.IsOpen == 2 {
  8375. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8376. theTime := time.Now()
  8377. advices := models.DoctorAdvice{
  8378. CheckTime: theTime.Unix(),
  8379. Checker: checker,
  8380. UpdatedTime: time.Now().Unix(),
  8381. }
  8382. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8383. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8384. for _, item := range list {
  8385. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8386. redis := service.RedisClient()
  8387. //清空key 值
  8388. redis.Set(key, "", time.Second)
  8389. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8390. redis.Set(keyTwo, "", time.Second)
  8391. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8392. redis.Set(keyThree, "", time.Second)
  8393. recordDate := theTime.Format("2006-01-02")
  8394. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8395. redis.Set(keyFour, "", time.Second)
  8396. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8397. redis.Set(keyFive, "", time.Second)
  8398. defer redis.Close()
  8399. }
  8400. this.ServeSuccessJSON(map[string]interface{}{
  8401. "msg": "1",
  8402. "ids": ids,
  8403. })
  8404. return
  8405. }
  8406. }
  8407. func (this *DialysisAPIController) CheckSchedule() {
  8408. patientID, _ := this.GetInt64("patient_id")
  8409. recordDateStr := this.GetString("record_date")
  8410. nurseID, _ := this.GetInt64("start_nurse")
  8411. schedual_type, _ := this.GetInt64("schedual_type")
  8412. bedID, _ := this.GetInt64("bed")
  8413. start_time := this.GetString("start_time")
  8414. fmt.Println("patientID", patientID)
  8415. fmt.Println("recordDateStr", recordDateStr)
  8416. fmt.Println("nurseID", nurseID)
  8417. fmt.Println("schedual_type------", schedual_type)
  8418. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8420. return
  8421. }
  8422. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8423. if parseStartDateErr != nil {
  8424. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8425. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8426. return
  8427. }
  8428. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8429. if parseErr != nil {
  8430. this.ErrorLog("时间解析失败:%v", parseErr)
  8431. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8432. return
  8433. }
  8434. adminUserInfo := this.GetMobileAdminUserInfo()
  8435. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  8436. if getPatientErr != nil {
  8437. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  8438. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8439. return
  8440. } else if patient == nil {
  8441. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8442. return
  8443. }
  8444. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  8445. if getNurseErr != nil {
  8446. this.ErrorLog("获取护士失败:%v", getNurseErr)
  8447. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8448. return
  8449. } else if nurse == nil {
  8450. this.ErrorLog("护士不存在")
  8451. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8452. return
  8453. }
  8454. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  8455. if getDeviceNumberErr != nil {
  8456. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  8457. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8458. return
  8459. } else if deviceNumber == nil {
  8460. this.ErrorLog("床位号不存在")
  8461. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8462. return
  8463. }
  8464. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  8465. if getRecordErr != nil {
  8466. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  8467. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8468. return
  8469. } else if dialysisRecord != nil {
  8470. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  8471. return
  8472. }
  8473. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  8474. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  8475. timeLayout := "2006-01-02 15:04:05"
  8476. loc, _ := time.LoadLocation("Local")
  8477. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  8478. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  8479. schedulestartTime := theStartTime.Unix()
  8480. scheduleendTime := theEndTime.Unix()
  8481. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  8482. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  8483. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8484. //查询该床位是否有人用了
  8485. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8486. if err == nil {
  8487. if schedule.ID == 0 {
  8488. this.ServeSuccessJSON(map[string]interface{}{
  8489. "status": 0,
  8490. "msg": "请求失败",
  8491. })
  8492. } else {
  8493. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  8494. if order.ID > 0 { //该机位被其他人占用了
  8495. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  8496. return
  8497. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  8498. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  8499. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  8500. this.ServeSuccessJSON(map[string]interface{}{
  8501. "status": 1,
  8502. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  8503. })
  8504. return
  8505. } else {
  8506. this.ServeSuccessJSON(map[string]interface{}{
  8507. "status": 0,
  8508. "msg": "",
  8509. })
  8510. }
  8511. }
  8512. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  8513. this.ServeSuccessJSON(map[string]interface{}{
  8514. "status": 2,
  8515. "msg": "当前机位已有患者在使用,请重新选择!",
  8516. })
  8517. }
  8518. }
  8519. } else {
  8520. this.ServeSuccessJSON(map[string]interface{}{
  8521. "status": 0,
  8522. "msg": "",
  8523. })
  8524. }
  8525. }
  8526. func (this *DialysisAPIController) GetNewDoctorListToday() {
  8527. orgId := this.GetMobileAdminUserInfo().Org.Id
  8528. schedule_type, _ := this.GetInt64("schedule_type")
  8529. partion_type, _ := this.GetInt64("partion_type")
  8530. start_time := this.GetString("start_time")
  8531. timeLayout := "2006-01-02"
  8532. loc, _ := time.LoadLocation("Local")
  8533. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8534. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  8535. _, config := service.FindXTHisRecordByOrgId(orgId)
  8536. appId := this.GetMobileAdminUserInfo().App.Id
  8537. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  8538. if err == nil {
  8539. this.ServeSuccessJSON(map[string]interface{}{
  8540. "list": list,
  8541. "config": config,
  8542. "doctorList": doctorList,
  8543. })
  8544. return
  8545. } else {
  8546. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8547. return
  8548. }
  8549. }
  8550. func (this *DialysisAPIController) SaveMobileInformation() {
  8551. patient_id, _ := this.GetInt64("patient_id")
  8552. record_date, _ := this.GetInt64("record_date")
  8553. startTime := this.GetString("start_time")
  8554. module, _ := this.GetInt64("module")
  8555. remark := this.GetString("remark")
  8556. timeLayout := "2006-01-02 15:04"
  8557. loc, _ := time.LoadLocation("Local")
  8558. if len(startTime) == 0 {
  8559. utils.ErrorLog("len(start_time) == 0")
  8560. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8561. return
  8562. }
  8563. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  8564. if err != nil {
  8565. utils.ErrorLog(err.Error())
  8566. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8567. return
  8568. }
  8569. StartTime := theTime.Unix()
  8570. fmt.Println("startime-------------", StartTime)
  8571. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8572. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  8573. information := models.XtDialysisInformation{
  8574. Module: module,
  8575. PatientId: patient_id,
  8576. RecordDate: record_date,
  8577. ApplicationDate: StartTime,
  8578. Creater: creater,
  8579. ApplicationStatus: 2,
  8580. Checker: 0,
  8581. CheckTime: 0,
  8582. Remark: remark,
  8583. UserOrgId: user_org_id,
  8584. Ctime: time.Now().Unix(),
  8585. Status: 1,
  8586. Mtime: 0,
  8587. }
  8588. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  8589. if infor.ID == 0 {
  8590. service.SaveDialysisInformation(information)
  8591. }
  8592. if infor.ID > 0 {
  8593. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  8594. }
  8595. this.ServeSuccessJSON(map[string]interface{}{
  8596. "information": information,
  8597. })
  8598. return
  8599. }
  8600. func (this *DialysisAPIController) GetMobileInformation() {
  8601. limit, _ := this.GetInt64("limit")
  8602. page, _ := this.GetInt64("page")
  8603. orgid := this.GetMobileAdminUserInfo().Org.Id
  8604. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  8605. appid := this.GetMobileAdminUserInfo().App.Id
  8606. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8607. patients, _ := service.GetAllpatientThirty(orgid)
  8608. this.ServeSuccessJSON(map[string]interface{}{
  8609. "information": information,
  8610. "total": total,
  8611. "doclist": doclist,
  8612. "patients": patients,
  8613. })
  8614. return
  8615. }
  8616. func (this *DialysisAPIController) GetMobileInformationOne() {
  8617. limit, _ := this.GetInt64("limit")
  8618. page, _ := this.GetInt64("page")
  8619. orgid := this.GetMobileAdminUserInfo().Org.Id
  8620. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  8621. appid := this.GetMobileAdminUserInfo().App.Id
  8622. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8623. patients, _ := service.GetAllpatientThirty(orgid)
  8624. this.ServeSuccessJSON(map[string]interface{}{
  8625. "information": information,
  8626. "total": total,
  8627. "doclist": doclist,
  8628. "patients": patients,
  8629. })
  8630. return
  8631. }
  8632. func (this *DialysisAPIController) CheckMobileInformation() {
  8633. id, _ := this.GetInt64("id")
  8634. application_status, _ := this.GetInt64("application_status")
  8635. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8636. checktime := time.Now().Unix()
  8637. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  8638. if err == nil {
  8639. this.ServeSuccessJSON(map[string]interface{}{
  8640. "msg": "ok",
  8641. })
  8642. return
  8643. }
  8644. }
  8645. func (c *DialysisAPIController) GetControlMonitorList() {
  8646. partition, _ := c.GetInt64("partition")
  8647. monitorDate := c.GetString("date")
  8648. patient_id, _ := c.GetInt64("patient_id")
  8649. pat_type, _ := c.GetInt64("pat_type")
  8650. timeLayout := "2006-01-02"
  8651. loc, _ := time.LoadLocation("Local")
  8652. var theStartTime int64
  8653. if len(monitorDate) > 0 {
  8654. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  8655. if err != nil {
  8656. theStartTime = 0
  8657. }
  8658. theStartTime = theTime.Unix()
  8659. }
  8660. adminInfo := c.GetMobileAdminUserInfo()
  8661. orgID := adminInfo.Org.Id
  8662. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  8663. if err != nil {
  8664. c.ErrorLog("获取排班信息失败:%v", err)
  8665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8666. } else {
  8667. if len(monitor) > 0 {
  8668. //获取所有床位
  8669. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  8670. //获取所有分区
  8671. zoneList, _ := service.GetAllZoneByList(orgID)
  8672. //获取透析处方
  8673. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  8674. //获取透前评估
  8675. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  8676. //获取上机
  8677. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  8678. //获取透后
  8679. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  8680. //获取透后监测
  8681. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  8682. //获取所有的患者
  8683. patients, _ := service.GetAllPatientListByListOne(orgID)
  8684. //获取所有透析模式
  8685. treatments, _ := service.GetAllTreatModeByList(orgID)
  8686. //获取所有医嘱
  8687. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  8688. //获取双人核对
  8689. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  8690. //治疗小结
  8691. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  8692. //待消毒
  8693. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  8694. for key, item := range monitor {
  8695. // 获取床位信息
  8696. for _, it := range numberList {
  8697. if item.BedId == it.ID {
  8698. monitor[key].DeviceNumber = it
  8699. break
  8700. }
  8701. }
  8702. //获取分区信息
  8703. for _, it := range zoneList {
  8704. if item.PartitionId == it.ID {
  8705. monitor[key].DeviceZone = it
  8706. }
  8707. }
  8708. for _, prescription := range prescriptions {
  8709. if item.PatientId == prescription.PatientId {
  8710. monitor[key].Prescription = prescription
  8711. break
  8712. }
  8713. }
  8714. for _, it := range checkList {
  8715. if item.PatientId == it.PatientId {
  8716. monitor[key].DoubleCheck = it
  8717. break
  8718. }
  8719. }
  8720. for _, it := range summaryList {
  8721. if item.PatientId == it.PatientId {
  8722. monitor[key].TreatmentSummaryForList = it
  8723. break
  8724. }
  8725. }
  8726. // 透前评估
  8727. for _, assessmentBefore := range assessmentBefores {
  8728. if item.PatientId == assessmentBefore.PatientId {
  8729. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  8730. break
  8731. }
  8732. }
  8733. // 透析上下机
  8734. for _, dialysisOrder := range dialysisOrders {
  8735. if item.PatientId == dialysisOrder.PatientId {
  8736. monitor[key].DialysisOrder = dialysisOrder
  8737. break
  8738. }
  8739. }
  8740. // 治疗小节
  8741. for _, afterDislysis := range AssessmentAfterDislysis {
  8742. if item.PatientId == afterDislysis.PatientId {
  8743. monitor[key].AssessmentAfterDislysis = afterDislysis
  8744. break
  8745. }
  8746. }
  8747. for _, it := range monitorlist {
  8748. if item.PatientId == it.PatientId {
  8749. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  8750. }
  8751. }
  8752. for _, it := range adviceList {
  8753. if item.PatientId == it.PatientId {
  8754. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  8755. }
  8756. }
  8757. for _, patient := range patients {
  8758. if item.PatientId == patient.ID {
  8759. monitor[key].MonitorPatients = patient
  8760. break
  8761. }
  8762. }
  8763. for _, treatment := range treatments {
  8764. if item.ModeId == treatment.ID {
  8765. monitor[key].TreatmentMode = treatment
  8766. break
  8767. }
  8768. }
  8769. for _, infor := range informationList {
  8770. if item.PatientId == infor.PatientId {
  8771. monitor[key].NewDeviceInformation = infor
  8772. break
  8773. }
  8774. }
  8775. }
  8776. }
  8777. }
  8778. patients, err := service.GetAllpatientFourty(orgID)
  8779. var mds []*models.NewMonitorDialysisScheduleList
  8780. if pat_type == 0 {
  8781. for _, item := range monitor {
  8782. mds = append(mds, item)
  8783. }
  8784. }
  8785. //待医嘱核对
  8786. if pat_type == 1 {
  8787. for _, item := range monitor {
  8788. if len(item.AdviceList) > 0 {
  8789. mds = append(mds, item)
  8790. }
  8791. }
  8792. }
  8793. //待开小结
  8794. if pat_type == 2 {
  8795. for _, item := range monitor {
  8796. if item.TreatmentSummaryForList == nil {
  8797. mds = append(mds, item)
  8798. }
  8799. }
  8800. }
  8801. //待下机
  8802. if pat_type == 3 {
  8803. for _, item := range monitor {
  8804. if item.DialysisOrder != nil {
  8805. if item.DialysisOrder.ID > 0 {
  8806. mds = append(mds, item)
  8807. }
  8808. }
  8809. }
  8810. }
  8811. //待消毒
  8812. if pat_type == 4 {
  8813. for _, item := range monitor {
  8814. if item.NewDeviceInformation == nil {
  8815. mds = append(mds, item)
  8816. }
  8817. }
  8818. }
  8819. //待双人核对
  8820. if pat_type == 5 {
  8821. for _, item := range monitor {
  8822. if item.DoubleCheck == nil {
  8823. mds = append(mds, item)
  8824. }
  8825. }
  8826. }
  8827. //医嘱未执行
  8828. if pat_type == 6 {
  8829. for _, item := range monitor {
  8830. if len(item.AdviceList) > 0 {
  8831. mds = append(mds, item)
  8832. }
  8833. }
  8834. }
  8835. //患者未签名
  8836. if pat_type == 7 {
  8837. for _, item := range monitor {
  8838. if item.DialysisOrder != nil {
  8839. if item.DialysisOrder.ID > 0 {
  8840. mds = append(mds, item)
  8841. }
  8842. }
  8843. }
  8844. }
  8845. //目标超滤于实际超滤不同
  8846. if pat_type == 8 {
  8847. for _, item := range monitor {
  8848. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  8849. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  8850. mds = append(mds, item)
  8851. }
  8852. }
  8853. }
  8854. }
  8855. //血压少于5次
  8856. if pat_type == 9 {
  8857. for _, item := range monitor {
  8858. if len(item.MonitoringRecord) < 5 {
  8859. mds = append(mds, item)
  8860. }
  8861. }
  8862. }
  8863. if pat_type == 10 {
  8864. for _, item := range monitor {
  8865. if len(item.MonitoringRecord) == 0 {
  8866. mds = append(mds, item)
  8867. }
  8868. }
  8869. }
  8870. if pat_type == 11 {
  8871. for _, item := range monitor {
  8872. if len(item.MonitoringRecord) > 0 {
  8873. mds = append(mds, item)
  8874. }
  8875. }
  8876. }
  8877. if pat_type == 12 {
  8878. for _, item := range monitor {
  8879. if len(item.MonitoringRecord) > 0 {
  8880. mds = append(mds, item)
  8881. }
  8882. }
  8883. }
  8884. if err == nil {
  8885. c.ServeSuccessJSON(map[string]interface{}{
  8886. "monitor": mds,
  8887. "patients": patients,
  8888. })
  8889. } else {
  8890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8891. }
  8892. }
  8893. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  8894. admin_user_id, _ := c.GetInt64("admin_user_id")
  8895. timeStr := time.Now().Format("2006-01-02")
  8896. timeLayout := "2006-01-02 15:04:05"
  8897. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  8898. timenow := timeStringToTime.Unix()
  8899. orgId := c.GetMobileAdminUserInfo().Org.Id
  8900. //查询当前护士的患者
  8901. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  8902. var patientIds []int64
  8903. for _, item := range orderList {
  8904. patientIds = append(patientIds, item.PatientId)
  8905. }
  8906. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  8907. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  8908. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  8909. //药品管理信息
  8910. _, drugStockConfig := service.FindHisConfig(orgId)
  8911. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  8912. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  8913. c.ServeSuccessJSON(map[string]interface{}{
  8914. "adviceList": adviceList,
  8915. "hisAdviceList": hisAdviceList,
  8916. "projectList": projectList,
  8917. "drugStockConfig": drugStockConfig,
  8918. "patientList": patientList,
  8919. "projectConfig": projectConfig,
  8920. })
  8921. }
  8922. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  8923. patient_id, _ := c.GetInt64("patient_id")
  8924. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  8925. c.ServeSuccessJSON(map[string]interface{}{
  8926. "recrods": recrods,
  8927. })
  8928. }
  8929. func (c *DialysisAPIController) ExMobileChangeSch() {
  8930. id_one, _ := c.GetInt64("id_one")
  8931. id_two, _ := c.GetInt64("id_two")
  8932. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  8933. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  8934. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  8935. //if order2.ID > 0 {
  8936. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  8937. // return
  8938. //}
  8939. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  8940. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  8941. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  8942. if count > 0 {
  8943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  8944. return
  8945. }
  8946. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  8947. if count1 > 0 {
  8948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  8949. return
  8950. }
  8951. }
  8952. err := service.UpdateScheduleThree(sch, sch_two)
  8953. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  8954. if order.ID > 0 {
  8955. //查询该患者的排班机位
  8956. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  8957. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  8958. redis := service.RedisClient()
  8959. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  8960. redis.Set(key, "", time.Second)
  8961. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  8962. //清空key 值
  8963. redis.Set(keyOne, "", time.Second)
  8964. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  8965. //return
  8966. }
  8967. if err == nil {
  8968. //去除当天患者排班中重复数据,保留最后一条数据
  8969. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  8970. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  8971. c.ServeSuccessJSON(map[string]interface{}{
  8972. "msg": "交换成功",
  8973. })
  8974. } else {
  8975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8976. return
  8977. }
  8978. }
  8979. func (c *DialysisAPIController) MobileCoverSch() {
  8980. id_one, _ := c.GetInt64("id_one")
  8981. id_two, _ := c.GetInt64("id_two")
  8982. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  8983. //针对凤凰医院
  8984. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  8985. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  8986. if len(advice) > 0 {
  8987. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  8988. }
  8989. }
  8990. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  8991. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  8992. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  8993. if len(hisAdvice) > 0 {
  8994. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  8995. }
  8996. if len(project) > 0 {
  8997. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  8998. }
  8999. }
  9000. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9001. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9002. if order.ID > 0 {
  9003. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9004. redis := service.RedisClient()
  9005. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9006. redis.Set(key, "", time.Second)
  9007. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9008. //清空key 值
  9009. redis.Set(keyOne, "", time.Second)
  9010. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9011. //return
  9012. }
  9013. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9014. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9015. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9016. if count > 0 {
  9017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9018. return
  9019. }
  9020. }
  9021. var new_sch models.Schedule
  9022. new_sch = sch
  9023. new_sch.BedId = sch_two.BedId
  9024. new_sch.ScheduleDate = sch_two.ScheduleDate
  9025. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9026. new_sch.PartitionId = sch_two.PartitionId
  9027. new_sch.ScheduleType = sch_two.ScheduleType
  9028. new_sch.ID = 0
  9029. //删除原来的排班
  9030. err := service.SaveSchTwo(sch, sch_two)
  9031. //生成新的排班
  9032. if err == nil {
  9033. err2 := service.SaveSch(&new_sch)
  9034. if err2 == nil {
  9035. //去除当天患者排班中重复数据,保留最后一条数据
  9036. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9037. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9038. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9039. c.ServeSuccessJSON(map[string]interface{}{
  9040. "msg": "覆盖成功",
  9041. "new_sch": new_sch,
  9042. })
  9043. } else {
  9044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9045. return
  9046. }
  9047. } else {
  9048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9049. return
  9050. }
  9051. }
  9052. func (c *DialysisAPIController) BatchCheckAdvice() {
  9053. patient_id, _ := c.GetInt64("patient_id")
  9054. advice_date, _ := c.GetInt64("advice_date")
  9055. org_id := c.GetMobileAdminUserInfo().Org.Id
  9056. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  9057. //查询是his系统还是血透系统
  9058. _, configs := service.FindXTHisRecordByOrgId(org_id)
  9059. //his客户
  9060. if configs.IsOpen == 1 {
  9061. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  9062. for _, item := range adviceList {
  9063. service.BatchCheckHisAdvice(item.ID, creater)
  9064. }
  9065. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9066. for _, item := range projectList {
  9067. service.BatchCheckProject(item.ID, creater)
  9068. }
  9069. c.ServeSuccessJSON(map[string]interface{}{
  9070. "adviceList": adviceList,
  9071. "projectList": projectList,
  9072. })
  9073. }
  9074. if configs.IsOpen != 1 {
  9075. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  9076. for _, item := range adviceList {
  9077. service.BatchAdviceList(item.ID, creater)
  9078. }
  9079. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9080. for _, item := range projectList {
  9081. service.BatchCheckProject(item.ID, creater)
  9082. }
  9083. c.ServeSuccessJSON(map[string]interface{}{
  9084. "adviceList": adviceList,
  9085. "projectList": projectList,
  9086. })
  9087. }
  9088. return
  9089. }