dialysis_api_controller.go 450KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638
  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. //针对溪康
  891. if adminUserInfo.Org.Id == 10721 {
  892. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  893. if len(adviceInfoList) > 0 {
  894. for _, item := range adviceInfoList {
  895. service.UpdateHisAdviceList(item.ID, creater)
  896. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  897. redis := service.RedisClient()
  898. //清空key 值
  899. redis.Set(key, "", time.Second)
  900. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  901. redis.Set(keyTwo, "", time.Second)
  902. theTime := time.Now()
  903. recordDate := theTime.Format("2006-01-02")
  904. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  905. redis.Set(keyFour, "", time.Second)
  906. defer redis.Close()
  907. }
  908. }
  909. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  910. if len(adviceList) > 0 {
  911. for _, item := range adviceList {
  912. service.UpdateAdviceList(item.ID, creater)
  913. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  914. redis := service.RedisClient()
  915. //清空key 值
  916. redis.Set(key, "", time.Second)
  917. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  918. redis.Set(keyTwo, "", time.Second)
  919. theTime := time.Now()
  920. recordDate := theTime.Format("2006-01-02")
  921. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  922. redis.Set(keyFour, "", time.Second)
  923. defer redis.Close()
  924. }
  925. }
  926. }
  927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  928. redis := service.RedisClient()
  929. //清空key 值
  930. redis.Set(key, "", time.Second)
  931. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  932. redis.Set(keyOne, "", time.Second)
  933. defer redis.Close()
  934. if err == nil {
  935. c.ServeSuccessJSON(map[string]interface{}{
  936. "doubleCheck": &doubleCheck,
  937. })
  938. }
  939. } else { //修改
  940. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  941. if infor.ID > 0 {
  942. var cha_time int64
  943. timeNowStr := time.Now().Format("2006-01-02")
  944. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  945. //今日的日期减去设置的日期
  946. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  947. if cha_time >= recordDate.Unix() {
  948. //查询审核是否允许
  949. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  950. //申请状态不允许的情况 拒绝修改
  951. if infor.ApplicationStatus != 1 {
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  953. return
  954. }
  955. }
  956. }
  957. doubleCheck.FirstCheckTime = firstCheckDate
  958. doubleCheck.CheckTime = checkDate
  959. doubleCheck.Creater = creater
  960. doubleCheck.Modifier = modifier
  961. doubleCheck.CreatedTime = check.CreatedTime
  962. doubleCheck.ID = check.ID
  963. doubleCheck.EmployeeNumber = employee_number
  964. doubleCheck.NeedleBatchNumber = needle_batch_number
  965. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  966. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  967. //查询未核对的医嘱
  968. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  969. for _, advice := range doctorList {
  970. if advice.ExecutionStaff == modifier {
  971. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  972. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  973. return
  974. }
  975. }
  976. }
  977. //针对溪康
  978. if adminUserInfo.Org.Id == 10721 {
  979. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  980. if len(adviceInfoList) > 0 {
  981. for _, item := range adviceInfoList {
  982. service.UpdateHisAdviceList(item.ID, creater)
  983. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  984. redis := service.RedisClient()
  985. //清空key 值
  986. redis.Set(key, "", time.Second)
  987. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  988. redis.Set(keyTwo, "", time.Second)
  989. theTime := time.Now()
  990. recordDate := theTime.Format("2006-01-02")
  991. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  992. redis.Set(keyFour, "", time.Second)
  993. defer redis.Close()
  994. }
  995. }
  996. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  997. if len(adviceList) > 0 {
  998. for _, item := range adviceList {
  999. service.UpdateAdviceList(item.ID, creater)
  1000. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1001. redis := service.RedisClient()
  1002. //清空key 值
  1003. redis.Set(key, "", time.Second)
  1004. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1005. redis.Set(keyTwo, "", time.Second)
  1006. theTime := time.Now()
  1007. recordDate := theTime.Format("2006-01-02")
  1008. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1009. redis.Set(keyFour, "", time.Second)
  1010. defer redis.Close()
  1011. }
  1012. }
  1013. }
  1014. err := service.UpdateDoubleCheck(&doubleCheck)
  1015. //针对长沙南雅
  1016. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  1017. //查询未核对的医嘱
  1018. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1019. if len(doctorList) > 0 && modifier > 0 {
  1020. for _, advice := range doctorList {
  1021. service.UpdateDoctorAdviceList(advice.ID, modifier)
  1022. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1023. redis := service.RedisClient()
  1024. //清空key 值
  1025. redis.Set(key, "", time.Second)
  1026. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1027. redis.Set(keyTwo, "", time.Second)
  1028. theTime := time.Now()
  1029. recordDate := theTime.Format("2006-01-02")
  1030. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1031. redis.Set(keyFour, "", time.Second)
  1032. defer redis.Close()
  1033. }
  1034. }
  1035. }
  1036. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1037. redis := service.RedisClient()
  1038. //清空key 值
  1039. redis.Set(key, "", time.Second)
  1040. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1041. redis.Set(keyOne, "", time.Second)
  1042. defer redis.Close()
  1043. if err == nil {
  1044. c.ServeSuccessJSON(map[string]interface{}{
  1045. "doubleCheck": &doubleCheck,
  1046. "msg": "1",
  1047. })
  1048. }
  1049. }
  1050. }
  1051. func (c *DialysisAPIController) PostAcceptsAssessment() {
  1052. id, _ := c.GetInt64("patient", 0)
  1053. recordDateStr := c.GetString("record_date")
  1054. way, _ := c.GetInt64("way", 0)
  1055. consciousness, _ := c.GetInt64("consciousness", 0)
  1056. appetite, _ := c.GetInt64("appetite", 0)
  1057. condition, _ := c.GetInt64("condition", 0)
  1058. posture, _ := c.GetInt64("posture")
  1059. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1060. danger_level, _ := c.GetInt64("danger_level", 0)
  1061. intake, _ := c.GetInt64("intake", 0)
  1062. nutrition, _ := c.GetInt64("nutrition", 0)
  1063. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1064. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1065. score := c.GetString("score")
  1066. sick_condition_other := c.GetString("sick_condition_other")
  1067. //precaution, _ := c.GetInt64("precaution", 0)
  1068. precaution := c.GetString("precaution")
  1069. precaution_other := c.GetString("precaution_other")
  1070. psychological_other := c.GetString("psychological_other")
  1071. admission_number := c.GetString("admission_number")
  1072. tumble, _ := c.GetInt64("tumble")
  1073. diacrisis := c.GetString("diacrisis")
  1074. his_department := c.GetString("his_department")
  1075. his_bed := c.GetString("his_bed")
  1076. if id <= 0 {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1078. return
  1079. }
  1080. adminUserInfo := c.GetMobileAdminUserInfo()
  1081. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1082. if patient.ID == 0 {
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1084. return
  1085. }
  1086. //now := time.Now()
  1087. //year, month, day := now.Date()
  1088. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1089. //todayTimeStamp := today_time.Unix()
  1090. if len(recordDateStr) == 0 {
  1091. recordDateStr = time.Now().Format("2006-01-02")
  1092. }
  1093. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1094. if parseDateErr != nil {
  1095. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. // 查询信息规挡的设置天数
  1100. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1101. if infor.ID > 0 && infor.WeekDay > 0 {
  1102. var cha_time int64
  1103. timeNowStr := time.Now().Format("2006-01-02")
  1104. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1105. //今日的日期减去设置的日期
  1106. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1107. if cha_time >= recordDate.Unix() {
  1108. //查询审核是否允许
  1109. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1110. //申请状态不允许的情况 拒绝修改
  1111. if infor.ApplicationStatus != 1 {
  1112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1113. return
  1114. }
  1115. }
  1116. }
  1117. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1118. if adminUserInfo.Org.Id == 10340 {
  1119. if condition == 1 {
  1120. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1121. if admission_number == "" {
  1122. admission_number = lastAcceptTreatment.AdmissionNumber
  1123. }
  1124. }
  1125. }
  1126. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1127. UserOrgId: adminUserInfo.Org.Id,
  1128. PatientId: id,
  1129. RecordDate: recordDate.Unix(),
  1130. Way: way,
  1131. Consciousness: consciousness,
  1132. Appetite: appetite,
  1133. Condition: condition,
  1134. SickCondition: sick_condition,
  1135. DangerLevel: danger_level,
  1136. Intake: intake,
  1137. Nutrition: nutrition,
  1138. PsychologicalAssessment: psychological_assessment,
  1139. PsychologicalAssessmentOther: psychological_assessment_other,
  1140. SickConditionOther: sick_condition_other,
  1141. Posture: posture,
  1142. CreatedTime: time.Now().Unix(),
  1143. UpdateTime: time.Now().Unix(),
  1144. Status: 1,
  1145. Score: score,
  1146. Precaution: precaution,
  1147. PrecautionOther: precaution_other,
  1148. PsychologicalOther: psychological_other,
  1149. AdmissionNumber: admission_number,
  1150. Tumble: tumble,
  1151. Diacrisis: diacrisis,
  1152. HisBed: his_bed,
  1153. HisDepartment: his_department,
  1154. }
  1155. if receiveTreatment.ID == 0 { //新增
  1156. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1157. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1158. finish := models.XtDialysisFinish{
  1159. IsFinish: 1,
  1160. UserOrgId: adminUserInfo.Org.Id,
  1161. Status: 1,
  1162. Ctime: time.Now().Unix(),
  1163. Mtime: 0,
  1164. Module: 2,
  1165. RecordDate: recordDate.Unix(),
  1166. Sourse: 1,
  1167. PatientId: id,
  1168. }
  1169. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1170. if dialysisFinish.ID == 0 {
  1171. service.CreateDialysisFinish(finish)
  1172. }
  1173. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1174. redis := service.RedisClient()
  1175. defer redis.Close()
  1176. //清空key 值
  1177. redis.Set(key, "", time.Second)
  1178. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1179. redis.Set(keyOne, "", time.Second)
  1180. if err == nil {
  1181. c.ServeSuccessJSON(map[string]interface{}{
  1182. "receiveTreatmentAsses": receiveTreatmentAsses,
  1183. })
  1184. }
  1185. } else { //修改
  1186. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1187. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1188. // if getPermissionErr != nil {
  1189. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1190. // return
  1191. // } else if headNursePermission == nil {
  1192. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1193. // return
  1194. // }
  1195. //}
  1196. // 查询信息规挡的设置天数
  1197. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1198. if infor.ID > 0 && infor.WeekDay > 0 {
  1199. var cha_time int64
  1200. timeNowStr := time.Now().Format("2006-01-02")
  1201. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1202. //今日的日期减去设置的日期
  1203. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1204. if cha_time >= recordDate.Unix() {
  1205. //查询审核是否允许
  1206. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1207. //申请状态不允许的情况 拒绝修改
  1208. if infor.ApplicationStatus != 1 {
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1210. return
  1211. }
  1212. }
  1213. }
  1214. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1215. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1216. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1217. receiveTreatmentAsses.ID = receiveTreatment.ID
  1218. if adminUserInfo.Org.Id == 10340 {
  1219. if condition == 1 {
  1220. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1221. if receiveTreatmentAsses.AdmissionNumber == "" {
  1222. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1223. }
  1224. }
  1225. }
  1226. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1227. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1228. redis := service.RedisClient()
  1229. defer redis.Close()
  1230. //清空key 值
  1231. redis.Set(key, "", time.Second)
  1232. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1233. redis.Set(keyOne, "", time.Second)
  1234. if err == nil {
  1235. c.ServeSuccessJSON(map[string]interface{}{
  1236. "receiveTreatmentAsses": receiveTreatmentAsses,
  1237. })
  1238. }
  1239. }
  1240. }
  1241. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1242. id, _ := c.GetInt64("patient", 0)
  1243. recordDateStr := c.GetString("record_date")
  1244. weightAfter, _ := c.GetFloat("weight_after", 0)
  1245. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1246. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1247. fmt.Println("weight_loss", weightReduce)
  1248. temperature, _ := c.GetFloat("temperature", 0)
  1249. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1250. breathing_rate := c.GetString("breathing_rate")
  1251. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1252. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1253. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1254. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1255. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1256. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1257. cruor := c.GetString("cruor")
  1258. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1259. internalFistula := c.GetString("internal_fistula")
  1260. catheter := c.GetString("catheter")
  1261. complications := c.GetString("complication")
  1262. remark := c.GetString("remark")
  1263. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1264. dialysis_intakes := c.GetString("dialysis_intakes")
  1265. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1266. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1267. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1268. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1269. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1270. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1271. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1272. patientGose, _ := c.GetInt64("patient_gose", 0)
  1273. inpatientDepartment := c.GetString("inpatient_department")
  1274. observationContent := c.GetString("observation_content")
  1275. observationContentOther := c.GetString("observation_content_other")
  1276. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1277. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1278. in_advance_reason := c.GetString("in_advance_reason")
  1279. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1280. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1281. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1282. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1283. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1284. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1285. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1286. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1287. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1288. is_eat, _ := c.GetInt64("is_eat", 0)
  1289. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1290. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1291. channels, _ := c.GetInt64("channel", 0)
  1292. return_blood, _ := c.GetInt64("return_blood", 0)
  1293. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1294. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1295. dialysis_during, _ := c.GetFloat("dialysis_during")
  1296. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1297. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1298. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1299. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1300. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1301. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1302. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1303. setting_pressure := c.GetString("setting_pressure")
  1304. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1305. diastolic_pressure := c.GetString("diastolic_pressure")
  1306. other_complication := c.GetString("other_complication")
  1307. ktv := c.GetString("ktv")
  1308. urr := c.GetString("urr")
  1309. hypertenison, _ := c.GetInt64("hypertenison")
  1310. hypopiesia, _ := c.GetInt64("hypopiesia")
  1311. leave_office_method, _ := c.GetInt64("leave_office_method")
  1312. lapse, _ := c.GetInt64("lapse")
  1313. consciousness, _ := c.GetInt64("consciousness")
  1314. fallrisk, _ := c.GetInt64("fallrisk")
  1315. machine_run := c.GetString("machine_run")
  1316. after_urea := c.GetString("after_urea")
  1317. pip_coagulation := c.GetString("pip_coagulation")
  1318. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1319. transfusion_volume := c.GetString("transfusion_volume")
  1320. last_after_weight := c.GetString("last_after_weight")
  1321. displace_liqui_value := c.GetString("displace_liqui_value")
  1322. start_time := c.GetString("start_time")
  1323. symptom_after_dialysis_remark := c.GetString("symptom_after_dialysis_remark")
  1324. if id <= 0 {
  1325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1326. return
  1327. }
  1328. adminUserInfo := c.GetMobileAdminUserInfo()
  1329. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1330. if patient.ID == 0 {
  1331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1332. return
  1333. }
  1334. if len(recordDateStr) == 0 {
  1335. recordDateStr = time.Now().Format("2006-01-02")
  1336. }
  1337. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1338. fmt.Println("parseDateErr", parseDateErr)
  1339. if parseDateErr != nil {
  1340. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1342. return
  1343. }
  1344. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1345. //now := time.Now()
  1346. //year, month, day := now.Date()
  1347. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1348. //todayTimeStamp := today_time.Unix()
  1349. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1350. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1351. UserOrgId: adminUserInfo.Org.Id,
  1352. PatientId: id,
  1353. AssessmentDate: recordDate.Unix(),
  1354. Temperature: temperature,
  1355. PulseFrequency: pulse_frequency,
  1356. BreathingRate: breathing_rate,
  1357. SystolicBloodPressure: systolic_blood_pressure,
  1358. DiastolicBloodPressure: diastolic_blood_pressure,
  1359. ActualUltrafiltration: actual_ultrafiltration,
  1360. ActualDisplacement: actual_displacement,
  1361. ActualTreatmentHour: actualtreatHour,
  1362. ActualTreatmentMinute: actualtreatmin,
  1363. WeightAfter: weightAfter,
  1364. AdditionalWeight: additionalWeight,
  1365. WeightLoss: weightReduce,
  1366. Cruor: cruor,
  1367. SymptomAfterDialysis: symptomsAfterDialysi,
  1368. InternalFistula: internalFistula,
  1369. Catheter: catheter,
  1370. Complication: complications,
  1371. DialysisIntakes: dialysateVolume,
  1372. CreatedTime: time.Now().Unix(),
  1373. UpdatedTime: time.Now().Unix(),
  1374. Status: 1,
  1375. Remark: remark,
  1376. BloodAccessPartId: blood_access_part_id,
  1377. BloodAccessPartOperaId: blood_access_part_opera_id,
  1378. DialysisIntakesUnit: dialysis_intakes_unit,
  1379. PuncturePointOozingBlood: puncturePointOozingBlood,
  1380. PuncturePointHaematoma: puncturePointHaematoma,
  1381. InternalFistulaTremorAc: internalFistulaTremorAc,
  1382. PatientGose: patientGose,
  1383. InpatientDepartment: inpatientDepartment,
  1384. ObservationContent: observationContent,
  1385. ObservationContentOther: observationContentOther,
  1386. DialysisProcess: dialysis_process,
  1387. InAdvanceMinute: in_advance_minute,
  1388. InAdvanceReason: in_advance_reason,
  1389. HemostasisMinute: hemostasis_minute,
  1390. HemostasisOpera: hemostasis_opera,
  1391. TremorNoise: tremor_noise,
  1392. DisequilibriumSyndrome: disequilibrium_syndrome,
  1393. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1394. ArterialTube: arterial_tube,
  1395. IntravenousTube: intravenous_tube,
  1396. Dialyzer: dialyzer,
  1397. InAdvanceReasonOther: in_advance_reason_other,
  1398. IsEat: is_eat,
  1399. CvcA: cvc_a,
  1400. CvcV: cvc_v,
  1401. Channel: channels,
  1402. ReturnBlood: return_blood,
  1403. RehydrationVolume: rehydration_volume,
  1404. DialysisDuring: dialysis_during,
  1405. StrokeVolume: stroke_volume,
  1406. BloodFlow: blood_flow,
  1407. SealingFluidDispose: sealing_fluid_dispose,
  1408. SealingFluidSpecial: sealing_fluid_special,
  1409. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1410. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1411. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1412. SettingPressure: setting_pressure,
  1413. DiastolicPressure: diastolic_pressure,
  1414. OtherComplication: other_complication,
  1415. Ktv: ktv,
  1416. Urr: urr,
  1417. Hypopiesia: hypopiesia,
  1418. Hypertenison: hypertenison,
  1419. Lapse: lapse,
  1420. LeaveOfficeMethod: leave_office_method,
  1421. Consciousness: consciousness,
  1422. Fallrisk: fallrisk,
  1423. MachineRun: machine_run,
  1424. AfterUrea: after_urea,
  1425. PipCoagulation: pip_coagulation,
  1426. AccumulatedBloodVolume: accumulated_blood_volume,
  1427. TransfusionVolume: transfusion_volume,
  1428. LastAfterWeight: last_after_weight,
  1429. DisplaceLiquiValue: displace_liqui_value,
  1430. RecordTime: startDate.Unix(),
  1431. SymptomAfterDialysisRemark: symptom_after_dialysis_remark,
  1432. }
  1433. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1434. // 查询信息规挡的设置天数
  1435. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1436. if infor.ID > 0 && infor.WeekDay > 0 {
  1437. var cha_time int64
  1438. timeNowStr := time.Now().Format("2006-01-02")
  1439. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1440. //今日的日期减去设置的日期
  1441. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1442. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1443. if cha_time >= recordDate.Unix() {
  1444. //查询审核是否允许
  1445. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1446. //申请状态不允许的情况 拒绝修改
  1447. if infor.ApplicationStatus != 1 {
  1448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1449. return
  1450. }
  1451. }
  1452. }
  1453. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1454. if assessmentAfter.ID == 0 { //新增
  1455. if appRole.UserType == 2 || appRole.UserType == 1 {
  1456. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1457. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1458. } else {
  1459. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1460. }
  1461. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1462. if assessmentAfterDislysis.UserOrgId != 10340 {
  1463. if assessmentAfterDislysis.WeightAfter == 0 {
  1464. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1465. }
  1466. }
  1467. if adminUserInfo.Org.Id == 10693 {
  1468. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1469. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1470. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1471. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1472. }
  1473. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1474. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1475. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1476. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1477. }
  1478. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1479. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1480. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1481. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1482. }
  1483. if assessmentAfterDislysis.PulseFrequency == 0 {
  1484. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1485. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1486. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1487. }
  1488. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1489. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1490. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1491. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1492. }
  1493. }
  1494. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1495. //记录日志
  1496. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1497. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1498. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1499. PatientId: assessmentAfterDislysis.PatientId,
  1500. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1501. Status: 1,
  1502. ErrLog: string(byterequest),
  1503. AdminUserId: adminUserInfo.AdminUser.Id,
  1504. Ctime: 0,
  1505. Mtime: 0,
  1506. Source: "手机端保存透后评估",
  1507. }
  1508. service.CreateAfterDialysisLog(afterDialysisLog)
  1509. finish := models.XtDialysisFinish{
  1510. IsFinish: 1,
  1511. UserOrgId: adminUserInfo.Org.Id,
  1512. Status: 1,
  1513. Ctime: time.Now().Unix(),
  1514. Mtime: 0,
  1515. Module: 9,
  1516. RecordDate: recordDate.Unix(),
  1517. Sourse: 1,
  1518. PatientId: id,
  1519. }
  1520. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1521. if dialysisFinish.ID == 0 {
  1522. service.CreateDialysisFinish(finish)
  1523. }
  1524. redis := service.RedisClient()
  1525. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1526. redis.Set(keyTwo, "", time.Second)
  1527. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1528. //清空key 值
  1529. redis.Set(key, "", time.Second)
  1530. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1531. redis.Set(keyOne, "", time.Second)
  1532. defer redis.Close()
  1533. if err == nil {
  1534. c.ServeSuccessJSON(map[string]interface{}{
  1535. "assessmentAfterDislysis": assessmentAfterDislysis,
  1536. })
  1537. }
  1538. return
  1539. } else { //修改
  1540. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1541. if infor.ID > 0 && infor.WeekDay > 0 {
  1542. var cha_time int64
  1543. timeNowStr := time.Now().Format("2006-01-02")
  1544. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1545. //今日的日期减去设置的日期
  1546. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1547. if cha_time >= recordDate.Unix() {
  1548. //查询审核是否允许
  1549. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1550. //申请状态不允许的情况 拒绝修改
  1551. if infor.ApplicationStatus != 1 {
  1552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1553. return
  1554. }
  1555. }
  1556. }
  1557. if appRole.UserType == 2 || appRole.UserType == 1 {
  1558. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1559. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1560. } else {
  1561. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1562. if assessmentAfterDislysis.Creater == 0 {
  1563. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1564. }
  1565. }
  1566. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1567. assessmentAfterDislysis.ID = assessmentAfter.ID
  1568. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1569. if assessmentAfterDislysis.UserOrgId != 10340 {
  1570. if assessmentAfterDislysis.WeightAfter == 0 {
  1571. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1572. }
  1573. }
  1574. if adminUserInfo.Org.Id == 10693 {
  1575. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1576. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1577. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1578. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1579. }
  1580. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1581. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1582. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1583. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1584. }
  1585. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1586. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1587. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1588. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1589. }
  1590. if assessmentAfterDislysis.PulseFrequency == 0 {
  1591. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1592. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1593. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1594. }
  1595. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1596. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1597. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1598. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1599. }
  1600. }
  1601. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1602. //记录日志
  1603. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1604. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1605. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1606. PatientId: assessmentAfterDislysis.PatientId,
  1607. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1608. Status: 1,
  1609. ErrLog: string(byterequest),
  1610. AdminUserId: adminUserInfo.AdminUser.Id,
  1611. Ctime: time.Now().Unix(),
  1612. Mtime: 0,
  1613. Source: "手机端修改保存透后评估",
  1614. }
  1615. service.CreateAfterDialysisLog(afterDialysisLog)
  1616. redis := service.RedisClient()
  1617. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1618. redis.Set(keyTwo, "", time.Second)
  1619. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1620. //清空key 值
  1621. redis.Set(key, "", time.Second)
  1622. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1623. redis.Set(keyOne, "", time.Second)
  1624. if err == nil {
  1625. c.ServeSuccessJSON(map[string]interface{}{
  1626. "assessmentAfterDislysis": assessmentAfterDislysis,
  1627. })
  1628. return
  1629. }
  1630. }
  1631. return
  1632. }
  1633. func (c *DialysisAPIController) PostDialysisPrescription() {
  1634. id, _ := c.GetInt64("patient", 0)
  1635. recordDateStr := c.GetString("record_date")
  1636. if id <= 0 {
  1637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1638. return
  1639. }
  1640. adminUserInfo := c.GetMobileAdminUserInfo()
  1641. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1642. if patient.ID == 0 {
  1643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1644. return
  1645. }
  1646. if len(recordDateStr) == 0 {
  1647. recordDateStr = time.Now().Format("2006-01-02")
  1648. }
  1649. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1650. if parseDateErr != nil {
  1651. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1653. return
  1654. }
  1655. mode_id, _ := c.GetInt64("mode_id", 0)
  1656. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1657. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1658. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1659. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1660. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1661. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1662. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1663. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1664. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1665. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1666. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1667. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1668. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1669. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1670. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1671. kalium, _ := c.GetFloat("kalium", 0)
  1672. sodium, _ := c.GetFloat("sodium", 0)
  1673. calcium, _ := c.GetFloat("calcium", 0)
  1674. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1675. glucose, _ := c.GetFloat("glucose", 0)
  1676. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1677. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1678. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1679. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1680. conductivity, _ := c.GetFloat("conductivity", 0)
  1681. remark := c.GetString("remark")
  1682. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1683. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1684. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1685. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1686. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1687. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1688. special_medicine_other := c.GetString("special_medicine_other")
  1689. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1690. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1691. blood_access, _ := c.GetInt64("blood_access", 0)
  1692. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1693. body_fluid_other := c.GetString("body_fluid_other")
  1694. niprocart, _ := c.GetInt64("niprocart", 0)
  1695. jms, _ := c.GetInt64("jms", 0)
  1696. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1697. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1698. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1699. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1700. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1701. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1702. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1703. injector, _ := c.GetInt64("injector", 0)
  1704. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1705. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1706. safe_package, _ := c.GetInt64("package", 0)
  1707. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1708. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1709. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1710. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1711. blood := c.GetString("blood")
  1712. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1713. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1714. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1715. displace_speed := c.GetString("displace_speed")
  1716. illness, _ := c.GetInt64("illness")
  1717. amylaceum := c.GetString("amylaceum")
  1718. single_time := c.GetString("single_time")
  1719. single_water := c.GetString("single_water")
  1720. replacement_flow := c.GetString("replacement_flow")
  1721. plasma_separator := c.GetString("plasma_separator")
  1722. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1723. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1724. oxygen_flow := c.GetString("oxygen_flow")
  1725. oxygen_time := c.GetString("oxygen_time")
  1726. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1727. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1728. puncture_needle := c.GetString("puncture_needle")
  1729. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1730. epo := c.GetString("epo")
  1731. epo_count, _ := c.GetFloat("epo_count", 0)
  1732. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1733. admin_user_id, _ := c.GetInt64("admin_user_id")
  1734. is_water := c.GetString("is_water")
  1735. var is_war int64
  1736. if is_water == "是" {
  1737. is_war = 1
  1738. }
  1739. if is_water == "否" {
  1740. is_war = 2
  1741. }
  1742. if is_water == "请选择" {
  1743. is_war = 0
  1744. }
  1745. drhy_water := c.GetString("drhy_water")
  1746. dry_water_hour := c.GetString("dry_water_hour")
  1747. water_machine := c.GetString("water_machine")
  1748. add_amount, _ := c.GetFloat("add_amount")
  1749. reduce_amount, _ := c.GetFloat("reduce_amount")
  1750. dialysis_remark := c.GetString("dialysis_remark")
  1751. prescribing_number, _ := c.GetFloat("prescribing_number")
  1752. prescription_sodium := c.GetString("prescription_sodium")
  1753. start_sodium := c.GetString("start_sodium")
  1754. sodium_curve := c.GetString("sodium_curve")
  1755. treatment_remark := c.GetString("treatment_remark")
  1756. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1757. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1758. prescription_water, _ := c.GetFloat("prescription_water")
  1759. dialysis_strainer := c.GetString("dialysis_strainer")
  1760. chaptalization := c.GetString("chaptalization")
  1761. washing_time := c.GetString("washing_time")
  1762. warsh_count := c.GetString("warsh_count")
  1763. blood_access_part_id := c.GetString("blood_access_part_id")
  1764. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1765. dialyzate := c.GetString("dialyzate")
  1766. first_super := c.GetString("first_super")
  1767. var first_sup int64
  1768. if first_super == "是" {
  1769. first_sup = 1
  1770. }
  1771. if first_super == "否" {
  1772. first_sup = 2
  1773. }
  1774. if first_super == "请选择" {
  1775. first_sup = 0
  1776. }
  1777. is_sequential := c.GetString("is_sequential")
  1778. var is_sequent int64
  1779. if is_sequential == "是" {
  1780. is_sequent = 1
  1781. }
  1782. if is_sequential == "否" {
  1783. is_sequent = 2
  1784. }
  1785. if is_sequential == "请选择" {
  1786. is_sequent = 0
  1787. }
  1788. conduct := c.GetString("conduct")
  1789. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1790. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1791. //
  1792. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1793. // if appRole.UserType == 3 {
  1794. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1795. // if getPermissionErr != nil {
  1796. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1797. // return
  1798. // } else if headNursePermission == nil {
  1799. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1800. // return
  1801. // }
  1802. // }
  1803. //}
  1804. // 查询信息规挡的设置天数
  1805. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1806. if infor.ID > 0 && infor.WeekDay > 0 {
  1807. var cha_time int64
  1808. timeNowStr := time.Now().Format("2006-01-02")
  1809. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1810. //今日的日期减去设置的日期
  1811. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1812. if cha_time >= recordDate.Unix() {
  1813. //查询审核是否允许
  1814. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1815. //申请状态不允许的情况 拒绝修改
  1816. if infor.ApplicationStatus != 1 {
  1817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1818. return
  1819. }
  1820. }
  1821. }
  1822. if mode_id > 0 {
  1823. var str string
  1824. //查找该机构用的是什么透析器
  1825. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1826. if filedConfig.ID > 0 {
  1827. str = dialyzerPerfusionApparatus
  1828. } else {
  1829. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1830. }
  1831. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1832. }
  1833. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1834. var dialysis_dialyszers_id int64
  1835. var dialysis_strainer_id int64
  1836. var dialysis_irrigation_id int64
  1837. if len(goodList) > 0 {
  1838. for _, item := range goodList {
  1839. if item.SpecificationName == dialysis_dialyszers {
  1840. dialysis_dialyszers_id = item.ID
  1841. }
  1842. if item.SpecificationName == dialysis_irrigation {
  1843. dialysis_irrigation_id = item.ID
  1844. }
  1845. if item.SpecificationName == dialysis_strainer {
  1846. dialysis_strainer_id = item.ID
  1847. }
  1848. }
  1849. }
  1850. //TODO 需要根据角色去判断
  1851. prescription := models.DialysisPrescription{
  1852. UserOrgId: adminUserInfo.Org.Id,
  1853. PatientId: id,
  1854. RecordDate: recordDate.Unix(),
  1855. ModeId: mode_id,
  1856. DialysisDuration: dialysis_duration,
  1857. Dialyzer: dialyzer,
  1858. PerfusionApparatus: perfusion_apparatus,
  1859. BloodFlowVolume: blood_flow_volume,
  1860. DewaterAmount: dewater_amount,
  1861. DisplaceLiqui: displace_liqui,
  1862. ReplacementWay: replacement_way,
  1863. Anticoagulant: anticoagulant,
  1864. AnticoagulantShouji: anticoagulant_shouji,
  1865. AnticoagulantWeichi: anticoagulant_weichi,
  1866. AnticoagulantZongliang: anticoagulant_zongliang,
  1867. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1868. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1869. Kalium: kalium,
  1870. Sodium: sodium,
  1871. Calcium: calcium,
  1872. Bicarbonate: bicarbonate,
  1873. Glucose: glucose,
  1874. // DryWeight: dry_weight,
  1875. DialysateFlow: dialysate_flow,
  1876. DialysateTemperature: dialysate_temperature,
  1877. // PrescriptionDoctor: prescription_doctor,
  1878. ReplacementTotal: replacement_total,
  1879. Conductivity: conductivity,
  1880. Remark: remark,
  1881. Status: 1,
  1882. CreatedTime: time.Now().Unix(),
  1883. UpdatedTime: time.Now().Unix(),
  1884. DialysisDurationMinute: dialysisDurationMinute,
  1885. DialysisDurationHour: dialysisDurationHour,
  1886. TargetUltrafiltration: targetUltrafiltration,
  1887. DialysateFormulation: dialysateFormulation,
  1888. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1889. BodyFluid: body_fluid,
  1890. SpecialMedicine: special_medicine,
  1891. SpecialMedicineOther: special_medicine_other,
  1892. DisplaceLiquiPart: displace_liqui_part,
  1893. DisplaceLiquiValue: displace_liqui_value,
  1894. BloodAccess: blood_access,
  1895. Ultrafiltration: ultrafiltration,
  1896. BodyFluidOther: body_fluid_other,
  1897. Niprocart: niprocart,
  1898. Jms: jms,
  1899. FistulaNeedleSet: fistula_needle_set,
  1900. FistulaNeedleSet16: fistula_needle_set_16,
  1901. Hemoperfusion: hemoperfusion,
  1902. DialyserSterilised: dialyser_sterilised,
  1903. Filtryzer: filtryzer,
  1904. Dialyzers: dialyzers,
  1905. Injector: injector,
  1906. Bloodlines: bloodlines,
  1907. TubingHemodialysis: tubing_hemodialysis,
  1908. Package: safe_package,
  1909. ALiquid: a_liquid,
  1910. TargetKtv: target_ktv,
  1911. PreImpulse: pre_impulse,
  1912. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1913. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1914. Blood: blood,
  1915. DialysisDialyszers: dialysis_dialyszers,
  1916. DialysisIrrigation: dialysis_irrigation,
  1917. AntioxidantCommodityName: antioxidant_commodity_name,
  1918. DisplaceSpeed: displace_speed,
  1919. Illness: illness,
  1920. Amylaceum: amylaceum,
  1921. SingleTime: single_time,
  1922. SingleWater: single_water,
  1923. ReplacementFlow: replacement_flow,
  1924. PlasmaSeparator: plasma_separator,
  1925. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1926. OxygenUptake: oxygen_uptake,
  1927. OxygenFlow: oxygen_flow,
  1928. OxygenTime: oxygen_time,
  1929. HemodialysisPipelines: hemodialysis_pipelines,
  1930. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1931. PunctureNeedle: puncture_needle,
  1932. PunctureNeedleCount: puncture_needle_count,
  1933. Epo: epo,
  1934. EpoCount: epo_count,
  1935. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1936. AdminUserId: admin_user_id,
  1937. IsWater: is_war,
  1938. DrhyWater: drhy_water,
  1939. DryWaterHour: dry_water_hour,
  1940. WaterMachine: water_machine,
  1941. AddAmount: add_amount,
  1942. ReduceAmount: reduce_amount,
  1943. DialysisRemark: dialysis_remark,
  1944. PrescribingNumber: prescribing_number,
  1945. StartSodium: start_sodium,
  1946. SodiumCurve: sodium_curve,
  1947. TreatmentRemark: treatment_remark,
  1948. PrescriptionSodium: prescription_sodium,
  1949. DialysisFluidFlow: dialysis_fluid_flow,
  1950. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1951. PrescriptionWater: prescription_water,
  1952. DialysisStrainer: dialysis_strainer,
  1953. Chaptalization: chaptalization,
  1954. WashingTime: washing_time,
  1955. WarshCount: warsh_count,
  1956. BloodAccessPartId: blood_access_part_id,
  1957. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1958. Dialyzate: dialyzate,
  1959. DialysisDialyszersId: dialysis_dialyszers_id,
  1960. DialysisIrrigationId: dialysis_irrigation_id,
  1961. DialysisStrainerId: dialysis_strainer_id,
  1962. FirstSuper: first_sup,
  1963. IsSequential: is_sequent,
  1964. Conduct: conduct,
  1965. }
  1966. if adminUserInfo.Org.Id == 10721 {
  1967. if prescription.ModeId == 2 {
  1968. if prescription.ReplacementTotal == 0 {
  1969. prescription.ReplacementTotal = 15
  1970. }
  1971. }
  1972. }
  1973. //查询最近透析准备表里是否存在 透析器 灌流器
  1974. //
  1975. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1976. //
  1977. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1978. //
  1979. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1980. //if len(mation)>0{
  1981. // for _, item := range splitStr {
  1982. // for _,it := range mation{
  1983. // if(item == it.SpecificationName){
  1984. //
  1985. // //查询最近一次的透析器
  1986. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1987. //
  1988. // if errcode == gorm.ErrRecordNotFound{
  1989. // //插入数据
  1990. // prepare := models.DialysisBeforePrepare{
  1991. // UserOrgId: adminUserInfo.Org.Id,
  1992. // PatientId: id,
  1993. // RecordDate: recordDate.Unix(),
  1994. // GoodTypeId: it.GoodTypeId,
  1995. // GoodId: it.ID,
  1996. // Count: 1,
  1997. // Ctime: time.Now().Unix(),
  1998. // Creater: adminUserInfo.AdminUser.Id,
  1999. // Status:1,
  2000. //
  2001. // }
  2002. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2003. // fmt.Println("",errcode)
  2004. // }
  2005. // }
  2006. // }
  2007. //
  2008. // }
  2009. //
  2010. // for _, item := range splitIrrigation {
  2011. // for _,it := range mation{
  2012. // if(item == it.SpecificationName){
  2013. // //查询最近一次的透析器
  2014. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2015. // if errcode == gorm.ErrRecordNotFound{
  2016. // //插入数据
  2017. // prepare := models.DialysisBeforePrepare{
  2018. // UserOrgId: adminUserInfo.Org.Id,
  2019. // PatientId: id,
  2020. // RecordDate: recordDate.Unix(),
  2021. // GoodTypeId: it.GoodTypeId,
  2022. // GoodId: it.ID,
  2023. // Count: 1,
  2024. // Ctime: time.Now().Unix(),
  2025. // Creater: adminUserInfo.AdminUser.Id,
  2026. // Status:1,
  2027. //
  2028. // }
  2029. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2030. // fmt.Println(errcode)
  2031. // }
  2032. // }
  2033. // }
  2034. // }
  2035. //}
  2036. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2037. if dialysisPrescription.ID == 0 { //新增
  2038. if appRole.UserType == 2 || appRole.UserType == 1 {
  2039. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2040. }
  2041. prescription.Creater = adminUserInfo.AdminUser.Id
  2042. //针对河间咸得
  2043. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2044. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2045. prescription.DisplaceLiquiPart = 0
  2046. prescription.DisplaceLiquiValue = 0
  2047. }
  2048. }
  2049. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2050. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2051. }
  2052. err := service.AddSigleRecord(&prescription)
  2053. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2054. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2055. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2056. if len(monitorList) > 0 {
  2057. var ultrafiltration_rate float64
  2058. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2059. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2060. var replacement_rate float64
  2061. //乘10 除10是为了保留一位小数
  2062. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2063. var firstOpeateTime = monitorList[0].OperateTime
  2064. for _, item := range monitorList {
  2065. //超滤率
  2066. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2067. //置换率
  2068. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2069. //超滤量
  2070. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2071. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2072. //置换量
  2073. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2074. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2075. }
  2076. }
  2077. }
  2078. //记录日志
  2079. byterequest, _ := json.Marshal(prescription)
  2080. prescriptionLog := models.XtDialysisPrescriptionLog{
  2081. UserOrgId: prescription.UserOrgId,
  2082. Ctime: time.Now().Unix(),
  2083. Mtime: 0,
  2084. ErrLog: string(byterequest),
  2085. AdminUserId: adminUserInfo.AdminUser.Id,
  2086. RecordDate: prescription.RecordDate,
  2087. PatientId: prescription.PatientId,
  2088. Source: "手机端新增保存处方",
  2089. Status: 1,
  2090. }
  2091. service.CreatePrescriptionLog(prescriptionLog)
  2092. finish := models.XtDialysisFinish{
  2093. IsFinish: 1,
  2094. UserOrgId: adminUserInfo.Org.Id,
  2095. Status: 1,
  2096. Ctime: time.Now().Unix(),
  2097. Mtime: 0,
  2098. Module: 1,
  2099. RecordDate: recordDate.Unix(),
  2100. Sourse: 1,
  2101. PatientId: id,
  2102. }
  2103. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2104. if dialysisFinish.ID == 0 {
  2105. service.CreateDialysisFinish(finish)
  2106. }
  2107. //长沙南雅医院,自动生成抗凝剂的临时处方
  2108. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2109. if prescribing_number == 0 {
  2110. prescribing_number = 1
  2111. }
  2112. if prescribing_number == 0 && id == 14682 {
  2113. prescribing_number = 2
  2114. }
  2115. if prescribing_number == 0 && id == 18560 {
  2116. prescribing_number = 2
  2117. }
  2118. advice := models.DoctorAdvice{
  2119. UserOrgId: adminUserInfo.Org.Id,
  2120. PatientId: id,
  2121. GroupNo: 0,
  2122. AdviceType: 2,
  2123. RecordDate: recordDate.Unix(),
  2124. AdviceDate: recordDate.Unix(),
  2125. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2126. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2127. AdviceDesc: "",
  2128. ReminderDate: 0,
  2129. SingleDose: anticoagulant_zongliang,
  2130. SingleDoseUnit: "iu",
  2131. DrugSpec: 0,
  2132. DrugSpecUnit: "",
  2133. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2134. PrescribingNumberUnit: "支",
  2135. DeliveryWay: "静脉注射",
  2136. ExecutionFrequency: "上机前",
  2137. AdviceDoctor: 0,
  2138. Status: 1,
  2139. CreatedTime: time.Now().Unix(),
  2140. UpdatedTime: time.Now().Unix(),
  2141. IsPrescription: 1,
  2142. ExecutionState: 2,
  2143. StopState: 2,
  2144. IsSettle: 2,
  2145. }
  2146. // 查询排班信息
  2147. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2148. if schedulePatient.ID > 0 {
  2149. if schedulePatient.ScheduleType == 1 {
  2150. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2151. }
  2152. if schedulePatient.ScheduleType == 2 {
  2153. advice.StartTime = recordDate.Unix() + 9*60*60
  2154. }
  2155. }
  2156. // 抗凝剂名称
  2157. switch anticoagulant {
  2158. case 1:
  2159. advice.AdviceName = "无肝素"
  2160. break
  2161. case 2:
  2162. advice.AdviceName = "普通肝素"
  2163. break
  2164. case 3:
  2165. advice.AdviceName = "低分子肝素"
  2166. break
  2167. case 4:
  2168. advice.AdviceName = "阿加曲班"
  2169. break
  2170. case 5:
  2171. advice.AdviceName = "枸橼酸钠"
  2172. break
  2173. case 6:
  2174. advice.AdviceName = "低分子肝素钙"
  2175. break
  2176. case 7:
  2177. advice.AdviceName = "低分子肝素钠"
  2178. break
  2179. case 8:
  2180. advice.AdviceName = "依诺肝素"
  2181. break
  2182. case 9:
  2183. advice.AdviceName = "达肝素"
  2184. break
  2185. case 10:
  2186. advice.AdviceName = "体外抗凝"
  2187. break
  2188. case 11:
  2189. advice.AdviceName = "那曲肝素"
  2190. break
  2191. case 12:
  2192. advice.AdviceName = "无抗凝剂"
  2193. break
  2194. }
  2195. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2196. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2197. advice.AdviceDoctor = appRole.AdminUserId
  2198. }
  2199. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2200. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2201. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2202. advice.AdviceName = "低分子肝素钠注射液"
  2203. // 修改患者临时医嘱里的抗凝剂医嘱
  2204. advice.ID = advicePrescription.ID
  2205. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2206. } else {
  2207. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2208. advice.AdviceName = "低分子肝素钠注射液"
  2209. // 新增患者临时医嘱里的抗凝剂医嘱
  2210. service.CreateDoctorAdvice(&advice)
  2211. }
  2212. }
  2213. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2214. redis := service.RedisClient()
  2215. defer redis.Close()
  2216. //清空key 值
  2217. redis.Set(key, "", time.Second)
  2218. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2219. redis.Set(keyOne, "", time.Second)
  2220. }
  2221. //获取key,清空redis
  2222. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2223. redis := service.RedisClient()
  2224. //清空key 值
  2225. redis.Set(key, "", time.Second)
  2226. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2227. //清空key 值
  2228. redis.Set(keyOne, "", time.Second)
  2229. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2230. //清空key 值
  2231. redis.Set(keyTwo, "", time.Second)
  2232. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2233. redis.Set(keySix, "", time.Second)
  2234. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2235. redis.Set(keySeven, "", time.Second)
  2236. if err == nil {
  2237. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2238. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2239. //清空key 值
  2240. redis.Set(keyThree, "", time.Second)
  2241. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2242. //清空key 值
  2243. redis.Set(keyFour, "", time.Second)
  2244. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2245. redis.Set(keyFive, "", time.Second)
  2246. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2247. redis.Set(keySix, "", time.Second)
  2248. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2249. redis.Set(keySeven, "", time.Second)
  2250. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2251. //清空key 值
  2252. redis.Set(keyOne, "", time.Second)
  2253. if updateErr != nil {
  2254. utils.ErrorLog("%v", updateErr)
  2255. }
  2256. defer redis.Close()
  2257. c.ServeSuccessJSON(map[string]interface{}{
  2258. "prescription": prescription,
  2259. })
  2260. }
  2261. } else { //修改
  2262. //if mode_id > 0 {
  2263. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2264. //}
  2265. //if template.TemplateId == 1 {
  2266. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2267. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2268. // if getPermissionErr != nil {
  2269. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2270. // return
  2271. // } else if headNursePermission == nil {
  2272. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2273. // return
  2274. // }
  2275. // }
  2276. //}
  2277. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2278. prescription.Modifier = adminUserInfo.AdminUser.Id
  2279. if appRole.UserType == 2 || appRole.UserType == 1 {
  2280. prescription_doctor := adminUserInfo.AdminUser.Id
  2281. prescription.PrescriptionDoctor = prescription_doctor
  2282. } else {
  2283. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2284. }
  2285. if dialysisPrescription.Creater == 0 { //体重称
  2286. prescription.Creater = adminUserInfo.AdminUser.Id
  2287. } else {
  2288. prescription.Creater = dialysisPrescription.Creater
  2289. if adminUserInfo.Org.Id == 9882 {
  2290. if appRole.UserType == 2 || appRole.UserType == 1 {
  2291. prescription_doctor := adminUserInfo.AdminUser.Id
  2292. prescription.PrescriptionDoctor = prescription_doctor
  2293. prescription.Creater = prescription_doctor
  2294. }
  2295. }
  2296. }
  2297. prescription.ID = dialysisPrescription.ID
  2298. if adminUserInfo.Org.Id == 10721 {
  2299. if prescription.ModeId == 2 {
  2300. if prescription.ReplacementTotal == 0 {
  2301. prescription.ReplacementTotal = 15
  2302. }
  2303. }
  2304. }
  2305. service.UpDateDialysisPrescription(&prescription)
  2306. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2307. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2308. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2309. if len(monitorList) > 0 {
  2310. var ultrafiltration_rate float64
  2311. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2312. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2313. var replacement_rate float64
  2314. //乘10 除10是为了保留一位小数
  2315. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2316. var firstOpeateTime = monitorList[0].OperateTime
  2317. for _, item := range monitorList {
  2318. //超滤率
  2319. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2320. //置换率
  2321. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2322. //超滤量
  2323. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2324. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2325. //置换量
  2326. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2327. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2328. }
  2329. }
  2330. }
  2331. //记录日志
  2332. byterequest, _ := json.Marshal(prescription)
  2333. prescriptionLog := models.XtDialysisPrescriptionLog{
  2334. UserOrgId: prescription.UserOrgId,
  2335. Ctime: time.Now().Unix(),
  2336. Mtime: 0,
  2337. ErrLog: string(byterequest),
  2338. AdminUserId: adminUserInfo.AdminUser.Id,
  2339. RecordDate: prescription.RecordDate,
  2340. PatientId: prescription.PatientId,
  2341. Source: "手机端修改处方",
  2342. Status: 1,
  2343. }
  2344. service.CreatePrescriptionLog(prescriptionLog)
  2345. finish := models.XtDialysisFinish{
  2346. IsFinish: 1,
  2347. UserOrgId: adminUserInfo.Org.Id,
  2348. Status: 1,
  2349. Ctime: time.Now().Unix(),
  2350. Mtime: 0,
  2351. Module: 1,
  2352. RecordDate: recordDate.Unix(),
  2353. Sourse: 1,
  2354. PatientId: id,
  2355. }
  2356. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2357. if dialysisFinish.ID == 0 {
  2358. service.CreateDialysisFinish(finish)
  2359. }
  2360. //修改处方
  2361. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2362. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2363. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2364. if advicePrescription.ID > 0 {
  2365. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2366. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2367. redis := service.RedisClient()
  2368. defer redis.Close()
  2369. //清空key 值
  2370. redis.Set(key, "", time.Second)
  2371. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2372. redis.Set(keyOne, "", time.Second)
  2373. }
  2374. }
  2375. //获取key,清空redis
  2376. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2377. redis := service.RedisClient()
  2378. //清空key 值
  2379. redis.Set(key, "", time.Second)
  2380. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2381. //清空key 值
  2382. redis.Set(keyOne, "", time.Second)
  2383. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2384. redis.Set(keySix, "", time.Second)
  2385. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2386. redis.Set(keySeven, "", time.Second)
  2387. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2388. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2389. //清空key 值
  2390. redis.Set(keyTwoOne, "", time.Second)
  2391. defer redis.Close()
  2392. if updateErr != nil {
  2393. utils.ErrorLog("%v", updateErr)
  2394. }
  2395. c.ServeSuccessJSON(map[string]interface{}{
  2396. "prescription": prescription,
  2397. })
  2398. }
  2399. }
  2400. func (c *DialysisAPIController) Finish() {
  2401. id, _ := c.GetInt64("patient", 0)
  2402. recordDateStr := c.GetString("record_date")
  2403. nurseID, _ := c.GetInt64("nurse")
  2404. end_time := c.GetString("end_time")
  2405. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2406. internal_fistula := c.GetString("blood_access_internal_fistula")
  2407. catheter := c.GetString("catheter")
  2408. cruor := c.GetString("cruor")
  2409. mission := c.GetString("mission")
  2410. condenser := c.GetString("condenser")
  2411. if id <= 0 || nurseID <= 0 {
  2412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2413. return
  2414. }
  2415. adminUserInfo := c.GetMobileAdminUserInfo()
  2416. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2417. if patient.ID == 0 {
  2418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2419. return
  2420. }
  2421. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2422. if getNurseErr != nil {
  2423. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2425. return
  2426. } else if nurse == nil {
  2427. c.ErrorLog("护士不存在")
  2428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2429. return
  2430. }
  2431. if len(recordDateStr) == 0 {
  2432. recordDateStr = time.Now().Format("2006-01-02")
  2433. }
  2434. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2435. if parseDateErr != nil {
  2436. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2438. return
  2439. }
  2440. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2441. if parseEndDateErr != nil {
  2442. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2444. return
  2445. }
  2446. // 查询信息规挡的设置天数
  2447. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2448. if infor.ID > 0 && infor.WeekDay > 0 {
  2449. var cha_time int64
  2450. timeNowStr := time.Now().Format("2006-01-02")
  2451. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2452. //今日的日期减去设置的日期
  2453. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2454. if cha_time >= recordDate.Unix() {
  2455. //查询审核是否允许
  2456. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2457. //申请状态不允许的情况 拒绝修改
  2458. if infor.ApplicationStatus != 1 {
  2459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2460. return
  2461. }
  2462. }
  2463. }
  2464. //now := time.Now()
  2465. //year, month, day := now.Date()
  2466. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2467. //todayTimeStamp := today_time.Unix()
  2468. // 获取当天的第一条透析纪录
  2469. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2470. if getMonitorRecordsErr != nil {
  2471. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2473. return
  2474. }
  2475. // 获取当前的最后一条透析纪录
  2476. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2477. if getMonitorRecordsErr != nil {
  2478. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2480. return
  2481. }
  2482. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2483. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2484. if getAADErr != nil {
  2485. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2487. return
  2488. }
  2489. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2490. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2491. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2492. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2493. if assessmentAfterDislysis != nil {
  2494. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2495. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2496. } else {
  2497. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2498. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2499. tempassessmentAfterDislysis.Status = 1
  2500. tempassessmentAfterDislysis.PatientId = id
  2501. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2502. }
  2503. //长沙南雅
  2504. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2505. //获取最后一条透析处方数据
  2506. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2507. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2508. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2509. }
  2510. if dialysisOrder.Stage == 1 {
  2511. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2512. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2513. fmt.Println(value)
  2514. a, b := math.Modf(value)
  2515. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2516. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2517. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2518. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2519. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2520. }
  2521. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2522. //var num1 int64
  2523. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2524. //fmt.Println(num1)
  2525. //sub := float64(num1 / 3600)
  2526. //fmt.Println(sub)
  2527. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2528. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2529. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2530. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2531. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2532. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2533. if adminUserInfo.Org.Id != 10375 {
  2534. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2535. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2536. }
  2537. if adminUserInfo.Org.Id != 10445 {
  2538. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2539. }
  2540. //北方营口医院
  2541. if adminUserInfo.Org.Id == 10445 {
  2542. //获取最后一条透析处方数据
  2543. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2544. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2545. } else {
  2546. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2547. }
  2548. //新化博翔
  2549. if adminUserInfo.Org.Id == 10447 {
  2550. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2551. }
  2552. //阳春
  2553. if adminUserInfo.Org.Id == 10485 {
  2554. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2555. }
  2556. if adminUserInfo.Org.Id == 10551 {
  2557. //获取最后一条透析处方数据
  2558. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2559. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2560. }
  2561. if adminUserInfo.Org.Id == 10580 {
  2562. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2563. }
  2564. if adminUserInfo.Org.Id == 10612 {
  2565. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2566. }
  2567. //孝康
  2568. if adminUserInfo.Org.Id == 10693 {
  2569. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2570. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2571. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2572. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2573. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2574. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2575. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2576. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2577. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2578. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2579. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2580. }
  2581. if adminUserInfo.Org.Id == 10721 {
  2582. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2583. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2584. }
  2585. if adminUserInfo.Org.Id == 10697 {
  2586. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2587. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2588. lastWeightAfter.LastAfterWeight = floatAfeter
  2589. }
  2590. if adminUserInfo.Org.Id == 10624 {
  2591. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2592. }
  2593. }
  2594. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10693 || adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10735 {
  2595. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2596. if adminUserInfo.Org.Id != 10702 {
  2597. if evaluation.SystolicBloodPressure == 0 {
  2598. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2599. if adminUserInfo.Org.Id == 10693 {
  2600. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2601. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2602. }
  2603. pre := models.PredialysisEvaluation{
  2604. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2605. }
  2606. fmt.Println("prew", pre)
  2607. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2608. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2609. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2610. redis := service.RedisClient()
  2611. redis.Set(key, "", time.Second)
  2612. redis.Set(keyOne, "", time.Second)
  2613. defer redis.Close()
  2614. fmt.Println(getNurseErr)
  2615. }
  2616. }
  2617. if adminUserInfo.Org.Id != 10702 {
  2618. if evaluation.DiastolicBloodPressure == 0 {
  2619. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2620. if adminUserInfo.Org.Id == 10693 {
  2621. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2622. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2623. }
  2624. pres := models.PredialysisEvaluation{
  2625. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2626. }
  2627. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2628. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2629. redis := service.RedisClient()
  2630. redis.Set(key, "", time.Second)
  2631. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2632. redis.Set(keyOne, "", time.Second)
  2633. defer redis.Close()
  2634. fmt.Println(getNurseErr)
  2635. }
  2636. }
  2637. if adminUserInfo.Org.Id != 10702 {
  2638. if evaluation.PulseFrequency == 0 {
  2639. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2640. if adminUserInfo.Org.Id == 10693 {
  2641. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2642. evaluation.PulseFrequency = pulseFrequency
  2643. }
  2644. press := models.PredialysisEvaluation{
  2645. PulseFrequency: evaluation.PulseFrequency,
  2646. }
  2647. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2648. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2649. redis := service.RedisClient()
  2650. redis.Set(key, "", time.Second)
  2651. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2652. redis.Set(keyOne, "", time.Second)
  2653. defer redis.Close()
  2654. fmt.Println(getNurseErr)
  2655. }
  2656. }
  2657. if evaluation.Temperature == 0 {
  2658. evaluation.Temperature = fmonitorRecords.Temperature
  2659. press := models.PredialysisEvaluation{
  2660. Temperature: evaluation.Temperature,
  2661. }
  2662. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2663. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2664. redis := service.RedisClient()
  2665. redis.Set(key, "", time.Second)
  2666. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2667. redis.Set(keyOne, "", time.Second)
  2668. defer redis.Close()
  2669. fmt.Println(getNurseErr)
  2670. }
  2671. }
  2672. if adminUserInfo.Org.Id == 9583 {
  2673. //获取透析处方的最后一条数据
  2674. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2675. if diaerr != nil {
  2676. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2678. return
  2679. }
  2680. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2681. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2682. }
  2683. }
  2684. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2685. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2686. }
  2687. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2688. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2689. }
  2690. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2691. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2692. }
  2693. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2694. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2695. }
  2696. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2697. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2698. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2699. }
  2700. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2701. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2702. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2703. }
  2704. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2705. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2706. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2707. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2708. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2709. }
  2710. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10735 {
  2711. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2712. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2713. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2714. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2715. }
  2716. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2717. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2718. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2719. }
  2720. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2721. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2722. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2723. }
  2724. if lastAssessmentAfterDislysis != nil {
  2725. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2726. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2727. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2728. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2729. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2730. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2731. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2732. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2733. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2734. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2735. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2736. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2737. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2738. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2739. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2740. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2741. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2742. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2743. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2744. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2745. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2746. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2747. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2748. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2749. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2750. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2751. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2752. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2753. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2754. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2755. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2756. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2757. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2758. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2759. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2760. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2761. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2762. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2763. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2764. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2765. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2766. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2767. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2768. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2769. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2770. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2771. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2772. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2773. if tempassessmentAfterDislysis.PatientId == 18695 {
  2774. tempassessmentAfterDislysis.ActualDisplacement = 0
  2775. }
  2776. if adminUserInfo.Org.Id != 10375 {
  2777. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2778. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2779. }
  2780. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2781. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2782. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2783. }
  2784. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2785. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2786. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2787. }
  2788. }
  2789. finish := models.XtDialysisFinish{
  2790. IsFinish: 1,
  2791. UserOrgId: adminUserInfo.Org.Id,
  2792. Status: 1,
  2793. Ctime: time.Now().Unix(),
  2794. Mtime: 0,
  2795. Module: 9,
  2796. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2797. Sourse: 1,
  2798. PatientId: tempassessmentAfterDislysis.PatientId,
  2799. }
  2800. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2801. if dialysisFinish.ID == 0 {
  2802. service.CreateDialysisFinish(finish)
  2803. }
  2804. //孝康
  2805. if adminUserInfo.Org.Id == 10693 {
  2806. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2807. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2808. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2809. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2810. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2811. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2812. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2813. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2814. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2815. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2816. }
  2817. if adminUserInfo.Org.Id == 10697 {
  2818. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2819. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2820. lastWeightAfter.LastAfterWeight = floatAfeter
  2821. }
  2822. if adminUserInfo.Org.Id == 10721 {
  2823. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2824. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2825. }
  2826. tempassessmentAfterDislysis.RecordTime = dialysisOrder.EndTime
  2827. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2828. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2829. redis := service.RedisClient()
  2830. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2831. redis.Set(keyOne, "", time.Second)
  2832. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2833. redis.Set(keyTwo, "", time.Second)
  2834. defer redis.Close()
  2835. //清空key 值
  2836. redis.Set(key, "", time.Second)
  2837. if err != nil {
  2838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2839. return
  2840. }
  2841. if dialysisOrder == nil {
  2842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2843. return
  2844. }
  2845. if dialysisOrder.Stage == 2 {
  2846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2847. return
  2848. }
  2849. if dialysisOrder.Stage == 1 {
  2850. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2851. finish := models.XtDialysisFinish{
  2852. IsFinish: 1,
  2853. UserOrgId: adminUserInfo.Org.Id,
  2854. Status: 1,
  2855. Ctime: time.Now().Unix(),
  2856. Mtime: 0,
  2857. Module: 8,
  2858. RecordDate: recordDate.Unix(),
  2859. Sourse: 1,
  2860. PatientId: id,
  2861. }
  2862. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2863. if dialysisFinish.ID == 0 {
  2864. service.CreateDialysisFinish(finish)
  2865. }
  2866. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2867. redis := service.RedisClient()
  2868. defer redis.Close()
  2869. //清空key 值
  2870. redis.Set(key, "", time.Second)
  2871. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2872. redis.Set(keyOne, "", time.Second)
  2873. //结束时候透析次数加1
  2874. service.UpdateSolutionByPatientId(id)
  2875. //下机完自动消毒,针对长沙南雅
  2876. if dialysisOrder.Stage == 1 {
  2877. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 || adminUserInfo.Org.Id == 10612 {
  2878. //根据床位号获取设备型号
  2879. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2880. //查询使用消毒最后一条消毒记录
  2881. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2882. fmt.Println("err", err)
  2883. if err == gorm.ErrRecordNotFound {
  2884. //查找排班
  2885. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2886. //查询改设备是否有消毒计划
  2887. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2888. //根据床位号获取设备id
  2889. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2890. //查询病人信息
  2891. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2892. var con = ""
  2893. if patients.IsInfectious == 0 {
  2894. con = ""
  2895. }
  2896. if patients.IsInfectious == 1 {
  2897. con = "无"
  2898. }
  2899. if patients.IsInfectious == 2 {
  2900. con = "有"
  2901. }
  2902. if errcode == nil {
  2903. var end_time int64
  2904. end_time = endDate.Unix() + plan.DisinfecTime*60
  2905. //新增消毒
  2906. information := models.DeviceInformation{
  2907. Date: dialysisOrder.DialysisDate,
  2908. Zone: dialysisOrder.ZoneId,
  2909. Class: dialysisOrder.SchedualType,
  2910. BedNumber: dialysisOrder.BedID,
  2911. PatientId: dialysisOrder.PatientId,
  2912. DialysisMode: scheduleByPatient.ModeId,
  2913. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2914. Disinfection: 1,
  2915. DialysisConcentration: 1,
  2916. DisinfectionStatus: 1,
  2917. Move: 1,
  2918. UserOrgId: dialysisOrder.UserOrgId,
  2919. DisinfectType: plan.Way,
  2920. DisinfectantType: plan.MachineDisinfectant,
  2921. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2922. Disinfectant: plan.Disinfectant,
  2923. Ctime: time.Now().Unix(),
  2924. Status: 1,
  2925. SignName: nurseID,
  2926. EquimentId: addmacher.ID,
  2927. DisinfectionResidue: 2,
  2928. Bed: addmacher.BedNumber,
  2929. StartTime: dialysisOrder.StartTime,
  2930. EndTime: dialysisOrder.EndTime,
  2931. Contagion: con,
  2932. WeightLoss: 0,
  2933. Hyperfiltratio: 0,
  2934. DialysisHour: "",
  2935. MachineRun: 1,
  2936. DisinfecStartime: endDate.Unix(),
  2937. DisinfecEndtime: end_time,
  2938. }
  2939. err := service.CreateInformationTwo(&information)
  2940. fmt.Println("报错", err)
  2941. }
  2942. }
  2943. }
  2944. }
  2945. dialysisOrder.Stage = 2
  2946. dialysisOrder.FinishNurse = nurseID
  2947. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2948. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2949. dialysisOrder.EndTime = endDate.Unix()
  2950. // 长沙南雅需求
  2951. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2952. //获取最后1条监测的数据
  2953. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2954. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2955. var accumulatedBloodVolume float64
  2956. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2957. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2958. fmt.Println(err)
  2959. // 查询未执行的医嘱
  2960. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2961. for _, item := range doctorAdvice {
  2962. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2963. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2964. redis := service.RedisClient()
  2965. //清空key 值
  2966. redis.Set(key, "", time.Second)
  2967. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2968. redis.Set(keyTwo, "", time.Second)
  2969. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2970. redis.Set(keyThree, "", time.Second)
  2971. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2972. theTime := toTime.Format("2006-01-02")
  2973. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2974. redis.Set(keyFour, "", time.Second)
  2975. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2976. redis.Set(keyFive, "", time.Second)
  2977. defer redis.Close()
  2978. }
  2979. }
  2980. go func() {
  2981. ssoDomain := beego.AppConfig.String("call_domain")
  2982. api := ssoDomain + "/index/downpatient"
  2983. values := make(url.Values)
  2984. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2985. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2986. values.Set("patient_id", strconv.FormatInt(id, 10))
  2987. http.PostForm(api, values)
  2988. }()
  2989. if err == nil {
  2990. c.ServeSuccessJSON(map[string]interface{}{
  2991. "dialysisOrder": dialysisOrder,
  2992. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2993. })
  2994. } else {
  2995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2996. }
  2997. }
  2998. }
  2999. func (c *DialysisAPIController) GetAllZone() {
  3000. adminUserInfo := c.GetMobileAdminUserInfo()
  3001. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  3002. if err == nil {
  3003. c.ServeSuccessJSON(map[string]interface{}{
  3004. "zone": zone,
  3005. })
  3006. }
  3007. }
  3008. func (c *DialysisAPIController) GetSchedualPatientsList() {
  3009. adminUserInfo := c.GetMobileAdminUserInfo()
  3010. page, _ := c.GetInt64("page", 1)
  3011. limit, _ := c.GetInt64("limit", 10)
  3012. schedulType, _ := c.GetInt64("schedul_type", 0)
  3013. startTime, _ := c.GetInt64("schedul_time", 0)
  3014. partitionType, _ := c.GetInt64("partition_type", 0)
  3015. keywords := c.GetString("keywords")
  3016. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  3017. if err == nil {
  3018. c.ServeSuccessJSON(map[string]interface{}{
  3019. "schedule": dialysisSchedule,
  3020. })
  3021. }
  3022. return
  3023. }
  3024. // /m/api/dialysis/start [post]
  3025. // @param patient_id:int
  3026. // @param record_date:string 排班时间 (yyyy-mm-dd)
  3027. // @param nurse:int 上机护士
  3028. // @param bed:int 床位号
  3029. func (this *DialysisAPIController) StartDialysis() {
  3030. patientID, _ := this.GetInt64("patient_id")
  3031. recordDateStr := this.GetString("record_date")
  3032. nurseID, _ := this.GetInt64("start_nurse")
  3033. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3034. blood_drawing, _ := this.GetInt64("blood_drawing")
  3035. schedual_type, _ := this.GetInt64("schedual_type")
  3036. bedID, _ := this.GetInt64("bed")
  3037. start_time := this.GetString("start_time")
  3038. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3039. change_nurse, _ := this.GetInt64("change_nurse")
  3040. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3041. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3042. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3043. puncture_needle := this.GetString("puncture_needle")
  3044. puncture_way := this.GetString("puncture_way")
  3045. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3046. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3047. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3048. zone_id, _ := this.GetInt64("zone_id")
  3049. elecsign := this.GetString("url")
  3050. nuclein_date_str := this.GetString("nuclein_date_str")
  3051. schedule_remark := this.GetString("schedule_remark")
  3052. order_remark := this.GetString("order_remark")
  3053. catheter_operation := this.GetString("catheter_operation")
  3054. blood_flow_volume := this.GetString("blood_flow_volume")
  3055. dialysis_strainer := this.GetString("dialysis_strainer")
  3056. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3057. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3058. return
  3059. }
  3060. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3061. if parseStartDateErr != nil {
  3062. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3063. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3064. return
  3065. }
  3066. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3067. if parseErr != nil {
  3068. this.ErrorLog("时间解析失败:%v", parseErr)
  3069. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3070. return
  3071. }
  3072. adminUserInfo := this.GetMobileAdminUserInfo()
  3073. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3074. if getPatientErr != nil {
  3075. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3077. return
  3078. } else if patient == nil {
  3079. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3080. return
  3081. }
  3082. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3083. if getNurseErr != nil {
  3084. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3085. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3086. return
  3087. } else if nurse == nil {
  3088. this.ErrorLog("护士不存在")
  3089. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3090. return
  3091. }
  3092. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3093. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3094. if getDeviceNumberErr != nil {
  3095. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3096. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3097. return
  3098. } else if deviceNumber == nil {
  3099. this.ErrorLog("床位号不存在")
  3100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3101. return
  3102. }
  3103. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3104. if getRecordErr != nil {
  3105. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3106. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3107. return
  3108. } else if dialysisRecord != nil {
  3109. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3110. return
  3111. }
  3112. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3113. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3114. timeLayout := "2006-01-02 15:04:05"
  3115. loc, _ := time.LoadLocation("Local")
  3116. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3117. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3118. schedulestartTime := theStartTime.Unix()
  3119. scheduleendTime := theEndTime.Unix()
  3120. var theNucleinDate int64
  3121. timeLayoutOne := "2006-01-02"
  3122. if len(nuclein_date_str) > 0 {
  3123. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3124. if err != nil {
  3125. utils.ErrorLog(err.Error())
  3126. }
  3127. theNucleinDate = theTime.Unix()
  3128. }
  3129. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3130. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3131. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3132. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3133. //查询该床位是否有人用了
  3134. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3135. if err == gorm.ErrRecordNotFound { //空床位
  3136. // 修改了床位逻辑
  3137. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3138. if daySchedule.ID > 0 {
  3139. daySchedule.PartitionId = deviceNumber.ZoneID
  3140. daySchedule.BedId = bedID
  3141. daySchedule.ScheduleType = schedual_type
  3142. daySchedule.UpdatedTime = time.Now().Unix()
  3143. xtSchedule := models.Schedule{
  3144. PartitionId: deviceNumber.ZoneID,
  3145. BedId: bedID,
  3146. ScheduleType: schedual_type,
  3147. UpdatedTime: time.Now().Unix(),
  3148. }
  3149. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3150. if err != nil {
  3151. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3152. return
  3153. }
  3154. }
  3155. } else if err == nil {
  3156. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3157. if order.ID > 0 { //该机位被其他人占用了
  3158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3159. return
  3160. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3161. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3162. if daySchedule.ID > 0 {
  3163. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3164. if err != nil {
  3165. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3166. return
  3167. }
  3168. }
  3169. }
  3170. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3171. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3172. return
  3173. }
  3174. //else if order.ID == 0 { //该床位没被占用
  3175. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3176. // if daySchedule.ID > 0 {
  3177. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3178. // //daySchedule.BedId = bedID
  3179. // //daySchedule.ScheduleType = schedual_type
  3180. // //daySchedule.UpdatedTime = time.Now().Unix()
  3181. // //err := service.UpdateSchedule(&daySchedule)
  3182. // xtSchedule := models.Schedule{
  3183. // PartitionId: deviceNumber.ZoneID,
  3184. // BedId: bedID,
  3185. // ScheduleType: schedual_type,
  3186. // UpdatedTime: time.Now().Unix(),
  3187. // }
  3188. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3189. // if err != nil {
  3190. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3191. // return
  3192. // }
  3193. // }
  3194. //}
  3195. //}
  3196. } else if err != nil {
  3197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3198. return
  3199. }
  3200. // 查询信息规挡的设置天数
  3201. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3202. if infor.ID > 0 && infor.WeekDay > 0 {
  3203. var cha_time int64
  3204. timeNowStr := time.Now().Format("2006-01-02")
  3205. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3206. //今日的日期减去设置的日期
  3207. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3208. if cha_time >= recordDate.Unix() {
  3209. //查询审核是否允许
  3210. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3211. //申请状态不允许的情况 拒绝修改
  3212. if infor.ApplicationStatus != 1 {
  3213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3214. return
  3215. }
  3216. }
  3217. }
  3218. dialysisRecord = &models.DialysisOrder{
  3219. DialysisDate: recordDate.Unix(),
  3220. UserOrgId: adminUserInfo.Org.Id,
  3221. PatientId: patientID,
  3222. Stage: 1,
  3223. BedID: bedID,
  3224. StartNurse: nurseID,
  3225. Status: 1,
  3226. StartTime: startDate.Unix(),
  3227. CreatedTime: time.Now().Unix(),
  3228. UpdatedTime: time.Now().Unix(),
  3229. PunctureNurse: puncture_nurse,
  3230. Creator: adminUserInfo.AdminUser.Id,
  3231. Modifier: adminUserInfo.AdminUser.Id,
  3232. SchedualType: schedual_type,
  3233. WashpipeNurse: washpipe_nurse,
  3234. ChangeNurse: change_nurse,
  3235. DifficultPunctureNurse: difficult_puncture_nurse,
  3236. NewFistulaNurse: new_fistula_nurse,
  3237. ZoneId: zone_id,
  3238. QualityNurseId: quality_nurse_id,
  3239. PunctureNeedle: puncture_needle,
  3240. PunctureWay: puncture_way,
  3241. DialysisIrrigation: dialysis_irrigation,
  3242. DialysisDialyszers: dialysis_dialyszers,
  3243. BloodAccessId: blood_access_id,
  3244. Url: elecsign,
  3245. NucleinDate: theNucleinDate,
  3246. ScheduleRemark: schedule_remark,
  3247. OrderRemark: order_remark,
  3248. CatheterOperation: catheter_operation,
  3249. BloodFlowVolume: blood_flow_volume,
  3250. BloodDrawing: blood_drawing,
  3251. DialysisStrainer: dialysis_strainer,
  3252. }
  3253. //查询该床位是否有人用了
  3254. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3255. if errorscode == gorm.ErrRecordNotFound {
  3256. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3257. finish := models.XtDialysisFinish{
  3258. IsFinish: 1,
  3259. UserOrgId: adminUserInfo.Org.Id,
  3260. Status: 1,
  3261. Ctime: time.Now().Unix(),
  3262. Mtime: 0,
  3263. Module: 6,
  3264. RecordDate: schedulestartTime,
  3265. Sourse: 1,
  3266. PatientId: patientID,
  3267. }
  3268. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3269. if dialysisFinish.ID == 0 {
  3270. service.CreateDialysisFinish(finish)
  3271. }
  3272. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3273. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3274. //统计该患者总次数
  3275. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3276. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3277. }
  3278. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3279. //统计该患者总次数
  3280. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3281. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3282. }
  3283. redis := service.RedisClient()
  3284. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3285. redis.Set(key, "", time.Second)
  3286. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3287. //清空key 值
  3288. redis.Set(keyOne, "", time.Second)
  3289. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3290. //清空key 值
  3291. redis.Set(keyTwo, "", time.Second)
  3292. if createErr != nil {
  3293. this.ErrorLog("上机失败:%v", createErr)
  3294. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3295. return
  3296. }
  3297. }
  3298. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3299. var tempdispose string
  3300. // 只针对中能建
  3301. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3302. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3303. }
  3304. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3305. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3306. }
  3307. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3308. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3309. //}
  3310. var ultrafiltration_rate float64
  3311. var ultrafiltration_rate_one string
  3312. var replacement_rate float64
  3313. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3314. //后期预增脱水量
  3315. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3316. if prescription.ID > 0 {
  3317. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3318. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3319. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375 || adminUserInfo.Org.Id == 10599 || adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10740 || adminUserInfo.Org.Id == 10745) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  3320. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3321. }
  3322. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3323. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3324. }
  3325. //针对医师汇
  3326. if adminUserInfo.Org.Id == 10121 {
  3327. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3328. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3329. }
  3330. //针对通道
  3331. if adminUserInfo.Org.Id == 10234 {
  3332. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3333. }
  3334. //针对监利大垸医院
  3335. if template.TemplateId == 41 {
  3336. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3337. }
  3338. //针对肇庆三鹤血液透析中心
  3339. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3340. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3341. }
  3342. if adminUserInfo.Org.Id == 10469 {
  3343. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3344. }
  3345. if adminUserInfo.Org.Id == 10667 {
  3346. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3347. }
  3348. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3349. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3350. }
  3351. // 只针对方济医院
  3352. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3353. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3354. ultrafiltration_rate = value
  3355. }
  3356. //针对
  3357. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3358. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3359. ultrafiltration_rate = ultrafiltration_rate / 1000
  3360. }
  3361. if adminUserInfo.Org.Id == 10551 {
  3362. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3363. ultrafiltration_rate = ultrafiltration_rate / 1000
  3364. }
  3365. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3366. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3367. ultrafiltration_rate = ultrafiltration_rate / 1000
  3368. }
  3369. if adminUserInfo.Org.Id == 10580 {
  3370. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3371. ultrafiltration_rate = ultrafiltration_rate / 1000
  3372. }
  3373. if adminUserInfo.Org.Id == 10629 {
  3374. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3375. ultrafiltration_rate = ultrafiltration_rate / 1000
  3376. }
  3377. if adminUserInfo.Org.Id == 10644 {
  3378. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3379. ultrafiltration_rate = ultrafiltration_rate / 1000
  3380. }
  3381. if adminUserInfo.Org.Id == 10667 {
  3382. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3383. ultrafiltration_rate = ultrafiltration_rate / 1000
  3384. }
  3385. if adminUserInfo.Org.Id == 10693 {
  3386. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3387. ultrafiltration_rate = ultrafiltration_rate
  3388. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3389. }
  3390. if adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10731 {
  3391. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3392. ultrafiltration_rate = ultrafiltration_rate
  3393. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3394. }
  3395. if adminUserInfo.Org.Id == 10206 {
  3396. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60)
  3397. ultrafiltration_rate = ultrafiltration_rate
  3398. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3399. }
  3400. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3401. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3402. ultrafiltration_rate = ultrafiltration_rate
  3403. }
  3404. if adminUserInfo.Org.Id == 10702 {
  3405. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3406. ultrafiltration_rate = ultrafiltration_rate / 1000
  3407. }
  3408. if adminUserInfo.Org.Id == 10723 {
  3409. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3410. ultrafiltration_rate = ultrafiltration_rate / 1000
  3411. }
  3412. if adminUserInfo.Org.Id == 10721 {
  3413. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3414. ultrafiltration_rate = ultrafiltration_rate / 1000
  3415. }
  3416. if adminUserInfo.Org.Id == 10721 {
  3417. if prescription.ModeId == 2 {
  3418. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3419. if totalMin == 0 {
  3420. totalMin = 240
  3421. }
  3422. if prescription.ReplacementTotal == 0 {
  3423. prescription.ReplacementTotal = 15
  3424. }
  3425. //乘10 除10是为了保留一位小数
  3426. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3427. }
  3428. }
  3429. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10731 || adminUserInfo.Org.Id == 10727 {
  3430. if prescription.ModeId == 2 {
  3431. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3432. if totalMin == 0 {
  3433. totalMin = 240
  3434. }
  3435. if prescription.DisplaceLiquiValue == 0 {
  3436. prescription.ReplacementTotal = 32
  3437. }
  3438. //乘10 除10是为了保留一位小数
  3439. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3440. }
  3441. }
  3442. }
  3443. }
  3444. if adminUserInfo.Org.Id == 10172 {
  3445. if prescription.ID == 0 {
  3446. if prescription.ModeId == 2 {
  3447. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3448. if totalMin == 0 {
  3449. totalMin = 240
  3450. }
  3451. if prescription.ReplacementTotal == 0 {
  3452. prescription.ReplacementTotal = 15
  3453. }
  3454. //乘10 除10是为了保留一位小数
  3455. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3456. }
  3457. }
  3458. }
  3459. record := models.MonitoringRecord{
  3460. UserOrgId: adminUserInfo.Org.Id,
  3461. PatientId: patientID,
  3462. DialysisOrderId: dialysisRecord.ID,
  3463. MonitoringDate: schedulestartTime,
  3464. OperateTime: startDate.Unix(),
  3465. // MonitoringTime: recordTime,
  3466. MonitoringNurse: nurseID,
  3467. Dispose: tempdispose,
  3468. UltrafiltrationRate: ultrafiltration_rate,
  3469. UltrafiltrationVolume: 0,
  3470. Status: 1,
  3471. CreatedTime: time.Now().Unix(),
  3472. UpdatedTime: time.Now().Unix(),
  3473. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3474. ReplacementRate: replacement_rate,
  3475. }
  3476. //只针对广慈医院
  3477. 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 {
  3478. // 查询病人是否有透前评估数据
  3479. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3480. //如果有数据就插入
  3481. if errcode == nil {
  3482. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3483. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3484. record.BreathingRate = befor.BreathingRate
  3485. record.PulseFrequency = befor.PulseFrequency
  3486. record.Temperature = befor.Temperature
  3487. }
  3488. }
  3489. //孝昌
  3490. if adminUserInfo.Org.Id == 10693 {
  3491. // 查询病人是否有透前评估数据
  3492. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3493. //如果有数据就插入
  3494. if errcode == nil {
  3495. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3496. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3497. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3498. record.BreathingRate = befor.BreathingRate
  3499. }
  3500. }
  3501. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3502. if newdialysisRecord.ID > 0 {
  3503. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3504. record.Temperature = 36.5
  3505. record.ArterialPressure = -100
  3506. record.DialysateTemperature = 36.5
  3507. record.Conductivity = 14
  3508. record.BreathingRate = "20"
  3509. record.VenousPressure = 80
  3510. record.TransmembranePressure = 60
  3511. record.Dispose = catheter_operation
  3512. }
  3513. //针对新化博翔
  3514. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3515. record.BloodOxygenSaturation = "99"
  3516. record.Conductivity = 14
  3517. record.DialysateTemperature = 36.5
  3518. record.BreathingRate = "20"
  3519. }
  3520. //针对兰溪人民医院的需求
  3521. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3522. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3523. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3524. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3525. record.Temperature = befor.Temperature
  3526. record.PulseFrequency = befor.PulseFrequency
  3527. record.BreathingRate = befor.BreathingRate
  3528. }
  3529. //针对乐山友谊医院的需求
  3530. if adminUserInfo.Org.Id == 10677 {
  3531. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3532. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3533. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3534. record.Temperature = befor.Temperature
  3535. record.PulseFrequency = befor.PulseFrequency
  3536. record.BreathingRate = befor.BreathingRate
  3537. }
  3538. //新化博翔
  3539. if adminUserInfo.Org.Id == 10447 {
  3540. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3541. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3542. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3543. record.BreathingRate = befor.BreathingRate
  3544. }
  3545. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3546. record.PulseFrequency = 80
  3547. record.Temperature = 36.5
  3548. }
  3549. //诊断灵山圣康
  3550. if adminUserInfo.Org.Id == 10375 {
  3551. record.Conductivity = 13.8
  3552. record.DialysateTemperature = 37
  3553. record.DialysateFlow = 500
  3554. record.BloodFlowVolume = 200
  3555. record.BreathingRate = "18"
  3556. record.SodiumConcentration = 140
  3557. }
  3558. //江成肾病医院
  3559. if adminUserInfo.Org.Id == 10517 {
  3560. record.SodiumConcentration = 138
  3561. record.DialysateTemperature = 36.5
  3562. }
  3563. //濉溪杏康血液透析中心
  3564. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3565. record.BloodFlowVolume = prescription.BloodFlowVolume
  3566. }
  3567. //胶州少海医院
  3568. if adminUserInfo.Org.Id == 10735 {
  3569. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3570. dialysisPrescription, _ := service.GetDialysisPrescription(patientID, adminUserInfo.Org.Id, recordDate.Unix())
  3571. record.BreathingRate = befor.BreathingRate
  3572. record.BloodFlowVolume = dialysisPrescription.BloodFlowVolume
  3573. record.Temperature = befor.Temperature
  3574. record.PulseFrequency = befor.PulseFrequency
  3575. }
  3576. if adminUserInfo.Org.Id != 10683 {
  3577. err = service.CreateMonitor(&record)
  3578. }
  3579. //记录日志
  3580. byterequest, _ := json.Marshal(record)
  3581. monitorRecordLog := models.XtMonitorRecordLog{
  3582. RecordDate: record.MonitoringDate,
  3583. PatientId: record.PatientId,
  3584. Module: 1,
  3585. AdminUserId: adminUserInfo.AdminUser.Id,
  3586. Ctime: time.Now().Unix(),
  3587. Mtime: 0,
  3588. Status: 1,
  3589. UserOrgId: record.UserOrgId,
  3590. ErrLog: string(byterequest),
  3591. Source: "执行上机时新增监测",
  3592. }
  3593. service.CreateMonitorRecordLog(monitorRecordLog)
  3594. finish := models.XtDialysisFinish{
  3595. IsFinish: 1,
  3596. UserOrgId: adminUserInfo.Org.Id,
  3597. Status: 1,
  3598. Ctime: time.Now().Unix(),
  3599. Mtime: 0,
  3600. Module: 7,
  3601. RecordDate: schedulestartTime,
  3602. Sourse: 1,
  3603. PatientId: patientID,
  3604. }
  3605. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3606. if dialysisFinish.ID == 0 {
  3607. service.CreateDialysisFinish(finish)
  3608. }
  3609. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3610. redis := service.RedisClient()
  3611. //清空key 值
  3612. redis.Set(key, "", time.Second)
  3613. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3614. redis.Set(keyOne, "", time.Second)
  3615. defer redis.Close()
  3616. if err != nil {
  3617. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3618. return
  3619. }
  3620. }
  3621. go func() {
  3622. ssoDomain := beego.AppConfig.String("call_domain")
  3623. api := ssoDomain + "/index/uppatient"
  3624. values := make(url.Values)
  3625. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3626. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3627. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3628. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3629. http.PostForm(api, values)
  3630. }()
  3631. this.ServeSuccessJSON(map[string]interface{}{
  3632. "dialysis_order": newdialysisRecord,
  3633. "monitor": record,
  3634. })
  3635. return
  3636. }
  3637. func (c *DialysisAPIController) PostSolution() {
  3638. id, _ := c.GetInt64("patient", 0)
  3639. recordDateStr := c.GetString("record_date")
  3640. if id <= 0 {
  3641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3642. return
  3643. }
  3644. adminUserInfo := c.GetMobileAdminUserInfo()
  3645. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3646. if patient.ID == 0 {
  3647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3648. return
  3649. }
  3650. if len(recordDateStr) == 0 {
  3651. recordDateStr = time.Now().Format("2006-01-02")
  3652. }
  3653. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3654. if parseDateErr != nil {
  3655. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3657. return
  3658. }
  3659. mode_id, _ := c.GetInt64("mode_id", 0)
  3660. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3661. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3662. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3663. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3664. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3665. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3666. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3667. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3668. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3669. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3670. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3671. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3672. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3673. kalium, _ := c.GetFloat("kalium", 0)
  3674. sodium, _ := c.GetFloat("sodium", 0)
  3675. calcium, _ := c.GetFloat("calcium", 0)
  3676. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3677. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3678. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3679. glucose, _ := c.GetFloat("glucose", 0)
  3680. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3681. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3682. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3683. conductivity, _ := c.GetFloat("conductivity", 0)
  3684. remark := c.GetString("remark")
  3685. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3686. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3687. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3688. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3689. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3690. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3691. special_medicine_other := c.GetString("special_medicine_other")
  3692. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3693. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3694. blood_access, _ := c.GetInt64("blood_access", 0)
  3695. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3696. body_fluid_other := c.GetString("body_fluid_other")
  3697. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3698. niprocart, _ := c.GetInt64("niprocart", 0)
  3699. jms, _ := c.GetInt64("jms", 0)
  3700. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3701. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3702. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3703. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3704. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3705. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3706. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3707. injector, _ := c.GetInt64("injector", 0)
  3708. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3709. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3710. safe_package, _ := c.GetInt64("package", 0)
  3711. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3712. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3713. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3714. blood := c.GetString("blood")
  3715. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3716. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3717. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3718. displace_speed := c.GetString("displace_speed")
  3719. illness, _ := c.GetInt64("illness")
  3720. amylaceum := c.GetString("amylaceum")
  3721. single_time := c.GetString("single_time")
  3722. single_water := c.GetString("single_water")
  3723. replacement_flow := c.GetString("replacement_flow")
  3724. plasma_separator := c.GetString("plasma_separator")
  3725. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3726. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3727. oxygen_flow := c.GetString("oxygen_flow")
  3728. oxygen_time := c.GetString("oxygen_time")
  3729. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3730. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3731. puncture_needle := c.GetString("puncture_needle")
  3732. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3733. epo := c.GetString("epo")
  3734. epo_count, _ := c.GetFloat("epo_count", 0)
  3735. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3736. pre_impulse := c.GetString("pre_impulse")
  3737. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3738. admin_user_id, _ := c.GetInt64("admin_user_id")
  3739. is_water := c.GetString("is_water")
  3740. add_amount, _ := c.GetFloat("add_amount")
  3741. reduce_amount, _ := c.GetFloat("reduce_amount")
  3742. prescribing_number, _ := c.GetFloat("prescribing_number")
  3743. treatment_remark := c.GetString("treatment_remark")
  3744. prescription_sodium := c.GetString("prescription_sodium")
  3745. start_sodium := c.GetString("start_sodium")
  3746. sodium_curve := c.GetString("sodium_curve")
  3747. var is_war int64
  3748. if is_water == "是" {
  3749. is_war = 1
  3750. }
  3751. if is_water == "否" {
  3752. is_war = 2
  3753. }
  3754. if is_water == "请选择" {
  3755. is_war = 0
  3756. }
  3757. drhy_water := c.GetString("drhy_water")
  3758. dry_water_hour := c.GetString("dry_water_hour")
  3759. water_machine := c.GetString("water_machine")
  3760. dialysis_remark := c.GetString("dialysis_remark")
  3761. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3762. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3763. prescription_water, _ := c.GetFloat("prescription_water")
  3764. dialysis_strainer := c.GetString("dialysis_strainer")
  3765. chaptalization := c.GetString("chaptalization")
  3766. washing_time := c.GetString("washing_time")
  3767. warsh_count := c.GetString("warsh_count")
  3768. blood_access_part_id := c.GetString("blood_access_part_id")
  3769. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3770. dialyzate := c.GetString("dialyzate")
  3771. first_super := c.GetString("first_super")
  3772. is_sequential := c.GetString("is_sequential")
  3773. var fisrt_sup int64
  3774. if first_super == "是" {
  3775. fisrt_sup = 1
  3776. }
  3777. if first_super == "否" {
  3778. fisrt_sup = 2
  3779. }
  3780. if first_super == "请选择" {
  3781. fisrt_sup = 0
  3782. }
  3783. var is_sequen int64
  3784. if is_sequential == "是" {
  3785. is_sequen = 1
  3786. }
  3787. if is_sequential == "否" {
  3788. is_sequen = 2
  3789. }
  3790. if is_sequential == "请选择" {
  3791. is_sequen = 0
  3792. }
  3793. conduct := c.GetString("conduct")
  3794. if mode_id > 0 {
  3795. var str string
  3796. //查找该机构用的是什么透析器
  3797. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3798. if filedConfig.ID > 0 {
  3799. str = dialyzerPerfusionApparatus
  3800. } else {
  3801. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3802. }
  3803. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3804. }
  3805. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3806. //
  3807. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3808. // if appRole.UserType == 3 {
  3809. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3810. // if getPermissionErr != nil {
  3811. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3812. // return
  3813. // } else if headNursePermission == nil {
  3814. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3815. // return
  3816. // }
  3817. // }
  3818. //}
  3819. // 查询信息规挡的设置天数
  3820. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3821. if infor.ID > 0 && infor.WeekDay > 0 {
  3822. var cha_time int64
  3823. timeNowStr := time.Now().Format("2006-01-02")
  3824. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3825. //今日的日期减去设置的日期
  3826. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3827. if cha_time >= recordDate.Unix() {
  3828. //查询审核是否允许
  3829. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3830. //申请状态不允许的情况 拒绝修改
  3831. if infor.ApplicationStatus != 1 {
  3832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3833. return
  3834. }
  3835. }
  3836. }
  3837. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  3838. var dialysis_dialyszers_id int64
  3839. var dialysis_strainer_id int64
  3840. var dialysis_irrigation_id int64
  3841. if len(goodList) > 0 {
  3842. for _, item := range goodList {
  3843. if item.SpecificationName == dialysis_dialyszers {
  3844. dialysis_dialyszers_id = item.ID
  3845. }
  3846. if item.SpecificationName == dialysis_irrigation {
  3847. dialysis_irrigation_id = item.ID
  3848. }
  3849. if item.SpecificationName == dialysis_strainer {
  3850. dialysis_strainer_id = item.ID
  3851. }
  3852. }
  3853. }
  3854. prescription := models.DialysisPrescription{
  3855. UserOrgId: adminUserInfo.Org.Id,
  3856. PatientId: id,
  3857. RecordDate: recordDate.Unix(),
  3858. ModeId: mode_id,
  3859. DialysisDuration: dialysis_duration,
  3860. Dialyzer: dialyzer,
  3861. PerfusionApparatus: perfusion_apparatus,
  3862. BloodFlowVolume: blood_flow_volume,
  3863. DewaterAmount: dewater_amount,
  3864. DisplaceLiqui: displace_liqui,
  3865. ReplacementWay: replacement_way,
  3866. Anticoagulant: anticoagulant,
  3867. AnticoagulantShouji: anticoagulant_shouji,
  3868. AnticoagulantWeichi: anticoagulant_weichi,
  3869. AnticoagulantZongliang: anticoagulant_zongliang,
  3870. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3871. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3872. Kalium: kalium,
  3873. Sodium: sodium,
  3874. Calcium: calcium,
  3875. Bicarbonate: bicarbonate,
  3876. Glucose: glucose,
  3877. // DryWeight: dry_weight,
  3878. DialysateFlow: dialysate_flow,
  3879. DialysateTemperature: dialysate_temperature,
  3880. Conductivity: conductivity,
  3881. Remark: remark,
  3882. Status: 1,
  3883. CreatedTime: time.Now().Unix(),
  3884. UpdatedTime: time.Now().Unix(),
  3885. DialysisDurationMinute: dialysisDurationMinute,
  3886. DialysisDurationHour: dialysisDurationHour,
  3887. TargetUltrafiltration: targetUltrafiltration,
  3888. DialysateFormulation: dialysateFormulation,
  3889. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3890. BodyFluid: body_fluid,
  3891. SpecialMedicine: special_medicine,
  3892. SpecialMedicineOther: special_medicine_other,
  3893. DisplaceLiquiPart: displace_liqui_part,
  3894. DisplaceLiquiValue: displace_liqui_value,
  3895. BloodAccess: blood_access,
  3896. Ultrafiltration: ultrafiltration,
  3897. BodyFluidOther: body_fluid_other,
  3898. ReplacementTotal: replacement_total,
  3899. Niprocart: niprocart,
  3900. Jms: jms,
  3901. FistulaNeedleSet: fistula_needle_set,
  3902. FistulaNeedleSet16: fistula_needle_set_16,
  3903. Hemoperfusion: hemoperfusion,
  3904. DialyserSterilised: dialyser_sterilised,
  3905. Filtryzer: filtryzer,
  3906. TargetKtv: target_ktv,
  3907. Dialyzers: dialyzers,
  3908. Injector: injector,
  3909. Bloodlines: bloodlines,
  3910. TubingHemodialysis: tubing_hemodialysis,
  3911. Package: safe_package,
  3912. ALiquid: a_liquid,
  3913. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3914. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3915. Blood: blood,
  3916. DialysisDialyszers: dialysis_dialyszers,
  3917. DialysisIrrigation: dialysis_irrigation,
  3918. AntioxidantCommodityName: antioxidant_commodity_name,
  3919. DisplaceSpeed: displace_speed,
  3920. Illness: illness,
  3921. Amylaceum: amylaceum,
  3922. SingleWater: single_water,
  3923. SingleTime: single_time,
  3924. ReplacementFlow: replacement_flow,
  3925. PlasmaSeparator: plasma_separator,
  3926. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3927. OxygenUptake: oxygen_uptake,
  3928. OxygenTime: oxygen_time,
  3929. OxygenFlow: oxygen_flow,
  3930. HemodialysisPipelines: hemodialysis_pipelines,
  3931. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3932. PunctureNeedle: puncture_needle,
  3933. PunctureNeedleCount: puncture_needle_count,
  3934. Epo: epo,
  3935. EpoCount: epo_count,
  3936. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3937. PreImpulse: impulse,
  3938. AdminUserId: admin_user_id,
  3939. IsWater: is_war,
  3940. DrhyWater: drhy_water,
  3941. DryWaterHour: dry_water_hour,
  3942. WaterMachine: water_machine,
  3943. AddAmount: add_amount,
  3944. ReduceAmount: reduce_amount,
  3945. DialysisRemark: dialysis_remark,
  3946. PrescribingNumber: prescribing_number,
  3947. PrescriptionSodium: prescription_sodium,
  3948. StartSodium: start_sodium,
  3949. SodiumCurve: sodium_curve,
  3950. TreatmentRemark: treatment_remark,
  3951. DialysisFluidFlow: dialysis_fluid_flow,
  3952. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3953. PrescriptionWater: prescription_water,
  3954. DialysisStrainer: dialysis_strainer,
  3955. Chaptalization: chaptalization,
  3956. WashingTime: washing_time,
  3957. WarshCount: warsh_count,
  3958. BloodAccessPartId: blood_access_part_id,
  3959. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3960. Dialyzate: dialyzate,
  3961. DialysisDialyszersId: dialysis_dialyszers_id,
  3962. DialysisIrrigationId: dialysis_irrigation_id,
  3963. DialysisStrainerId: dialysis_strainer_id,
  3964. FirstSuper: fisrt_sup,
  3965. IsSequential: is_sequen,
  3966. Conduct: conduct,
  3967. }
  3968. if adminUserInfo.Org.Id == 10721 {
  3969. if prescription.ModeId == 2 {
  3970. if prescription.ReplacementTotal == 0 {
  3971. prescription.ReplacementTotal = 15
  3972. }
  3973. }
  3974. }
  3975. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3976. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3977. //
  3978. if appRole.UserType == 2 || appRole.UserType == 1 {
  3979. prescription_doctor = adminUserInfo.AdminUser.Id
  3980. prescription.PrescriptionDoctor = prescription_doctor
  3981. }
  3982. if dialysisPrescription.ID == 0 { //新增
  3983. prescription.Creater = adminUserInfo.AdminUser.Id
  3984. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3985. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3986. }
  3987. } else { //修改
  3988. if dialysisPrescription.Creater == 0 {
  3989. prescription.Creater = adminUserInfo.AdminUser.Id
  3990. } else {
  3991. prescription.Creater = dialysisPrescription.Creater
  3992. if adminUserInfo.Org.Id == 9882 {
  3993. if appRole.UserType == 2 || appRole.UserType == 1 {
  3994. prescription.Creater = adminUserInfo.AdminUser.Id
  3995. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3996. }
  3997. }
  3998. }
  3999. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4000. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4001. }
  4002. //if/**/
  4003. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4004. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  4005. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4006. // if getPermissionErr != nil {
  4007. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4008. // return
  4009. // } else if headNursePermission == nil {
  4010. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4011. // return
  4012. // }
  4013. //}
  4014. //prescription.Creater = dialysisPrescription.Creater
  4015. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4016. prescription.Modifier = adminUserInfo.AdminUser.Id
  4017. prescription.ID = dialysisPrescription.ID
  4018. }
  4019. solution := models.DialysisSolution{
  4020. RegistrarsId: adminUserInfo.AdminUser.Id,
  4021. UserOrgId: adminUserInfo.Org.Id,
  4022. Doctor: prescription_doctor,
  4023. PatientId: id,
  4024. ModeId: mode_id,
  4025. DialysisDuration: dialysis_duration,
  4026. PerfusionApparatus: perfusion_apparatus,
  4027. BloodFlowVolume: blood_flow_volume,
  4028. Dewater: dewater_amount,
  4029. DisplaceLiqui: displace_liqui,
  4030. ReplacementWay: replacement_way,
  4031. Anticoagulant: anticoagulant,
  4032. AnticoagulantShouji: anticoagulant_shouji,
  4033. AnticoagulantWeichi: anticoagulant_weichi,
  4034. AnticoagulantZongliang: anticoagulant_zongliang,
  4035. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4036. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4037. Kalium: kalium,
  4038. Sodium: sodium,
  4039. Calcium: calcium,
  4040. Bicarbonate: bicarbonate,
  4041. Glucose: glucose,
  4042. // DryWeight: dry_weight,
  4043. DialysateFlow: dialysate_flow,
  4044. DialysateTemperature: dialysate_temperature,
  4045. Conductivity: conductivity,
  4046. Remark: remark,
  4047. Status: 1,
  4048. CreatedTime: time.Now().Unix(),
  4049. UpdatedTime: time.Now().Unix(),
  4050. DialysisDurationMinute: dialysisDurationMinute,
  4051. DialysisDurationHour: dialysisDurationHour,
  4052. TargetUltrafiltration: targetUltrafiltration,
  4053. DialysateFormulation: dialysateFormulation,
  4054. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4055. BodyFluid: body_fluid,
  4056. SpecialMedicine: special_medicine,
  4057. SpecialMedicineOther: special_medicine_other,
  4058. DisplaceLiquiPart: displace_liqui_part,
  4059. DisplaceLiquiValue: displace_liqui_value,
  4060. BloodAccess: blood_access,
  4061. Ultrafiltration: ultrafiltration,
  4062. BodyFluidOther: body_fluid_other,
  4063. ReplacementTotal: replacement_total,
  4064. TargetKtv: target_ktv,
  4065. DialysisDialyszers: dialysis_dialyszers,
  4066. DialysisIrrigation: dialysis_irrigation,
  4067. HemodialysisPipelines: hemodialysis_pipelines,
  4068. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4069. PunctureNeedle: puncture_needle,
  4070. PunctureNeedleCount: puncture_needle_count,
  4071. Epo: epo,
  4072. EpoCount: epo_count,
  4073. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4074. PreImpulse: impulse,
  4075. SolutionStatus: 1,
  4076. DialysisRemark: dialysis_remark,
  4077. PrescribingNumber: prescribing_number,
  4078. PrescriptionSodium: prescription_sodium,
  4079. StartSodium: start_sodium,
  4080. SodiumCurve: sodium_curve,
  4081. TreatmentRemark: treatment_remark,
  4082. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4083. DialysisFluidFlow: dialysis_fluid_flow,
  4084. PrescriptionWater: prescription_water,
  4085. DialysisStrainer: dialysis_strainer,
  4086. Chaptalization: chaptalization,
  4087. WashingTime: washing_time,
  4088. WarshCount: warsh_count,
  4089. BloodAccessPartId: blood_access_part_id,
  4090. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4091. Dialyzate: dialyzate,
  4092. DialysisDialyszersId: dialysis_dialyszers_id,
  4093. DialysisIrrigationId: dialysis_irrigation_id,
  4094. DialysisStrainerId: dialysis_strainer_id,
  4095. FirstSuper: fisrt_sup,
  4096. IsSequential: is_sequen,
  4097. Conduct: conduct,
  4098. }
  4099. //针对河间咸的
  4100. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4101. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4102. solution.DisplaceLiquiPart = 0
  4103. solution.DisplaceLiquiValue = 0
  4104. }
  4105. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4106. prescription.DisplaceLiquiPart = 0
  4107. prescription.DisplaceLiquiValue = 0
  4108. }
  4109. }
  4110. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4111. if solution.PrescribingNumber == 0 {
  4112. solution.PrescribingNumber = 1
  4113. }
  4114. if prescription.PrescribingNumber == 0 {
  4115. prescription.PrescribingNumber = 1
  4116. }
  4117. if solution.PrescribingNumber == 0 && id == 14682 {
  4118. solution.PrescribingNumber = 2
  4119. }
  4120. if solution.PrescribingNumber == 0 && id == 18560 {
  4121. solution.PrescribingNumber = 2
  4122. }
  4123. if prescription.PrescribingNumber == 0 && id == 14682 {
  4124. prescription.PrescribingNumber = 2
  4125. }
  4126. if prescription.PrescribingNumber == 0 && id == 18560 {
  4127. prescription.PrescribingNumber = 2
  4128. }
  4129. }
  4130. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4131. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  4132. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4133. if len(monitorList) > 0 {
  4134. var ultrafiltration_rate float64
  4135. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4136. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4137. var replacement_rate float64
  4138. //乘10 除10是为了保留一位小数
  4139. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4140. var firstOpeateTime = monitorList[0].OperateTime
  4141. for _, item := range monitorList {
  4142. //超滤率
  4143. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4144. //置换率
  4145. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4146. //超滤量
  4147. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4148. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4149. //置换量
  4150. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4151. fmt.Println("displacement_quantity----------------------", displacement_quantity)
  4152. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4153. }
  4154. }
  4155. }
  4156. //记录日志
  4157. byterequest, _ := json.Marshal(prescription)
  4158. prescriptionLog := models.XtDialysisPrescriptionLog{
  4159. UserOrgId: prescription.UserOrgId,
  4160. Ctime: time.Now().Unix(),
  4161. Mtime: 0,
  4162. ErrLog: string(byterequest),
  4163. AdminUserId: adminUserInfo.AdminUser.Id,
  4164. RecordDate: prescription.RecordDate,
  4165. PatientId: prescription.PatientId,
  4166. Source: "手机端新增长期处方",
  4167. Status: 1,
  4168. }
  4169. service.CreatePrescriptionLog(prescriptionLog)
  4170. finish := models.XtDialysisFinish{
  4171. IsFinish: 1,
  4172. UserOrgId: adminUserInfo.Org.Id,
  4173. Status: 1,
  4174. Ctime: time.Now().Unix(),
  4175. Mtime: 0,
  4176. Module: 1,
  4177. RecordDate: recordDate.Unix(),
  4178. Sourse: 1,
  4179. PatientId: id,
  4180. }
  4181. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4182. if dialysisFinish.ID == 0 {
  4183. service.CreateDialysisFinish(finish)
  4184. }
  4185. //获取最新1条
  4186. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4187. //更新状态
  4188. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4189. //长沙南雅医院,自动生成抗凝剂的临时处方
  4190. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4191. if prescribing_number == 0 {
  4192. prescribing_number = 1
  4193. }
  4194. advice := models.DoctorAdvice{
  4195. UserOrgId: adminUserInfo.Org.Id,
  4196. PatientId: id,
  4197. GroupNo: 0,
  4198. AdviceType: 2,
  4199. RecordDate: recordDate.Unix(),
  4200. AdviceDate: recordDate.Unix(),
  4201. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4202. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4203. AdviceDesc: "",
  4204. ReminderDate: 0,
  4205. SingleDose: prescription.AnticoagulantZongliang,
  4206. SingleDoseUnit: "iu",
  4207. DrugSpec: 0,
  4208. DrugSpecUnit: "",
  4209. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4210. PrescribingNumberUnit: "支",
  4211. DeliveryWay: "静脉注射",
  4212. ExecutionFrequency: "上机前",
  4213. AdviceDoctor: 0,
  4214. Status: 1,
  4215. CreatedTime: time.Now().Unix(),
  4216. UpdatedTime: time.Now().Unix(),
  4217. IsPrescription: 1,
  4218. ExecutionState: 2,
  4219. StopState: 2,
  4220. IsSettle: 2,
  4221. }
  4222. // 查询排班信息
  4223. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4224. if schedulePatient.ID > 0 {
  4225. if schedulePatient.ScheduleType == 1 {
  4226. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4227. }
  4228. if schedulePatient.ScheduleType == 2 {
  4229. advice.StartTime = recordDate.Unix() + 9*60*60
  4230. }
  4231. }
  4232. // 抗凝剂名称
  4233. switch anticoagulant {
  4234. case 1:
  4235. advice.AdviceName = "无肝素"
  4236. break
  4237. case 2:
  4238. advice.AdviceName = "普通肝素"
  4239. break
  4240. case 3:
  4241. advice.AdviceName = "低分子肝素"
  4242. break
  4243. case 4:
  4244. advice.AdviceName = "阿加曲班"
  4245. break
  4246. case 5:
  4247. advice.AdviceName = "枸橼酸钠"
  4248. break
  4249. case 6:
  4250. advice.AdviceName = "低分子肝素钙"
  4251. break
  4252. case 7:
  4253. advice.AdviceName = "低分子肝素钠"
  4254. break
  4255. case 8:
  4256. advice.AdviceName = "依诺肝素"
  4257. break
  4258. case 9:
  4259. advice.AdviceName = "达肝素"
  4260. break
  4261. case 10:
  4262. advice.AdviceName = "体外抗凝"
  4263. break
  4264. case 11:
  4265. advice.AdviceName = "那曲肝素"
  4266. break
  4267. case 12:
  4268. advice.AdviceName = "无抗凝剂"
  4269. break
  4270. }
  4271. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4272. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4273. advice.AdviceDoctor = appRole.AdminUserId
  4274. }
  4275. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4276. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4277. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4278. advice.AdviceName = "低分子肝素钠注射液"
  4279. // 修改患者临时医嘱里的抗凝剂医嘱
  4280. advice.ID = advicePrescription.ID
  4281. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4282. } else {
  4283. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4284. advice.AdviceName = "低分子肝素钠注射液"
  4285. service.CreateDoctorAdvice(&advice)
  4286. }
  4287. }
  4288. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4289. redis := service.RedisClient()
  4290. defer redis.Close()
  4291. //清空key 值
  4292. redis.Set(key, "", time.Second)
  4293. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4294. redis.Set(keyOne, "", time.Second)
  4295. }
  4296. //获取key,清空redis
  4297. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4298. redis := service.RedisClient()
  4299. defer redis.Close()
  4300. //清空key 值
  4301. redis.Set(key, "", time.Second)
  4302. //清空长期医嘱的key
  4303. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4304. redis.Set(soulution_key, "", time.Second)
  4305. //查询最近透析准备表里是否存在 透析器 灌流器
  4306. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4307. redis.Set(keyOne, "", time.Second)
  4308. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4309. redis.Set(keyTwo, "", time.Second)
  4310. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4311. redis.Set(keyThree, "", time.Second)
  4312. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4313. redis.Set(keyFour, "", time.Second)
  4314. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4315. //
  4316. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4317. //
  4318. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4319. //if len(mation)>0{
  4320. // for _, item := range splitStr {
  4321. // for _,it := range mation{
  4322. // if(item == it.SpecificationName){
  4323. //
  4324. // //查询最近一次的透析器
  4325. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4326. //
  4327. // if errcode == gorm.ErrRecordNotFound{
  4328. // //插入数据
  4329. // prepare := models.DialysisBeforePrepare{
  4330. // UserOrgId: adminUserInfo.Org.Id,
  4331. // PatientId: id,
  4332. // RecordDate: recordDate.Unix(),
  4333. // GoodTypeId: it.GoodTypeId,
  4334. // GoodId: it.ID,
  4335. // Count: 1,
  4336. // Ctime: time.Now().Unix(),
  4337. // Creater: adminUserInfo.AdminUser.Id,
  4338. // Status:1,
  4339. //
  4340. // }
  4341. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4342. // fmt.Println("",errcode)
  4343. // }
  4344. // }
  4345. // }
  4346. //
  4347. // }
  4348. //
  4349. // for _, item := range splitIrrigation {
  4350. // for _,it := range mation{
  4351. // if(item == it.SpecificationName){
  4352. // //查询最近一次的透析器
  4353. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4354. // if errcode == gorm.ErrRecordNotFound{
  4355. // //插入数据
  4356. // prepare := models.DialysisBeforePrepare{
  4357. // UserOrgId: adminUserInfo.Org.Id,
  4358. // PatientId: id,
  4359. // RecordDate: recordDate.Unix(),
  4360. // GoodTypeId: it.GoodTypeId,
  4361. // GoodId: it.ID,
  4362. // Count: 1,
  4363. // Ctime: time.Now().Unix(),
  4364. // Creater: adminUserInfo.AdminUser.Id,
  4365. // Status:1,
  4366. //
  4367. // }
  4368. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4369. // fmt.Println(errcode)
  4370. // }
  4371. // }
  4372. // }
  4373. // }
  4374. //}
  4375. c.ServeSuccessJSON(map[string]interface{}{
  4376. "solution": &solution,
  4377. "prescription": &prescription,
  4378. })
  4379. }
  4380. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4381. patient, _ := c.GetInt64("patient", 0)
  4382. adminUserInfo := c.GetMobileAdminUserInfo()
  4383. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4384. c.ServeSuccessJSON(map[string]interface{}{
  4385. "receiveTreatmentAsses": receiveTreatmentAsses,
  4386. })
  4387. }
  4388. func (this *DialysisAPIController) PostSignInfo() {
  4389. patientID, _ := this.GetInt64("patient_id")
  4390. recordDateStr := this.GetString("date")
  4391. if patientID <= 0 {
  4392. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4393. return
  4394. }
  4395. if len(recordDateStr) == 0 {
  4396. recordDateStr = time.Now().Format("2006-01-02")
  4397. }
  4398. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4399. if parseDateErr != nil {
  4400. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4401. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4402. return
  4403. }
  4404. adminInfo := this.GetMobileAdminUserInfo()
  4405. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4406. if err != nil {
  4407. this.ErrorLog("签名失败:%v", err)
  4408. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4409. return
  4410. }
  4411. this.ServeSuccessJSON(map[string]interface{}{
  4412. "doctor_id": adminInfo.AdminUser.Id,
  4413. })
  4414. }
  4415. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4416. patientID, _ := this.GetInt64("patient_id")
  4417. adminInfo := this.GetMobileAdminUserInfo()
  4418. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4419. this.ServeSuccessJSON(map[string]interface{}{
  4420. "monitor": record,
  4421. })
  4422. }
  4423. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4424. thisTime := time.Now()
  4425. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4426. timeLayout := "2006-01-02 15:04:05"
  4427. loc, _ := time.LoadLocation("Local")
  4428. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4429. theAssessmentDateTime := theStartTime.Unix()
  4430. patientID, _ := this.GetInt64("patient_id")
  4431. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4432. adminInfo := this.GetMobileAdminUserInfo()
  4433. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4434. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4435. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4436. var ultrafiltration_rate float64
  4437. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4438. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4439. fmt.Println(evaluation)
  4440. fmt.Println("prescription.ID", prescription.ID)
  4441. if prescription.ID > 0 {
  4442. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4443. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4444. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10745) && adminInfo.Org.Id != 9538 {
  4445. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4446. record.UltrafiltrationRate = ultrafiltration_rate
  4447. }
  4448. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4449. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4450. record.UltrafiltrationRate = ultrafiltration_rate
  4451. }
  4452. if adminInfo.Org.Id == 10510 {
  4453. record.UltrafiltrationRate = 0
  4454. }
  4455. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4456. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4457. record.UltrafiltrationRate = ultrafiltration_rate
  4458. }
  4459. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4460. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4461. record.UltrafiltrationRate = ultrafiltration_rate
  4462. }
  4463. // 只针对方济医院
  4464. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4465. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4466. ultrafiltration_rate = value
  4467. record.UltrafiltrationRate = ultrafiltration_rate
  4468. }
  4469. if template.TemplateId == 41 || template.TemplateId == 47 {
  4470. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4471. record.UltrafiltrationRate = ultrafiltration_rate
  4472. }
  4473. if template.TemplateId == 43 {
  4474. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4475. record.UltrafiltrationRate = ultrafiltration_rate
  4476. }
  4477. if template.TemplateId == 46 || template.TemplateId == 54 {
  4478. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4479. record.UltrafiltrationRate = ultrafiltration_rate
  4480. }
  4481. 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 {
  4482. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4483. record.UltrafiltrationRate = ultrafiltration_rate
  4484. }
  4485. if adminInfo.Org.Id == 10469 {
  4486. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4487. record.UltrafiltrationRate = ultrafiltration_rate
  4488. }
  4489. if adminInfo.Org.Id == 10667 {
  4490. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4491. record.UltrafiltrationRate = ultrafiltration_rate
  4492. }
  4493. if adminInfo.Org.Id == 10471 {
  4494. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4495. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4496. }
  4497. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4498. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4499. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4500. }
  4501. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4502. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4503. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4504. }
  4505. if adminInfo.Org.Id == 10721 {
  4506. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4507. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4508. }
  4509. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4510. record.UltrafiltrationRate = 0
  4511. }
  4512. if adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10731 {
  4513. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4514. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4515. }
  4516. if adminInfo.Org.Id == 10206 {
  4517. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4518. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4519. }
  4520. //if template.TemplateId == 47 {
  4521. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4522. // record.UltrafiltrationRate = ultrafiltration_rate
  4523. //}
  4524. }
  4525. }
  4526. // record.UltrafiltrationRate = ultrafiltration_rate
  4527. record.UltrafiltrationVolume = 0
  4528. 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
  4529. if ultrafiltration_rate > 0 {
  4530. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4531. record.UltrafiltrationVolume = value
  4532. }
  4533. }
  4534. 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
  4535. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4536. if adminInfo.Org.Id != 10735 {
  4537. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4538. record.UltrafiltrationVolume = ultrafiltration_volume
  4539. }
  4540. //胶州少海医院
  4541. if adminInfo.Org.Id == 10735 {
  4542. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4543. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4544. var ultrafiltration_rate_one = math.Floor(prescription.TargetUltrafiltration*1000/float64(totalMin)*60*1000) / 1000
  4545. if lastMonitorRecordList.ID > 0 {
  4546. record.UltrafiltrationRate = ultrafiltration_rate_one
  4547. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4548. record.UltrafiltrationVolume = ultrafiltration_volume
  4549. } else {
  4550. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4551. record.UltrafiltrationVolume = ultrafiltration_volume
  4552. }
  4553. }
  4554. }
  4555. }
  4556. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4557. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4558. record.UltrafiltrationVolume = ultrafiltration_volume
  4559. }
  4560. //长沙南雅
  4561. 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 {
  4562. if ultrafiltration_rate > 0 {
  4563. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4564. record.UltrafiltrationVolume = ultrafiltration_volume
  4565. }
  4566. }
  4567. if adminInfo.Org.Id == 10471 {
  4568. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4569. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4570. }
  4571. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4572. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4573. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4574. }
  4575. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4576. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4577. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4578. }
  4579. //长沙南雅累计血容量自动计算
  4580. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4581. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4582. //}
  4583. if template.TemplateId == 47 || template.TemplateId == 54 {
  4584. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4585. }
  4586. if adminInfo.Org.Id == 10510 {
  4587. record.UltrafiltrationVolume = 0
  4588. }
  4589. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10731 {
  4590. if ultrafiltration_rate > 0 {
  4591. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4592. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4593. }
  4594. }
  4595. //古镇乐生
  4596. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4597. if ultrafiltration_rate > 0 {
  4598. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4599. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4600. }
  4601. }
  4602. if adminInfo.Org.Id == 10206 {
  4603. if ultrafiltration_rate > 0 {
  4604. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4605. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4606. }
  4607. }
  4608. if adminInfo.Org.Id == 10721 {
  4609. var replacement_rate float64
  4610. var displacement_quantity float64
  4611. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4612. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  4613. record.ReplacementRate = replacement_rate
  4614. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4615. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4616. record.DisplacementQuantity = displacement_quantity
  4617. }
  4618. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 {
  4619. var replacement_rate float64
  4620. var displacement_quantity float64
  4621. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4622. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  4623. record.ReplacementRate = replacement_rate
  4624. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4625. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4626. record.DisplacementQuantity = displacement_quantity
  4627. }
  4628. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 {
  4629. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4630. record.UltrafiltrationVolume = ultrafiltration_volume
  4631. }
  4632. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4633. var replacement_rate float64
  4634. var displacement_quantity float64
  4635. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4636. if totalMin == 0 {
  4637. totalMin = 240
  4638. }
  4639. if prescription.DisplaceLiquiValue == 0 {
  4640. prescription.ReplacementTotal = 32
  4641. }
  4642. //乘10 除10是为了保留一位小数
  4643. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4644. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4645. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4646. record.DisplacementQuantity = displacement_quantity
  4647. }
  4648. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4649. this.ServeSuccessJSON(map[string]interface{}{
  4650. "monitor": record,
  4651. "lastMonitorRecordList": lastMonitorRecordList,
  4652. })
  4653. }
  4654. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4655. record_id, _ := this.GetInt64("id")
  4656. nurseID, _ := this.GetInt64("start_nurse")
  4657. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4658. bedID, _ := this.GetInt64("bed")
  4659. start_time := this.GetString("start_time")
  4660. schedual_type, _ := this.GetInt64("schedual_type")
  4661. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4662. change_nurse, _ := this.GetInt64("change_nurse")
  4663. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4664. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4665. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4666. patient_id, _ := this.GetInt64("patient_id")
  4667. record_date, _ := this.GetInt64("record_date")
  4668. puncture_needle := this.GetString("puncture_needle")
  4669. puncture_way := this.GetString("puncture_way")
  4670. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4671. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4672. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4673. nuclein_date_str := this.GetString("nuclein_date_str")
  4674. order_remark := this.GetString("order_remark")
  4675. schedule_remark := this.GetString("schedule_remark")
  4676. catheter_operation := this.GetString("catheter_operation")
  4677. blood_flow_volume := this.GetString("blood_flow_volume")
  4678. blood_drawing, _ := this.GetInt64("blood_drawing")
  4679. dialysis_strainer := this.GetString("dialysis_strainer")
  4680. if record_id == 0 {
  4681. this.ErrorLog("id:%v", record_id)
  4682. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4683. return
  4684. }
  4685. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4686. if parseStartDateErr != nil {
  4687. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4688. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4689. return
  4690. }
  4691. adminUserInfo := this.GetMobileAdminUserInfo()
  4692. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4693. if getNurseErr != nil {
  4694. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4695. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4696. return
  4697. } else if nurse == nil {
  4698. this.ErrorLog("护士不存在")
  4699. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4700. return
  4701. }
  4702. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4703. //if getNurseErr != nil {
  4704. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4705. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4706. // return
  4707. //} else if nurse == nil {
  4708. // this.ErrorLog("护士不存在")
  4709. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4710. // return
  4711. //}
  4712. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4713. if getDeviceNumberErr != nil {
  4714. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4715. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4716. return
  4717. } else if deviceNumber == nil {
  4718. this.ErrorLog("床位号不存在")
  4719. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4720. return
  4721. }
  4722. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4723. //
  4724. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4725. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4726. // if getPermissionErr != nil {
  4727. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4728. // return
  4729. // } else if headNursePermission == nil {
  4730. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4731. // return
  4732. // }
  4733. //}
  4734. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4735. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4736. timeLayout := "2006-01-02 15:04:05"
  4737. loc, _ := time.LoadLocation("Local")
  4738. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4739. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4740. schedulestartTime := theStartTime.Unix()
  4741. scheduleendTime := theEndTime.Unix()
  4742. var theNucleinDate int64
  4743. timeLayoutOne := "2006-01-02"
  4744. if len(nuclein_date_str) > 0 {
  4745. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4746. if err != nil {
  4747. utils.ErrorLog(err.Error())
  4748. }
  4749. theNucleinDate = theTime.Unix()
  4750. }
  4751. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4752. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4753. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4754. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4755. if err == gorm.ErrRecordNotFound { //空床位
  4756. // 修改了床位逻辑
  4757. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4758. if daySchedule.ID > 0 {
  4759. //daySchedule.BedId = bedID
  4760. //daySchedule.PartitionId = deviceNumber.ZoneID
  4761. //daySchedule.ScheduleType = schedual_type
  4762. //daySchedule.UpdatedTime = time.Now().Unix()
  4763. //err := service.UpdateSchedule(&daySchedule)
  4764. xtSchedule := models.Schedule{
  4765. PartitionId: deviceNumber.ZoneID,
  4766. BedId: bedID,
  4767. ScheduleType: schedual_type,
  4768. UpdatedTime: time.Now().Unix(),
  4769. }
  4770. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4771. if err != nil {
  4772. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4773. return
  4774. }
  4775. }
  4776. } else if err == nil {
  4777. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4778. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4779. if daySchedule.ID > 0 {
  4780. //daySchedule.BedId = bedID
  4781. //daySchedule.PartitionId = deviceNumber.ZoneID
  4782. //
  4783. //daySchedule.ScheduleType = schedual_type
  4784. //daySchedule.UpdatedTime = time.Now().Unix()
  4785. //err := service.UpdateSchedule(&daySchedule)
  4786. xtSchedule := models.Schedule{
  4787. PartitionId: deviceNumber.ZoneID,
  4788. BedId: bedID,
  4789. ScheduleType: schedual_type,
  4790. UpdatedTime: time.Now().Unix(),
  4791. }
  4792. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4793. if err != nil {
  4794. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4795. return
  4796. }
  4797. }
  4798. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4799. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4800. return
  4801. }
  4802. } else if err != nil {
  4803. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4804. return
  4805. }
  4806. }
  4807. dialysisRecord := &models.DialysisOrder{
  4808. ID: record_id,
  4809. UserOrgId: adminUserInfo.Org.Id,
  4810. BedID: bedID,
  4811. StartNurse: nurseID,
  4812. StartTime: startDate.Unix(),
  4813. PunctureNurse: puncture_nurse,
  4814. Creator: adminUserInfo.AdminUser.Id,
  4815. Modifier: adminUserInfo.AdminUser.Id,
  4816. WashpipeNurse: washpipe_nurse,
  4817. SchedualType: schedual_type,
  4818. ChangeNurse: change_nurse,
  4819. DifficultPunctureNurse: difficult_puncture_nurse,
  4820. NewFistulaNurse: new_fistula_nurse,
  4821. QualityNurseId: quality_nurse_id,
  4822. PunctureNeedle: puncture_needle,
  4823. PunctureWay: puncture_way,
  4824. DialysisDialyszers: dialysis_dialyszers,
  4825. DialysisIrrigation: dialysis_irrigation,
  4826. BloodAccessId: blood_access_id,
  4827. NucleinDate: theNucleinDate,
  4828. OrderRemark: order_remark,
  4829. ScheduleRemark: schedule_remark,
  4830. CatheterOperation: catheter_operation,
  4831. BloodFlowVolume: blood_flow_volume,
  4832. BloodDrawing: blood_drawing,
  4833. DialysisStrainer: dialysis_strainer,
  4834. }
  4835. //修改床位号需要重新消毒
  4836. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4837. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4838. //查询第一条监测
  4839. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4840. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4841. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4842. redis := service.RedisClient()
  4843. //清空key 值
  4844. redis.Set(key, "", time.Second)
  4845. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4846. redis.Set(keyOne, "", time.Second)
  4847. defer redis.Close()
  4848. }
  4849. // 查询信息规挡的设置天数
  4850. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4851. if infor.ID > 0 && infor.WeekDay > 0 {
  4852. var cha_time int64
  4853. timeNowStr := time.Now().Format("2006-01-02")
  4854. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4855. //今日的日期减去设置的日期
  4856. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4857. if cha_time >= record_date {
  4858. //查询审核是否允许
  4859. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4860. //申请状态不允许的情况 拒绝修改
  4861. if infor.ApplicationStatus != 1 {
  4862. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4863. return
  4864. }
  4865. }
  4866. }
  4867. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4868. //修改床位后重新生成消毒计划
  4869. if adminUserInfo.Org.Id == 10340 {
  4870. //根据床位号获取设备型号
  4871. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4872. //查询使用消毒最后一条消毒记录
  4873. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4874. fmt.Println("err", err)
  4875. if err == gorm.ErrRecordNotFound {
  4876. //查找排班
  4877. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4878. //查询改设备是否有消毒计划
  4879. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4880. //根据床位号获取设备id
  4881. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4882. //查询病人信息
  4883. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4884. var con = ""
  4885. if patients.IsInfectious == 0 {
  4886. con = ""
  4887. }
  4888. if patients.IsInfectious == 1 {
  4889. con = "无"
  4890. }
  4891. if patients.IsInfectious == 2 {
  4892. con = "有"
  4893. }
  4894. if errcode == nil {
  4895. var end_time int64
  4896. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4897. //新增消毒
  4898. information := models.DeviceInformation{
  4899. Date: dialysisRecord.DialysisDate,
  4900. Zone: dialysisRecord.ZoneId,
  4901. Class: dialysisRecord.SchedualType,
  4902. BedNumber: dialysisRecord.BedID,
  4903. PatientId: dialysisRecord.PatientId,
  4904. DialysisMode: scheduleByPatient.ModeId,
  4905. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4906. Disinfection: 1,
  4907. DialysisConcentration: 1,
  4908. DisinfectionStatus: 1,
  4909. Move: 1,
  4910. UserOrgId: dialysisRecord.UserOrgId,
  4911. DisinfectType: plan.Way,
  4912. DisinfectantType: plan.MachineDisinfectant,
  4913. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4914. Disinfectant: plan.Disinfectant,
  4915. Ctime: time.Now().Unix(),
  4916. Status: 1,
  4917. SignName: nurseID,
  4918. EquimentId: addmacher.ID,
  4919. DisinfectionResidue: 2,
  4920. Bed: addmacher.BedNumber,
  4921. StartTime: dialysisRecord.StartTime,
  4922. EndTime: dialysisRecord.EndTime,
  4923. Contagion: con,
  4924. WeightLoss: 0,
  4925. Hyperfiltratio: 0,
  4926. DialysisHour: "",
  4927. MachineRun: 1,
  4928. DisinfecStartime: dialysisRecord.EndTime,
  4929. DisinfecEndtime: end_time,
  4930. }
  4931. err := service.CreateInformationTwo(&information)
  4932. fmt.Println("报错", err)
  4933. }
  4934. }
  4935. }
  4936. order, _ := service.GetLastPatientOrder(record_id)
  4937. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4938. redis := service.RedisClient()
  4939. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4940. redis.Set(key, "", time.Second)
  4941. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4942. //清空key 值
  4943. redis.Set(keyOne, "", time.Second)
  4944. scheduleDateStartOne := startDate.Format("2006-01-02")
  4945. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4946. redis.Set(keyTwo, "", time.Second)
  4947. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4948. redis.Set(keyThree, "", time.Second)
  4949. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4950. redis.Set(keyFour, "", time.Second)
  4951. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4952. redis.Set(keyFive, "", time.Second)
  4953. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4954. redis.Set(keySix, "", time.Second)
  4955. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4956. redis.Set(keySeven, "", time.Second)
  4957. if updateErr != nil {
  4958. this.ErrorLog("修改上机失败:%v", updateErr)
  4959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4960. return
  4961. }
  4962. if updateErr == nil {
  4963. if tempDialysisRecord.Stage == 2 {
  4964. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4965. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4966. fmt.Println(value)
  4967. a, b := math.Modf(value)
  4968. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4969. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4970. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4971. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4972. redis := service.RedisClient()
  4973. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4974. redis.Set(key, "", time.Second)
  4975. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4976. redis.Set(keyOne, "", time.Second)
  4977. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4978. //清空key 值
  4979. redis.Set(keySix, "", time.Second)
  4980. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4981. redis.Set(keySeven, "", time.Second)
  4982. redis.Close()
  4983. if updateAssessmentErr != nil {
  4984. utils.ErrorLog("%v", updateAssessmentErr)
  4985. }
  4986. }
  4987. }
  4988. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4989. this.ServeSuccessJSON(map[string]interface{}{
  4990. "dialysis_order": dialysisRecords,
  4991. })
  4992. }
  4993. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4994. record_id, _ := c.GetInt64("id")
  4995. nurseID, _ := c.GetInt64("nurse")
  4996. end_time := c.GetString("end_time")
  4997. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4998. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4999. catheter := c.GetString("catheter")
  5000. cruor := c.GetString("cruor")
  5001. mission := c.GetString("mission")
  5002. condenser := c.GetString("condenser")
  5003. if record_id <= 0 || nurseID <= 0 {
  5004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5005. return
  5006. }
  5007. adminUserInfo := c.GetMobileAdminUserInfo()
  5008. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5009. if getNurseErr != nil {
  5010. c.ErrorLog("获取护士失败:%v", getNurseErr)
  5011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5012. return
  5013. } else if nurse == nil {
  5014. c.ErrorLog("护士不存在")
  5015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5016. return
  5017. }
  5018. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5019. if parseEndDateErr != nil {
  5020. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5022. return
  5023. }
  5024. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5025. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5026. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5027. // if getPermissionErr != nil {
  5028. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5029. // return
  5030. // } else if headNursePermission == nil {
  5031. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5032. // return
  5033. // }
  5034. //}
  5035. // 查询信息规挡的设置天数
  5036. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5037. if infor.ID > 0 {
  5038. var cha_time int64
  5039. timeNowStr := time.Now().Format("2006-01-02")
  5040. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5041. //今日的日期减去设置的日期
  5042. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5043. if cha_time >= tempDialysisRecords.DialysisDate {
  5044. //查询审核是否允许
  5045. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  5046. //申请状态不允许的情况 拒绝修改
  5047. if infor.ApplicationStatus != 1 {
  5048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5049. return
  5050. }
  5051. }
  5052. }
  5053. dialysisRecord := &models.DialysisOrder{
  5054. ID: record_id,
  5055. UserOrgId: adminUserInfo.Org.Id,
  5056. EndTime: endDate.Unix(),
  5057. FinishNurse: nurseID,
  5058. FinishModifier: adminUserInfo.AdminUser.Id,
  5059. PuncturePointHaematoma: puncture_point_haematoma,
  5060. BloodAccessInternalFistula: blood_access_internal_fistula,
  5061. Catheter: catheter,
  5062. Cruor: cruor,
  5063. Mission: mission,
  5064. Condenser: condenser,
  5065. }
  5066. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5067. redis := service.RedisClient()
  5068. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  5069. //清空key 值
  5070. redis.Set(key, "", time.Second)
  5071. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5072. //清空key 值
  5073. redis.Set(keyOne, "", time.Second)
  5074. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5075. redis.Set(keySeven, "", time.Second)
  5076. redis.Close()
  5077. if updateErr != nil {
  5078. c.ErrorLog("修改下机失败:%v", updateErr)
  5079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5080. return
  5081. }
  5082. if updateErr == nil {
  5083. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5084. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5085. a, b := math.Modf(value)
  5086. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5087. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5088. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5089. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5090. redis := service.RedisClient()
  5091. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  5092. redis.Set(keyTen, "", time.Second)
  5093. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  5094. redis.Set(keyTwo, "", time.Second)
  5095. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  5096. redis.Set(key, "", time.Second)
  5097. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5098. redis.Set(keyThree, "", time.Second)
  5099. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5100. redis.Set(keySeven, "", time.Second)
  5101. defer redis.Close()
  5102. if updateAssessmentErr != nil {
  5103. utils.ErrorLog("%v", updateAssessmentErr)
  5104. }
  5105. }
  5106. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5107. c.ServeSuccessJSON(map[string]interface{}{
  5108. "dialysis_order": dialysisRecords,
  5109. })
  5110. }
  5111. func (c *DialysisAPIController) GetLongAdvice() {
  5112. patient_id, _ := c.GetInt64("id")
  5113. adminUserInfo := c.GetMobileAdminUserInfo()
  5114. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5115. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5116. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5117. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5118. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5119. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5120. c.ServeSuccessJSON(map[string]interface{}{
  5121. "status": "1",
  5122. })
  5123. return
  5124. } else { //开启推送提醒
  5125. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5126. var advice_three []*models.DoctorAdvice
  5127. recordDateStr := time.Now().Format("2006-01-02")
  5128. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5129. nowtime := recordDate.Unix()
  5130. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5131. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5132. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5133. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5134. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5135. for _, advice := range advices {
  5136. if advice.FrequencyType == 3 {
  5137. t := time.Now()
  5138. week := int(t.Weekday())
  5139. fmt.Println(t.Weekday())
  5140. fmt.Println(week)
  5141. switch week {
  5142. case 1:
  5143. if strings.Index(advice.WeekDay, "周一") == -1 {
  5144. advice_three = append(advice_three, advice)
  5145. }
  5146. break
  5147. case 2:
  5148. if strings.Index(advice.WeekDay, "周二") == -1 {
  5149. advice_three = append(advice_three, advice)
  5150. }
  5151. break
  5152. case 3:
  5153. if strings.Index(advice.WeekDay, "周三") == -1 {
  5154. advice_three = append(advice_three, advice)
  5155. }
  5156. break
  5157. case 4:
  5158. if strings.Index(advice.WeekDay, "周四") == -1 {
  5159. advice_three = append(advice_three, advice)
  5160. }
  5161. break
  5162. case 5:
  5163. if strings.Index(advice.WeekDay, "周五") == -1 {
  5164. advice_three = append(advice_three, advice)
  5165. }
  5166. break
  5167. case 6:
  5168. if strings.Index(advice.WeekDay, "周六") == -1 {
  5169. advice_three = append(advice_three, advice)
  5170. }
  5171. break
  5172. case 0:
  5173. if strings.Index(advice.WeekDay, "周日") == -1 {
  5174. advice_three = append(advice_three, advice)
  5175. }
  5176. break
  5177. }
  5178. }
  5179. }
  5180. for _, advice := range advices_two {
  5181. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5182. now := p.Unix()
  5183. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5184. dayStr2 := "-" + dayStr
  5185. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5186. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5187. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5188. for _, ad := range advices {
  5189. advice_three = append(advice_three, ad)
  5190. }
  5191. }
  5192. if err == nil {
  5193. c.ServeSuccessJSON(map[string]interface{}{
  5194. "status": "2",
  5195. "advices": advices,
  5196. "advices_two": RemoveRepeatedElement(advice_three),
  5197. "is_open_remind": config.IsOpenRemind,
  5198. "his_config_open": hisConfig.IsOpen,
  5199. "is_advice_open": is_advice_open.IsAdviceOpen,
  5200. "prescription_open": prescription_open.IsOpen,
  5201. })
  5202. }
  5203. }
  5204. }
  5205. func (c *DialysisAPIController) GetLongAdviceOne() {
  5206. patient_id, _ := c.GetInt64("id")
  5207. startTime := c.GetString("schedule_date")
  5208. timeLayout := "2006-01-02"
  5209. loc, _ := time.LoadLocation("Local")
  5210. var theStartTime int64
  5211. if len(startTime) > 0 {
  5212. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5213. if err != nil {
  5214. utils.ErrorLog(err.Error())
  5215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5216. return
  5217. }
  5218. theStartTime = theTime.Unix()
  5219. }
  5220. adminUserInfo := c.GetMobileAdminUserInfo()
  5221. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5222. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5223. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5224. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5225. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5226. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5227. c.ServeSuccessJSON(map[string]interface{}{
  5228. "status": "1",
  5229. })
  5230. return
  5231. } else { //开启推送提醒
  5232. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5233. var advice_three []*models.DoctorAdvice
  5234. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5235. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5236. for _, advice := range advices {
  5237. if advice.FrequencyType == 3 {
  5238. t := time.Now()
  5239. week := int(t.Weekday())
  5240. fmt.Println(t.Weekday())
  5241. fmt.Println(week)
  5242. switch week {
  5243. case 1:
  5244. if strings.Index(advice.WeekDay, "周一") == -1 {
  5245. advice_three = append(advice_three, advice)
  5246. }
  5247. break
  5248. case 2:
  5249. if strings.Index(advice.WeekDay, "周二") == -1 {
  5250. advice_three = append(advice_three, advice)
  5251. }
  5252. break
  5253. case 3:
  5254. if strings.Index(advice.WeekDay, "周三") == -1 {
  5255. advice_three = append(advice_three, advice)
  5256. }
  5257. break
  5258. case 4:
  5259. if strings.Index(advice.WeekDay, "周四") == -1 {
  5260. advice_three = append(advice_three, advice)
  5261. }
  5262. break
  5263. case 5:
  5264. if strings.Index(advice.WeekDay, "周五") == -1 {
  5265. advice_three = append(advice_three, advice)
  5266. }
  5267. break
  5268. case 6:
  5269. if strings.Index(advice.WeekDay, "周六") == -1 {
  5270. advice_three = append(advice_three, advice)
  5271. }
  5272. break
  5273. case 0:
  5274. if strings.Index(advice.WeekDay, "周日") == -1 {
  5275. advice_three = append(advice_three, advice)
  5276. }
  5277. break
  5278. }
  5279. }
  5280. }
  5281. for _, advice := range advices_two {
  5282. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5283. now := p.Unix()
  5284. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5285. dayStr2 := "-" + dayStr
  5286. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5287. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5288. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5289. for _, ad := range advices {
  5290. advice_three = append(advice_three, ad)
  5291. }
  5292. }
  5293. if err == nil {
  5294. c.ServeSuccessJSON(map[string]interface{}{
  5295. "status": "2",
  5296. "advices": advices,
  5297. "advices_two": RemoveRepeatedElement(advice_three),
  5298. "is_open_remind": config.IsOpenRemind,
  5299. "his_config_open": hisConfig.IsOpen,
  5300. "is_advice_open": is_advice_open.IsAdviceOpen,
  5301. "prescription_open": prescription_open.IsOpen,
  5302. })
  5303. }
  5304. }
  5305. }
  5306. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5307. newArr = make([]*models.DoctorAdvice, 0)
  5308. for i := 0; i < len(arr); i++ {
  5309. repeat := false
  5310. for j := i + 1; j < len(arr); j++ {
  5311. if arr[i].ID == arr[j].ID {
  5312. repeat = true
  5313. break
  5314. }
  5315. }
  5316. if !repeat {
  5317. newArr = append(newArr, arr[i])
  5318. }
  5319. }
  5320. return
  5321. }
  5322. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5323. patient, _ := c.GetInt64("id", 0)
  5324. groupNo, _ := c.GetInt64("groupno", 0)
  5325. if patient <= 0 {
  5326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5327. return
  5328. }
  5329. adminUserInfo := c.GetMobileAdminUserInfo()
  5330. dataBody := make(map[string]interface{}, 0)
  5331. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5332. if err != nil {
  5333. utils.ErrorLog(err.Error())
  5334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5335. return
  5336. }
  5337. utils.ErrorLog("%v", dataBody)
  5338. timeLayout := "2006-01-02 15:04"
  5339. loc, _ := time.LoadLocation("Local")
  5340. timeLayout2 := "2006-01-02"
  5341. loc2, _ := time.LoadLocation("Local")
  5342. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5343. utils.ErrorLog("advice_type")
  5344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5345. return
  5346. }
  5347. adviceType := int64(2)
  5348. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5349. utils.ErrorLog("advice_date")
  5350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5351. return
  5352. }
  5353. adviceDate, _ := dataBody["advice_date"].(string)
  5354. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5355. AdviceDate := theTime.Unix()
  5356. RecordDate := theTime.Unix()
  5357. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5358. utils.ErrorLog("start_time")
  5359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5360. return
  5361. }
  5362. startTime, _ := dataBody["start_time"].(string)
  5363. if len(startTime) == 0 {
  5364. utils.ErrorLog("len(start_time) == 0")
  5365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5366. return
  5367. }
  5368. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5369. if err != nil {
  5370. utils.ErrorLog(err.Error())
  5371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5372. return
  5373. }
  5374. StartTime := theTime.Unix()
  5375. Remark := ""
  5376. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5377. remark, _ := dataBody["remark"].(string)
  5378. Remark = remark
  5379. }
  5380. var advices []*models.GroupAdvice
  5381. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5382. utils.ErrorLog("advices")
  5383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5384. return
  5385. }
  5386. adviceNames := dataBody["advices"].([]interface{})
  5387. for _, adviceNameMap := range adviceNames {
  5388. adviceNameM := adviceNameMap.(map[string]interface{})
  5389. var advice models.GroupAdvice
  5390. advice.Remark = Remark
  5391. advice.AdviceType = adviceType
  5392. advice.StartTime = StartTime
  5393. advice.AdviceDate = AdviceDate
  5394. advice.RecordDate = RecordDate
  5395. advice.Status = 1
  5396. advice.CreatedTime = time.Now().Unix()
  5397. advice.UpdatedTime = time.Now().Unix()
  5398. advice.StopState = 2
  5399. advice.ExecutionState = 2
  5400. advice.UserOrgId = adminUserInfo.Org.Id
  5401. advice.PatientId = patient
  5402. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5403. advice.IsSettle = 2
  5404. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5405. utils.ErrorLog("advice_name")
  5406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5407. return
  5408. }
  5409. adviceName, _ := adviceNameM["advice_name"].(string)
  5410. if len(adviceName) == 0 {
  5411. utils.ErrorLog("len(advice_name) == 0")
  5412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5413. return
  5414. }
  5415. advice.AdviceName = adviceName
  5416. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5417. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5418. advice.DrugSpec = drugSpec
  5419. }
  5420. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5421. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5422. advice.AdviceDesc = adviceDesc
  5423. }
  5424. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5425. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5426. advice.DrugSpecUnit = drugSpecUnit
  5427. }
  5428. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5429. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5430. // advice.SingleDose = singleDose
  5431. //}
  5432. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5433. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5434. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5435. }
  5436. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5437. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5438. advice.SingleDoseUnit = singleDoseUnit
  5439. }
  5440. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5441. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5442. // advice.PrescribingNumber = prescribingNumber
  5443. //}
  5444. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5445. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5446. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5447. }
  5448. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5449. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5450. advice.PrescribingNumberUnit = prescribingNumberUnit
  5451. }
  5452. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5453. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5454. advice.DeliveryWay = deliveryWay
  5455. }
  5456. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5457. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5458. advice.ExecutionFrequency = executionFrequency
  5459. }
  5460. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5461. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5462. advice.FrequencyType = frequency_type
  5463. }
  5464. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5465. day_count := int64(adviceNameM["day_count"].(float64))
  5466. advice.DayCount = day_count
  5467. }
  5468. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5469. week_day, _ := adviceNameM["week_day"].(string)
  5470. advice.WeekDay = week_day
  5471. }
  5472. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5473. way := int64(adviceNameM["way"].(float64))
  5474. advice.Way = way
  5475. }
  5476. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5477. drug_id := int64(adviceNameM["drug_id"].(float64))
  5478. advice.DrugId = drug_id
  5479. }
  5480. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5481. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5482. advice.DrugNameId = drug_name_id
  5483. }
  5484. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5485. remark, _ := adviceNameM["remark"].(string)
  5486. advice.Remark = remark
  5487. }
  5488. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5489. groupno := int64(adviceNameM["groupno"].(float64))
  5490. advice.GroupNo = groupno
  5491. }
  5492. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5493. template_id, _ := adviceNameM["template_id"].(string)
  5494. advice.TemplateId = template_id
  5495. }
  5496. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5497. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5498. advice.ExecutionFrequency = executionFrequency
  5499. }
  5500. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5501. children := adviceNameM["child"].([]interface{})
  5502. if len(children) > 0 {
  5503. for _, childrenMap := range children {
  5504. childMap := childrenMap.(map[string]interface{})
  5505. var child models.GroupAdvice
  5506. child.Remark = Remark
  5507. child.AdviceType = adviceType
  5508. child.StartTime = StartTime
  5509. child.AdviceDate = AdviceDate
  5510. child.RecordDate = RecordDate
  5511. child.Status = 1
  5512. child.CreatedTime = time.Now().Unix()
  5513. child.UpdatedTime = time.Now().Unix()
  5514. child.StopState = 2
  5515. child.ExecutionState = 2
  5516. child.UserOrgId = adminUserInfo.Org.Id
  5517. child.PatientId = patient
  5518. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5519. child.IsSettle = 1
  5520. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5521. utils.ErrorLog("child advice_name")
  5522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5523. return
  5524. }
  5525. childAdviceName, _ := childMap["advice_name"].(string)
  5526. if len(childAdviceName) == 0 {
  5527. utils.ErrorLog("len(child advice_name) == 0")
  5528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5529. return
  5530. }
  5531. child.AdviceName = childAdviceName
  5532. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5533. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5534. child.AdviceDesc = childAdviceDesc
  5535. }
  5536. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5537. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5538. child.DrugSpec = childDrugSpec
  5539. }
  5540. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5541. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5542. child.DrugSpecUnit = childDrugSpecUnit
  5543. }
  5544. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5545. child.SingleDose = childMap["single_dose"].(float64)
  5546. }
  5547. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5548. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5549. child.SingleDoseUnit = childSingleDoseUnit
  5550. }
  5551. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5552. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5553. }
  5554. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5555. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5556. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5557. }
  5558. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5559. groupno := int64(childMap["groupno"].(float64))
  5560. advice.GroupNo = groupno
  5561. }
  5562. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5563. remark, _ := childMap["remark"].(string)
  5564. child.Remark = remark
  5565. }
  5566. child.DeliveryWay = advice.DeliveryWay
  5567. child.ExecutionFrequency = advice.ExecutionFrequency
  5568. advice.Children = append(advice.Children, &child)
  5569. }
  5570. }
  5571. }
  5572. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5573. if temp_advice.ID == 0 {
  5574. advices = append(advices, &advice)
  5575. }
  5576. }
  5577. if len(advices) > 0 {
  5578. finish := models.XtDialysisFinish{
  5579. IsFinish: 1,
  5580. UserOrgId: adminUserInfo.Org.Id,
  5581. Status: 1,
  5582. Ctime: time.Now().Unix(),
  5583. Mtime: 0,
  5584. Module: 4,
  5585. RecordDate: AdviceDate,
  5586. Sourse: 1,
  5587. PatientId: patient,
  5588. }
  5589. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5590. if dialysisFinish.ID == 0 {
  5591. service.CreateDialysisFinish(finish)
  5592. }
  5593. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5594. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5595. for _, item := range advices {
  5596. byterequest, _ := json.Marshal(item)
  5597. adviceLog := models.XtDoctorAdviceLog{
  5598. UserOrgId: adminUserInfo.Org.Id,
  5599. PatientId: patient,
  5600. AdminUserId: adminUserInfo.AdminUser.Id,
  5601. Module: 1,
  5602. ErrLog: string(byterequest),
  5603. Status: 1,
  5604. Ctime: time.Now().Unix(),
  5605. Mtime: 0,
  5606. Source: "手机端医嘱推送",
  5607. RecordDate: item.AdviceDate,
  5608. }
  5609. service.CreateDoctorAdviceLog(adviceLog)
  5610. }
  5611. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5612. redis := service.RedisClient()
  5613. //清空key 值
  5614. redis.Set(key, "", time.Second)
  5615. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5616. redis.Set(keyOne, "", time.Second)
  5617. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5618. defer redis.Close()
  5619. redis.Set(keyThree, "", time.Second)
  5620. if err != nil {
  5621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5622. return
  5623. }
  5624. c.ServeSuccessJSON(map[string]interface{}{
  5625. "msg": "ok",
  5626. "advices": list,
  5627. })
  5628. } else {
  5629. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5630. for _, item := range advices {
  5631. byterequest, _ := json.Marshal(item)
  5632. adviceLog := models.XtDoctorAdviceLog{
  5633. UserOrgId: adminUserInfo.Org.Id,
  5634. PatientId: patient,
  5635. AdminUserId: adminUserInfo.AdminUser.Id,
  5636. Module: 1,
  5637. ErrLog: string(byterequest),
  5638. Status: 1,
  5639. Ctime: time.Now().Unix(),
  5640. Mtime: 0,
  5641. Source: "手机端医嘱推送",
  5642. RecordDate: item.AdviceDate,
  5643. }
  5644. service.CreateDoctorAdviceLog(adviceLog)
  5645. }
  5646. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5647. redis := service.RedisClient()
  5648. //清空key 值
  5649. redis.Set(key, "", time.Second)
  5650. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5651. redis.Set(keyOne, "", time.Second)
  5652. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5653. defer redis.Close()
  5654. redis.Set(keyThree, "", time.Second)
  5655. if err != nil {
  5656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5657. return
  5658. }
  5659. c.ServeSuccessJSON(map[string]interface{}{
  5660. "msg": "ok",
  5661. "advices": list,
  5662. })
  5663. }
  5664. } else {
  5665. c.ServeSuccessJSON(map[string]interface{}{
  5666. "msg": "ok",
  5667. })
  5668. }
  5669. return
  5670. }
  5671. func (c *DialysisAPIController) UploadDryWeight() {
  5672. patient_id, _ := c.GetInt64("id")
  5673. dry_weight, _ := c.GetFloat("dry_weight")
  5674. doctor_id, _ := c.GetInt64("doctor_id")
  5675. remark := c.GetString("remark")
  5676. adminUserInfo := c.GetMobileAdminUserInfo()
  5677. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5678. if err == gorm.ErrRecordNotFound {
  5679. dryWeight := &models.SgjPatientDryweight{
  5680. PatientId: patient_id,
  5681. DryWeight: dry_weight,
  5682. Remakes: remark,
  5683. Ctime: time.Now().Unix(),
  5684. Mtime: time.Now().Unix(),
  5685. Creator: doctor_id,
  5686. Status: 1,
  5687. UserOrgId: adminUserInfo.Org.Id,
  5688. AdjustedValue: "/",
  5689. UserId: adminUserInfo.AdminUser.Id,
  5690. }
  5691. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5692. redis := service.RedisClient()
  5693. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5694. redis.Set(keyOne, "", time.Second)
  5695. loc, _ := time.LoadLocation("Local")
  5696. nowTime := time.Now()
  5697. nowDay := nowTime.Format("2006-01-02")
  5698. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5699. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5700. redis.Set(key, "", time.Second)
  5701. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5702. redis.Set(keyTwo, "", time.Second)
  5703. redis.Close()
  5704. if createErr == nil {
  5705. c.ServeSuccessJSON(map[string]interface{}{
  5706. "msg": "提交成功",
  5707. "weight": dryWeight,
  5708. })
  5709. }
  5710. } else {
  5711. dryWeight := &models.SgjPatientDryweight{
  5712. PatientId: patient_id,
  5713. DryWeight: dry_weight,
  5714. Remakes: remark,
  5715. Ctime: time.Now().Unix(),
  5716. Mtime: time.Now().Unix(),
  5717. Creator: doctor_id,
  5718. Status: 1,
  5719. UserOrgId: adminUserInfo.Org.Id,
  5720. AdjustedValue: "/",
  5721. UserId: adminUserInfo.AdminUser.Id,
  5722. }
  5723. var value float64
  5724. value = dry_weight - weightAdjust.DryWeight
  5725. if value < 0 {
  5726. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5727. } else if value == 0 {
  5728. dryWeight.AdjustedValue = "/"
  5729. } else if value > 0 {
  5730. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5731. }
  5732. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5733. //康桥
  5734. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  5735. timeNowStr := time.Now().Format("2006-01-02")
  5736. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5737. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5738. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5739. if beforAssesment.ID > 0 {
  5740. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5741. var dewater_amount float64
  5742. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5743. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5744. //获取key,清空redis
  5745. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5746. redis := service.RedisClient()
  5747. //清空key 值
  5748. redis.Set(key, "", time.Second)
  5749. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5750. //清空key 值
  5751. redis.Set(keyOne, "", time.Second)
  5752. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5753. //清空key 值
  5754. redis.Set(keyTwo, "", time.Second)
  5755. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5756. redis.Set(keySix, "", time.Second)
  5757. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5758. redis.Set(keySeven, "", time.Second)
  5759. }
  5760. }
  5761. redis := service.RedisClient()
  5762. loc, _ := time.LoadLocation("Local")
  5763. nowTime := time.Now()
  5764. nowDay := nowTime.Format("2006-01-02")
  5765. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5766. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5767. redis.Set(keyOne, "", time.Second)
  5768. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5769. redis.Set(key, "", time.Second)
  5770. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5771. redis.Set(keyTwo, "", time.Second)
  5772. redis.Close()
  5773. if createErr == nil {
  5774. c.ServeSuccessJSON(map[string]interface{}{
  5775. "msg": "提交成功",
  5776. "weight": dryWeight,
  5777. })
  5778. }
  5779. }
  5780. }
  5781. func (c *DialysisAPIController) GetSolution() {
  5782. patient_id, _ := c.GetInt64("patient_id")
  5783. mode_id, _ := c.GetInt64("mode_id")
  5784. adminUserInfo := c.GetMobileAdminUserInfo()
  5785. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5786. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5787. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5788. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5789. if err != nil {
  5790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5791. return
  5792. }
  5793. c.ServeSuccessJSON(map[string]interface{}{
  5794. "solution": solution,
  5795. "prescription": prescription,
  5796. "system_prescription": system_prescription,
  5797. "dialysisPrescription": dialysisPrescription,
  5798. })
  5799. }
  5800. func (c *DialysisAPIController) GetSchedule() {
  5801. schedual_type, _ := c.GetInt64("schedual_type")
  5802. adminUserInfo := c.GetMobileAdminUserInfo()
  5803. scheduleTime, _ := c.GetInt64("record_date")
  5804. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5805. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5806. c.ServeSuccessJSON(map[string]interface{}{
  5807. "number": deviceNumber,
  5808. "list": list,
  5809. })
  5810. }
  5811. func (c *DialysisAPIController) GetPatientId() {
  5812. id, _ := c.GetInt64("id")
  5813. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5814. patientId, _ := service.GetPatientId(id)
  5815. //获取该患者的所有传染病
  5816. list, _ := service.GetPatientInfectious(id)
  5817. c.ServeSuccessJSON(map[string]interface{}{
  5818. "patient": patientId,
  5819. "infectioulist": list,
  5820. })
  5821. }
  5822. func (this *DialysisAPIController) GetDialysisSchedule() {
  5823. schedualDate := this.GetString("date")
  5824. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5825. if parseDateErr != nil {
  5826. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5827. return
  5828. }
  5829. adminInfo := this.GetMobileAdminUserInfo()
  5830. orgID := adminInfo.Org.Id
  5831. redis := service.RedisClient()
  5832. defer redis.Close()
  5833. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5834. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5835. if len(scheduals) > 0 {
  5836. //缓存数据
  5837. scheduals_json, err := json.Marshal(scheduals)
  5838. if err == nil {
  5839. redis.Set(key, scheduals_json, time.Second*30)
  5840. }
  5841. }
  5842. this.ServeSuccessJSON(map[string]interface{}{
  5843. "scheduals": scheduals,
  5844. })
  5845. }
  5846. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5847. change_type, _ := this.GetInt64("type", 0)
  5848. record_date := this.GetString("record_time")
  5849. patient_id, _ := this.GetInt64("patient_id", 0)
  5850. timeLayout := "2006-01-02"
  5851. loc, _ := time.LoadLocation("Local")
  5852. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5853. record_time := theAdviceRecordTime.Unix()
  5854. adminUserInfo := this.GetMobileAdminUserInfo()
  5855. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5856. if err == nil {
  5857. if len(advices) == 0 {
  5858. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5859. return
  5860. } else {
  5861. this.ServeSuccessJSON(map[string]interface{}{
  5862. "advices": advices,
  5863. "schedule": sch,
  5864. })
  5865. return
  5866. }
  5867. } else {
  5868. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5869. return
  5870. }
  5871. }
  5872. func (c *DialysisAPIController) CreateConsumables() {
  5873. record_date := c.GetString("record_time")
  5874. patient_id, _ := c.GetInt64("patient_id", 0)
  5875. active, _ := c.GetInt64("active")
  5876. adminUser := c.GetMobileAdminUserInfo()
  5877. timeLayout := "2006-01-02"
  5878. loc, _ := time.LoadLocation("Local")
  5879. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5880. record_time := theRecordTime.Unix()
  5881. // 查询信息规挡的设置天数
  5882. orgid := c.GetMobileAdminUserInfo().Org.Id
  5883. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5884. if infor.ID > 0 {
  5885. var cha_time int64
  5886. timeNowStr := time.Now().Format("2006-01-02")
  5887. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5888. //今日的日期减去设置的日期
  5889. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5890. if cha_time >= record_time {
  5891. //查询审核是否允许
  5892. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5893. //申请状态不允许的情况 拒绝修改
  5894. if infor.ApplicationStatus != 1 {
  5895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5896. return
  5897. }
  5898. }
  5899. }
  5900. dataBody := make(map[string]interface{}, 0)
  5901. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5902. if err != nil {
  5903. utils.ErrorLog(err.Error())
  5904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5905. return
  5906. }
  5907. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5908. var beforePrepares []*models.DialysisBeforePrepareGoods
  5909. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5910. var dialysisBefor []*models.DialysisBeforePrepare
  5911. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5912. goods, _ := dataBody["goods"].([]interface{})
  5913. if len(goods) > 0 {
  5914. for _, item := range goods {
  5915. items := item.(map[string]interface{})
  5916. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5917. utils.ErrorLog("good_id")
  5918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5919. return
  5920. }
  5921. good_id := int64(items["good_id"].(float64))
  5922. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5923. utils.ErrorLog("good_type_id")
  5924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5925. return
  5926. }
  5927. good_type_id := int64(items["good_type_id"].(float64))
  5928. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5929. utils.ErrorLog("count")
  5930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5931. return
  5932. }
  5933. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5934. commdity_code := items["commdity_code"].(string)
  5935. fmt.Println("commdity", commdity_code)
  5936. prepareGoods := &models.DialysisBeforePrepareGoods{
  5937. GoodTypeId: good_type_id,
  5938. GoodId: good_id,
  5939. Count: count,
  5940. StorehouseId: houseConfig.StorehouseOutInfo,
  5941. }
  5942. beforePrepares = append(beforePrepares, prepareGoods)
  5943. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5944. GoodTypeId: good_type_id,
  5945. GoodId: good_id,
  5946. Count: count,
  5947. StorehouseId: houseConfig.StorehouseOutInfo,
  5948. }
  5949. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5950. prepare := &models.DialysisBeforePrepare{
  5951. GoodTypeId: good_type_id,
  5952. GoodId: good_id,
  5953. Count: count,
  5954. PatientId: patient_id,
  5955. RecordDate: record_time,
  5956. UserOrgId: adminUser.Org.Id,
  5957. Status: 1,
  5958. Ctime: time.Now().Unix(),
  5959. Creater: adminUser.AdminUser.Id,
  5960. CommdityCode: commdity_code,
  5961. StorehouseId: houseConfig.StorehouseOutInfo,
  5962. }
  5963. dialysisBefor = append(dialysisBefor, prepare)
  5964. }
  5965. }
  5966. //查询是否有库存
  5967. for _, item := range dialysisBefor {
  5968. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5969. if err == gorm.ErrRecordNotFound {
  5970. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5971. c.ServeSuccessJSON(map[string]interface{}{
  5972. "message": "1",
  5973. "good_name": goodObj.GoodName,
  5974. "specification_name": goodObj.SpecificationName,
  5975. })
  5976. return
  5977. }
  5978. if err != nil {
  5979. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5980. c.ServeSuccessJSON(map[string]interface{}{
  5981. "message": "1",
  5982. "good_name": goodObj.GoodName,
  5983. "specification_name": goodObj.SpecificationName,
  5984. })
  5985. return
  5986. }
  5987. }
  5988. fmt.Println("active-----------------------", active)
  5989. fmt.Println("len(goods)-----------------------", len(goods))
  5990. //新增
  5991. if active == 1 && len(goods) > 0 {
  5992. for _, item := range dialysisBefor {
  5993. dialyPrepareOne := models.DialysisBeforePrepare{
  5994. GoodTypeId: item.GoodTypeId,
  5995. GoodId: item.GoodId,
  5996. PatientId: item.PatientId,
  5997. RecordDate: item.RecordDate,
  5998. UserOrgId: item.UserOrgId,
  5999. Count: item.Count,
  6000. Ctime: time.Now().Unix(),
  6001. Creater: item.Creater,
  6002. CommdityCode: item.CommdityCode,
  6003. Status: 1,
  6004. StorehouseId: houseConfig.StorehouseOutInfo,
  6005. }
  6006. //先清除再插入
  6007. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6008. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  6009. //查询默认仓库
  6010. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6011. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6012. var total_count int64
  6013. for _, it := range stockList {
  6014. total_count += it.StockCount
  6015. }
  6016. //基础库插入数据
  6017. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6018. //更新库存
  6019. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6020. var flush_count int64
  6021. for _, it := range goodList {
  6022. flush_count += it.StockCount
  6023. }
  6024. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6025. }
  6026. if err == nil {
  6027. c.ServeSuccessJSON(map[string]interface{}{
  6028. "msg": "保存成功",
  6029. "message": "2",
  6030. })
  6031. return
  6032. } else {
  6033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6034. return
  6035. }
  6036. }
  6037. if len(beforePrepares) > 0 && active == 2 {
  6038. for _, item := range beforePrepares {
  6039. //1.查看该患者该耗材型号最后一次出库数量
  6040. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6041. //判断当前出库数量和最后一次出库数量的大小
  6042. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  6043. if item.Count <= goodInfo.Count {
  6044. //退库
  6045. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  6046. //查询今日出库数据
  6047. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6048. for _, it := range list {
  6049. prepare := models.DialysisBeforePrepare{
  6050. UserOrgId: it.OrgId,
  6051. PatientId: patient_id,
  6052. RecordDate: it.RecordTime,
  6053. GoodId: it.GoodId,
  6054. GoodTypeId: it.GoodTypeId,
  6055. Count: it.Count,
  6056. Ctime: time.Now().Unix(),
  6057. Creater: adminUser.AdminUser.Id,
  6058. Status: 1,
  6059. StorehouseId: houseConfig.StorehouseOutInfo,
  6060. }
  6061. //删除准备表数据
  6062. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6063. service.CreateDialysisBeforePrepareOne(&prepare)
  6064. }
  6065. }
  6066. var last_total int64
  6067. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6068. if item.Count >= goodInfo.Count {
  6069. //查询当前批次当前耗材最后一条出库数据
  6070. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6071. //计算当前出库和最后一次出库数据相差数据
  6072. last_total = item.Count - lastOutInfo.Count
  6073. //查询该批次剩余库存
  6074. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  6075. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  6076. if lastInfo.StockCount >= last_total {
  6077. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6078. //查询今日出库数据
  6079. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6080. for _, it := range list {
  6081. prepare := models.DialysisBeforePrepare{
  6082. UserOrgId: it.OrgId,
  6083. PatientId: patient_id,
  6084. RecordDate: it.RecordTime,
  6085. GoodId: it.GoodId,
  6086. GoodTypeId: it.GoodTypeId,
  6087. Count: it.Count,
  6088. Ctime: time.Now().Unix(),
  6089. Creater: adminUser.AdminUser.Id,
  6090. Status: 1,
  6091. StorehouseId: houseConfig.StorehouseOutInfo,
  6092. }
  6093. //删除准备表数据
  6094. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6095. service.CreateDialysisBeforePrepareOne(&prepare)
  6096. //查询默认仓库
  6097. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6098. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6099. var total_count int64
  6100. for _, it := range stockList {
  6101. total_count += it.StockCount
  6102. }
  6103. //基础库插入数据
  6104. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6105. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6106. var flush_count int64
  6107. for _, it := range goodList {
  6108. flush_count += it.StockCount
  6109. }
  6110. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6111. }
  6112. }
  6113. //如果库存不够,则出库到下一个批次
  6114. if lastInfo.StockCount < last_total {
  6115. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6116. //查询今日出库数据
  6117. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6118. for _, it := range list {
  6119. prepare := models.DialysisBeforePrepare{
  6120. UserOrgId: it.OrgId,
  6121. PatientId: patient_id,
  6122. RecordDate: it.RecordTime,
  6123. GoodId: it.GoodId,
  6124. GoodTypeId: it.GoodTypeId,
  6125. Count: it.Count,
  6126. Ctime: time.Now().Unix(),
  6127. Creater: adminUser.AdminUser.Id,
  6128. Status: 1,
  6129. StorehouseId: houseConfig.StorehouseOutInfo,
  6130. }
  6131. //删除准备表数据
  6132. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6133. service.CreateDialysisBeforePrepareOne(&prepare)
  6134. //查询默认仓库
  6135. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6136. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6137. var total_count int64
  6138. for _, it := range stockList {
  6139. total_count += it.StockCount
  6140. }
  6141. //基础库插入数据
  6142. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6143. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6144. var flush_count int64
  6145. for _, it := range goodList {
  6146. flush_count += it.StockCount
  6147. }
  6148. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6149. }
  6150. if err != nil {
  6151. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6152. c.ServeSuccessJSON(map[string]interface{}{
  6153. "message": "1",
  6154. "good_name": goodObj.GoodName,
  6155. "specification_name": goodObj.SpecificationName,
  6156. })
  6157. return
  6158. }
  6159. }
  6160. }
  6161. if err != nil {
  6162. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6163. c.ServeSuccessJSON(map[string]interface{}{
  6164. "message": "1",
  6165. "good_name": goodObj.GoodName,
  6166. "specification_name": goodObj.SpecificationName,
  6167. })
  6168. return
  6169. }
  6170. }
  6171. }
  6172. }
  6173. var errs error
  6174. if errs == nil {
  6175. c.ServeSuccessJSON(map[string]interface{}{
  6176. "msg": "提交成功",
  6177. "message": "2",
  6178. "good_name": "",
  6179. "specification_name": "",
  6180. })
  6181. return
  6182. } else {
  6183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6184. return
  6185. }
  6186. }
  6187. func (c *DialysisAPIController) CreateStockOutInfo() {
  6188. patient_id, _ := c.GetInt64("patient_id", 0)
  6189. record_date := c.GetString("record_time")
  6190. if patient_id <= 0 {
  6191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6192. return
  6193. }
  6194. adminInfo := c.GetMobileAdminUserInfo()
  6195. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6196. timeLayout := "2006-01-02"
  6197. loc, _ := time.LoadLocation("Local")
  6198. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6199. record_time := theRecordTime.Unix()
  6200. // 查询信息规挡的设置天数
  6201. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6202. if infor.ID > 0 && infor.WeekDay > 0 {
  6203. var cha_time int64
  6204. timeNowStr := time.Now().Format("2006-01-02")
  6205. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6206. //今日的日期减去设置的日期
  6207. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6208. if cha_time >= record_time {
  6209. //查询审核是否允许
  6210. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6211. //申请状态不允许的情况 拒绝修改
  6212. if infor.ApplicationStatus != 1 {
  6213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6214. return
  6215. }
  6216. }
  6217. }
  6218. //创建步骤表
  6219. finish := models.XtDialysisFinish{
  6220. IsFinish: 1,
  6221. UserOrgId: adminInfo.Org.Id,
  6222. Status: 1,
  6223. Ctime: time.Now().Unix(),
  6224. Mtime: 0,
  6225. Module: 11,
  6226. RecordDate: record_time,
  6227. Sourse: 1,
  6228. PatientId: patient_id,
  6229. }
  6230. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6231. if dialysisFinish.ID == 0 {
  6232. service.CreateDialysisFinish(finish)
  6233. }
  6234. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6235. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6236. //去重
  6237. consumables = RemoveRepeatedGood(consumables)
  6238. if adminInfo.Org.Id == 9919 {
  6239. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6240. //查询是否有库存
  6241. for _, item := range consumables {
  6242. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6243. if item.Count > warehouse.Count {
  6244. goodErrcode := models.XtGoodErrcode{
  6245. UserOrgId: item.UserOrgId,
  6246. Errcode: "自动出库库存不足",
  6247. GoodId: item.GoodId,
  6248. Status: 1,
  6249. Ctime: time.Now().Unix(),
  6250. Mtime: 0,
  6251. Count: 0,
  6252. StockCount: 0,
  6253. Creater: creator,
  6254. BatchNumberId: warehouse.ID,
  6255. WarehouseOutId: 0,
  6256. }
  6257. service.CreateGoodErrcode(goodErrcode)
  6258. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6259. c.ServeSuccessJSON(map[string]interface{}{
  6260. "message": "1",
  6261. "good_name": goodObj.GoodName,
  6262. "specification_name": goodObj.SpecificationName,
  6263. })
  6264. return
  6265. }
  6266. }
  6267. //查询是否有出库单
  6268. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6269. if err == gorm.ErrRecordNotFound {
  6270. //没有记录,则创建出库单
  6271. timeStr := time.Now().Format("2006-01-02")
  6272. timeArr := strings.Split(timeStr, "-")
  6273. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6274. total = total + 1
  6275. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6276. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6277. number = number + total
  6278. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6279. creater := adminInfo.AdminUser.Id
  6280. warehouseOut := models.WarehouseOut{
  6281. WarehouseOutOrderNumber: warehousing_out_order,
  6282. OperationTime: time.Now().Unix(),
  6283. OrgId: adminInfo.Org.Id,
  6284. Creater: creater,
  6285. Ctime: time.Now().Unix(),
  6286. Status: 1,
  6287. WarehouseOutTime: record_time,
  6288. Dealer: 0,
  6289. Manufacturer: 0,
  6290. Type: 1,
  6291. IsSys: 1,
  6292. StorehouseId: houseConfig.StorehouseOutInfo,
  6293. IsCheck: 1,
  6294. }
  6295. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6296. if err != nil {
  6297. goodErrcode := models.XtGoodErrcode{
  6298. UserOrgId: adminInfo.Org.Id,
  6299. Errcode: "创建出库单失败",
  6300. GoodId: 0,
  6301. Status: 1,
  6302. Ctime: time.Now().Unix(),
  6303. Mtime: 0,
  6304. Count: 0,
  6305. StockCount: 0,
  6306. Creater: creator,
  6307. BatchNumberId: 0,
  6308. WarehouseOutId: 0,
  6309. }
  6310. service.CreateGoodErrcode(goodErrcode)
  6311. utils.TraceLog("创建出库单失败 err = %v", err)
  6312. } else {
  6313. for _, item := range consumables {
  6314. //出库
  6315. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6316. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6317. if err == nil {
  6318. goodErrcode := models.XtGoodErrcode{
  6319. UserOrgId: adminInfo.Org.Id,
  6320. Errcode: "自动出库接口报错",
  6321. GoodId: 0,
  6322. Status: 1,
  6323. Ctime: time.Now().Unix(),
  6324. Mtime: 0,
  6325. Count: 0,
  6326. StockCount: 0,
  6327. Creater: creator,
  6328. BatchNumberId: 0,
  6329. WarehouseOutId: 0,
  6330. }
  6331. service.CreateGoodErrcode(goodErrcode)
  6332. utils.TraceLog("创建出库单失败 err = %v", err)
  6333. }
  6334. //查询
  6335. //出库数量相加
  6336. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6337. if errs != nil {
  6338. goodErrcode := models.XtGoodErrcode{
  6339. UserOrgId: item.UserOrgId,
  6340. Errcode: "创建剩余库存字段报错",
  6341. GoodId: item.GoodId,
  6342. Status: 1,
  6343. Ctime: time.Now().Unix(),
  6344. Mtime: 0,
  6345. Count: 0,
  6346. StockCount: 0,
  6347. Creater: creater,
  6348. BatchNumberId: 0,
  6349. WarehouseOutId: 0,
  6350. }
  6351. service.CreateGoodErrcode(goodErrcode)
  6352. }
  6353. }
  6354. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6355. if len(list) == 0 {
  6356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6357. return
  6358. }
  6359. for _, item := range list {
  6360. prepare := models.DialysisBeforePrepare{
  6361. UserOrgId: adminInfo.Org.Id,
  6362. PatientId: patient_id,
  6363. RecordDate: record_time,
  6364. GoodId: item.GoodId,
  6365. GoodTypeId: item.GoodTypeId,
  6366. Count: item.Count,
  6367. Creater: adminInfo.AdminUser.Id,
  6368. Status: 1,
  6369. Ctime: time.Now().Unix(),
  6370. StorehouseId: houseConfig.StorehouseOutInfo,
  6371. }
  6372. //清空准备表数据
  6373. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6374. if err != nil {
  6375. goodErrcode := models.XtGoodErrcode{
  6376. UserOrgId: item.OrgId,
  6377. Errcode: "自动出库清空准备表数据报错",
  6378. GoodId: item.GoodId,
  6379. Status: 1,
  6380. Ctime: time.Now().Unix(),
  6381. Mtime: 0,
  6382. Count: 0,
  6383. StockCount: 0,
  6384. Creater: creater,
  6385. BatchNumberId: 0,
  6386. WarehouseOutId: 0,
  6387. }
  6388. service.CreateGoodErrcode(goodErrcode)
  6389. }
  6390. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6391. if errs != nil {
  6392. goodErrcode := models.XtGoodErrcode{
  6393. UserOrgId: item.OrgId,
  6394. Errcode: "自动出库创建准备表数据报错",
  6395. GoodId: item.GoodId,
  6396. Status: 1,
  6397. Ctime: time.Now().Unix(),
  6398. Mtime: 0,
  6399. Count: 0,
  6400. StockCount: 0,
  6401. Creater: creater,
  6402. BatchNumberId: 0,
  6403. WarehouseOutId: 0,
  6404. }
  6405. service.CreateGoodErrcode(goodErrcode)
  6406. }
  6407. //查询默认仓库
  6408. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6409. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6410. var total_count int64
  6411. for _, it := range stockList {
  6412. total_count += it.StockCount
  6413. }
  6414. //基础库插入数据
  6415. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6416. if errcodes != nil {
  6417. goodErrcode := models.XtGoodErrcode{
  6418. UserOrgId: item.OrgId,
  6419. Errcode: "自动出库基础库插入数据",
  6420. GoodId: item.GoodId,
  6421. Status: 1,
  6422. Ctime: time.Now().Unix(),
  6423. Mtime: 0,
  6424. Count: 0,
  6425. StockCount: 0,
  6426. Creater: creater,
  6427. BatchNumberId: 0,
  6428. WarehouseOutId: 0,
  6429. }
  6430. service.CreateGoodErrcode(goodErrcode)
  6431. }
  6432. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6433. var flush_count int64
  6434. for _, it := range goodList {
  6435. flush_count += it.StockCount
  6436. }
  6437. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6438. if errsss != nil {
  6439. goodErrcode := models.XtGoodErrcode{
  6440. UserOrgId: item.OrgId,
  6441. Errcode: "自动出库剩余库存更新数据",
  6442. GoodId: item.GoodId,
  6443. Status: 1,
  6444. Ctime: time.Now().Unix(),
  6445. Mtime: 0,
  6446. Count: 0,
  6447. StockCount: 0,
  6448. Creater: creater,
  6449. BatchNumberId: 0,
  6450. WarehouseOutId: 0,
  6451. }
  6452. service.CreateGoodErrcode(goodErrcode)
  6453. }
  6454. }
  6455. }
  6456. //
  6457. } else if err == nil {
  6458. for _, item := range consumables {
  6459. //出库
  6460. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6461. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6462. if err != nil {
  6463. goodErrcode := models.XtGoodErrcode{
  6464. UserOrgId: adminInfo.Org.Id,
  6465. Errcode: "自动出库接口报错",
  6466. GoodId: 0,
  6467. Status: 1,
  6468. Ctime: time.Now().Unix(),
  6469. Mtime: 0,
  6470. Count: 0,
  6471. StockCount: 0,
  6472. Creater: creator,
  6473. BatchNumberId: 0,
  6474. WarehouseOutId: 0,
  6475. }
  6476. service.CreateGoodErrcode(goodErrcode)
  6477. }
  6478. //出库数量相加
  6479. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6480. if errss != nil {
  6481. goodErrcode := models.XtGoodErrcode{
  6482. UserOrgId: item.UserOrgId,
  6483. Errcode: "创建剩余库存字段报错",
  6484. GoodId: item.GoodId,
  6485. Status: 1,
  6486. Ctime: time.Now().Unix(),
  6487. Mtime: time.Now().Unix(),
  6488. Count: 0,
  6489. StockCount: 0,
  6490. Creater: item.Creater,
  6491. BatchNumberId: 0,
  6492. WarehouseOutId: 0,
  6493. }
  6494. service.CreateGoodErrcode(goodErrcode)
  6495. }
  6496. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6497. if len(list) == 0 {
  6498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6499. return
  6500. }
  6501. for _, item := range list {
  6502. prepare := models.DialysisBeforePrepare{
  6503. UserOrgId: adminInfo.Org.Id,
  6504. PatientId: patient_id,
  6505. RecordDate: record_time,
  6506. GoodId: item.GoodId,
  6507. GoodTypeId: item.GoodTypeId,
  6508. Count: item.Count,
  6509. Creater: adminInfo.AdminUser.Id,
  6510. Status: 1,
  6511. Ctime: time.Now().Unix(),
  6512. StorehouseId: houseConfig.StorehouseOutInfo,
  6513. }
  6514. //清空准备表数据
  6515. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6516. if errs != nil {
  6517. goodErrcode := models.XtGoodErrcode{
  6518. UserOrgId: adminInfo.Org.Id,
  6519. Errcode: "自动出库清空准备表数据报错",
  6520. GoodId: 0,
  6521. Status: 1,
  6522. Ctime: time.Now().Unix(),
  6523. Mtime: 0,
  6524. Count: 0,
  6525. StockCount: 0,
  6526. Creater: creator,
  6527. BatchNumberId: 0,
  6528. WarehouseOutId: 0,
  6529. }
  6530. service.CreateGoodErrcode(goodErrcode)
  6531. }
  6532. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6533. if errcodes != nil {
  6534. goodErrcode := models.XtGoodErrcode{
  6535. UserOrgId: adminInfo.Org.Id,
  6536. Errcode: "自动出库创建准备表数据报错",
  6537. GoodId: 0,
  6538. Status: 1,
  6539. Ctime: time.Now().Unix(),
  6540. Mtime: 0,
  6541. Count: 0,
  6542. StockCount: 0,
  6543. Creater: creator,
  6544. BatchNumberId: 0,
  6545. WarehouseOutId: 0,
  6546. }
  6547. service.CreateGoodErrcode(goodErrcode)
  6548. }
  6549. //查询默认仓库
  6550. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6551. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6552. var total_count int64
  6553. for _, it := range stockList {
  6554. total_count += it.StockCount
  6555. }
  6556. //基础库插入数据
  6557. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6558. if errcodes != nil {
  6559. goodErrcode := models.XtGoodErrcode{
  6560. UserOrgId: adminInfo.Org.Id,
  6561. Errcode: "自动出库基础库插入数据报错",
  6562. GoodId: 0,
  6563. Status: 1,
  6564. Ctime: time.Now().Unix(),
  6565. Mtime: 0,
  6566. Count: 0,
  6567. StockCount: 0,
  6568. Creater: creator,
  6569. BatchNumberId: 0,
  6570. WarehouseOutId: 0,
  6571. }
  6572. service.CreateGoodErrcode(goodErrcode)
  6573. }
  6574. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6575. var flush_count int64
  6576. for _, it := range goodList {
  6577. flush_count += it.StockCount
  6578. }
  6579. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6580. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6581. if errss != nil {
  6582. goodErrcode := models.XtGoodErrcode{
  6583. UserOrgId: item.OrgId,
  6584. Errcode: "自动出库剩余库存更新数据",
  6585. GoodId: item.GoodId,
  6586. Status: 1,
  6587. Ctime: time.Now().Unix(),
  6588. Mtime: 0,
  6589. Count: 0,
  6590. StockCount: 0,
  6591. Creater: creater,
  6592. BatchNumberId: 0,
  6593. WarehouseOutId: 0,
  6594. }
  6595. service.CreateGoodErrcode(goodErrcode)
  6596. }
  6597. }
  6598. }
  6599. }
  6600. c.ServeSuccessJSON(map[string]interface{}{
  6601. "msg": "提交成功",
  6602. "message": "2",
  6603. "good_name": "",
  6604. "specification_name": "",
  6605. })
  6606. return
  6607. }
  6608. if record.IsOpen == 1 {
  6609. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6610. //查询是否有库存
  6611. for _, item := range consumables {
  6612. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6613. if item.Count > warehouse.Count {
  6614. goodErrcode := models.XtGoodErrcode{
  6615. UserOrgId: item.UserOrgId,
  6616. Errcode: "自动出库库存不足",
  6617. GoodId: item.GoodId,
  6618. Status: 1,
  6619. Ctime: time.Now().Unix(),
  6620. Mtime: 0,
  6621. Count: 0,
  6622. StockCount: 0,
  6623. Creater: creator,
  6624. BatchNumberId: warehouse.ID,
  6625. WarehouseOutId: 0,
  6626. }
  6627. service.CreateGoodErrcode(goodErrcode)
  6628. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6629. c.ServeSuccessJSON(map[string]interface{}{
  6630. "message": "1",
  6631. "good_name": goodObj.GoodName,
  6632. "specification_name": goodObj.SpecificationName,
  6633. })
  6634. return
  6635. }
  6636. }
  6637. //查询是否有出库单
  6638. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6639. if err == gorm.ErrRecordNotFound {
  6640. //没有记录,则创建出库单
  6641. timeStr := time.Now().Format("2006-01-02")
  6642. timeArr := strings.Split(timeStr, "-")
  6643. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6644. total = total + 1
  6645. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6646. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6647. number = number + total
  6648. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6649. creater := adminInfo.AdminUser.Id
  6650. warehouseOut := models.WarehouseOut{
  6651. WarehouseOutOrderNumber: warehousing_out_order,
  6652. OperationTime: time.Now().Unix(),
  6653. OrgId: adminInfo.Org.Id,
  6654. Creater: creater,
  6655. Ctime: time.Now().Unix(),
  6656. Status: 1,
  6657. WarehouseOutTime: record_time,
  6658. Dealer: 0,
  6659. Manufacturer: 0,
  6660. Type: 1,
  6661. IsSys: 1,
  6662. StorehouseId: houseConfig.StorehouseOutInfo,
  6663. IsCheck: 1,
  6664. }
  6665. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6666. if err != nil {
  6667. goodErrcode := models.XtGoodErrcode{
  6668. UserOrgId: adminInfo.Org.Id,
  6669. Errcode: "创建出库单失败",
  6670. GoodId: 0,
  6671. Status: 1,
  6672. Ctime: time.Now().Unix(),
  6673. Mtime: 0,
  6674. Count: 0,
  6675. StockCount: 0,
  6676. Creater: creator,
  6677. BatchNumberId: 0,
  6678. WarehouseOutId: 0,
  6679. }
  6680. service.CreateGoodErrcode(goodErrcode)
  6681. utils.TraceLog("创建出库单失败 err = %v", err)
  6682. } else {
  6683. for _, item := range consumables {
  6684. //出库
  6685. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6686. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6687. if err == nil {
  6688. goodErrcode := models.XtGoodErrcode{
  6689. UserOrgId: adminInfo.Org.Id,
  6690. Errcode: "自动出库接口报错",
  6691. GoodId: 0,
  6692. Status: 1,
  6693. Ctime: time.Now().Unix(),
  6694. Mtime: 0,
  6695. Count: 0,
  6696. StockCount: 0,
  6697. Creater: creator,
  6698. BatchNumberId: 0,
  6699. WarehouseOutId: 0,
  6700. }
  6701. service.CreateGoodErrcode(goodErrcode)
  6702. utils.TraceLog("创建出库单失败 err = %v", err)
  6703. }
  6704. //查询
  6705. //出库数量相加
  6706. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6707. if errs != nil {
  6708. goodErrcode := models.XtGoodErrcode{
  6709. UserOrgId: item.UserOrgId,
  6710. Errcode: "创建剩余库存字段报错",
  6711. GoodId: item.GoodId,
  6712. Status: 1,
  6713. Ctime: time.Now().Unix(),
  6714. Mtime: 0,
  6715. Count: 0,
  6716. StockCount: 0,
  6717. Creater: creater,
  6718. BatchNumberId: 0,
  6719. WarehouseOutId: 0,
  6720. }
  6721. service.CreateGoodErrcode(goodErrcode)
  6722. }
  6723. }
  6724. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6725. if len(list) == 0 {
  6726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6727. return
  6728. }
  6729. for _, item := range list {
  6730. prepare := models.DialysisBeforePrepare{
  6731. UserOrgId: adminInfo.Org.Id,
  6732. PatientId: patient_id,
  6733. RecordDate: record_time,
  6734. GoodId: item.GoodId,
  6735. GoodTypeId: item.GoodTypeId,
  6736. Count: item.Count,
  6737. Creater: adminInfo.AdminUser.Id,
  6738. Status: 1,
  6739. Ctime: time.Now().Unix(),
  6740. StorehouseId: houseConfig.StorehouseOutInfo,
  6741. }
  6742. //清空准备表数据
  6743. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6744. if err != nil {
  6745. goodErrcode := models.XtGoodErrcode{
  6746. UserOrgId: item.OrgId,
  6747. Errcode: "自动出库清空准备表数据报错",
  6748. GoodId: item.GoodId,
  6749. Status: 1,
  6750. Ctime: time.Now().Unix(),
  6751. Mtime: 0,
  6752. Count: 0,
  6753. StockCount: 0,
  6754. Creater: creater,
  6755. BatchNumberId: 0,
  6756. WarehouseOutId: 0,
  6757. }
  6758. service.CreateGoodErrcode(goodErrcode)
  6759. }
  6760. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6761. if errs != nil {
  6762. goodErrcode := models.XtGoodErrcode{
  6763. UserOrgId: item.OrgId,
  6764. Errcode: "自动出库创建准备表数据报错",
  6765. GoodId: item.GoodId,
  6766. Status: 1,
  6767. Ctime: time.Now().Unix(),
  6768. Mtime: 0,
  6769. Count: 0,
  6770. StockCount: 0,
  6771. Creater: creater,
  6772. BatchNumberId: 0,
  6773. WarehouseOutId: 0,
  6774. }
  6775. service.CreateGoodErrcode(goodErrcode)
  6776. }
  6777. //查询默认仓库
  6778. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6779. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6780. var total_count int64
  6781. for _, it := range stockList {
  6782. total_count += it.StockCount
  6783. }
  6784. //基础库插入数据
  6785. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6786. if errcodes != nil {
  6787. goodErrcode := models.XtGoodErrcode{
  6788. UserOrgId: item.OrgId,
  6789. Errcode: "自动出库基础库插入数据",
  6790. GoodId: item.GoodId,
  6791. Status: 1,
  6792. Ctime: time.Now().Unix(),
  6793. Mtime: 0,
  6794. Count: 0,
  6795. StockCount: 0,
  6796. Creater: creater,
  6797. BatchNumberId: 0,
  6798. WarehouseOutId: 0,
  6799. }
  6800. service.CreateGoodErrcode(goodErrcode)
  6801. }
  6802. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6803. var flush_count int64
  6804. for _, it := range goodList {
  6805. flush_count += it.StockCount
  6806. }
  6807. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6808. if errsss != nil {
  6809. goodErrcode := models.XtGoodErrcode{
  6810. UserOrgId: item.OrgId,
  6811. Errcode: "自动出库剩余库存更新数据",
  6812. GoodId: item.GoodId,
  6813. Status: 1,
  6814. Ctime: time.Now().Unix(),
  6815. Mtime: 0,
  6816. Count: 0,
  6817. StockCount: 0,
  6818. Creater: creater,
  6819. BatchNumberId: 0,
  6820. WarehouseOutId: 0,
  6821. }
  6822. service.CreateGoodErrcode(goodErrcode)
  6823. }
  6824. }
  6825. }
  6826. //
  6827. } else if err == nil {
  6828. for _, item := range consumables {
  6829. //出库
  6830. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6831. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6832. if err != nil {
  6833. goodErrcode := models.XtGoodErrcode{
  6834. UserOrgId: adminInfo.Org.Id,
  6835. Errcode: "自动出库接口报错",
  6836. GoodId: 0,
  6837. Status: 1,
  6838. Ctime: time.Now().Unix(),
  6839. Mtime: 0,
  6840. Count: 0,
  6841. StockCount: 0,
  6842. Creater: creator,
  6843. BatchNumberId: 0,
  6844. WarehouseOutId: 0,
  6845. }
  6846. service.CreateGoodErrcode(goodErrcode)
  6847. }
  6848. //出库数量相加
  6849. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6850. if errss != nil {
  6851. goodErrcode := models.XtGoodErrcode{
  6852. UserOrgId: item.UserOrgId,
  6853. Errcode: "创建剩余库存字段报错",
  6854. GoodId: item.GoodId,
  6855. Status: 1,
  6856. Ctime: time.Now().Unix(),
  6857. Mtime: time.Now().Unix(),
  6858. Count: 0,
  6859. StockCount: 0,
  6860. Creater: item.Creater,
  6861. BatchNumberId: 0,
  6862. WarehouseOutId: 0,
  6863. }
  6864. service.CreateGoodErrcode(goodErrcode)
  6865. }
  6866. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6867. if len(list) == 0 {
  6868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6869. return
  6870. }
  6871. for _, item := range list {
  6872. prepare := models.DialysisBeforePrepare{
  6873. UserOrgId: adminInfo.Org.Id,
  6874. PatientId: patient_id,
  6875. RecordDate: record_time,
  6876. GoodId: item.GoodId,
  6877. GoodTypeId: item.GoodTypeId,
  6878. Count: item.Count,
  6879. Creater: adminInfo.AdminUser.Id,
  6880. Status: 1,
  6881. Ctime: time.Now().Unix(),
  6882. StorehouseId: houseConfig.StorehouseOutInfo,
  6883. }
  6884. //清空准备表数据
  6885. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6886. if errs != nil {
  6887. goodErrcode := models.XtGoodErrcode{
  6888. UserOrgId: adminInfo.Org.Id,
  6889. Errcode: "自动出库清空准备表数据报错",
  6890. GoodId: 0,
  6891. Status: 1,
  6892. Ctime: time.Now().Unix(),
  6893. Mtime: 0,
  6894. Count: 0,
  6895. StockCount: 0,
  6896. Creater: creator,
  6897. BatchNumberId: 0,
  6898. WarehouseOutId: 0,
  6899. }
  6900. service.CreateGoodErrcode(goodErrcode)
  6901. }
  6902. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6903. if errcodes != nil {
  6904. goodErrcode := models.XtGoodErrcode{
  6905. UserOrgId: adminInfo.Org.Id,
  6906. Errcode: "自动出库创建准备表数据报错",
  6907. GoodId: 0,
  6908. Status: 1,
  6909. Ctime: time.Now().Unix(),
  6910. Mtime: 0,
  6911. Count: 0,
  6912. StockCount: 0,
  6913. Creater: creator,
  6914. BatchNumberId: 0,
  6915. WarehouseOutId: 0,
  6916. }
  6917. service.CreateGoodErrcode(goodErrcode)
  6918. }
  6919. //查询默认仓库
  6920. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6921. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6922. var total_count int64
  6923. for _, it := range stockList {
  6924. total_count += it.StockCount
  6925. }
  6926. //基础库插入数据
  6927. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6928. if errcodes != nil {
  6929. goodErrcode := models.XtGoodErrcode{
  6930. UserOrgId: adminInfo.Org.Id,
  6931. Errcode: "自动出库基础库插入数据报错",
  6932. GoodId: 0,
  6933. Status: 1,
  6934. Ctime: time.Now().Unix(),
  6935. Mtime: 0,
  6936. Count: 0,
  6937. StockCount: 0,
  6938. Creater: creator,
  6939. BatchNumberId: 0,
  6940. WarehouseOutId: 0,
  6941. }
  6942. service.CreateGoodErrcode(goodErrcode)
  6943. }
  6944. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6945. var flush_count int64
  6946. for _, it := range goodList {
  6947. flush_count += it.StockCount
  6948. }
  6949. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6950. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6951. if errss != nil {
  6952. goodErrcode := models.XtGoodErrcode{
  6953. UserOrgId: item.OrgId,
  6954. Errcode: "自动出库剩余库存更新数据",
  6955. GoodId: item.GoodId,
  6956. Status: 1,
  6957. Ctime: time.Now().Unix(),
  6958. Mtime: 0,
  6959. Count: 0,
  6960. StockCount: 0,
  6961. Creater: creater,
  6962. BatchNumberId: 0,
  6963. WarehouseOutId: 0,
  6964. }
  6965. service.CreateGoodErrcode(goodErrcode)
  6966. }
  6967. }
  6968. }
  6969. }
  6970. c.ServeSuccessJSON(map[string]interface{}{
  6971. "msg": "提交成功",
  6972. "message": "2",
  6973. "good_name": "",
  6974. "specification_name": "",
  6975. })
  6976. return
  6977. } else {
  6978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6979. return
  6980. }
  6981. }
  6982. func (c *DialysisAPIController) EditConsumables() {
  6983. patient_id, _ := c.GetInt64("patient_id", 0)
  6984. record_date := c.GetString("record_time")
  6985. if patient_id <= 0 {
  6986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6987. return
  6988. }
  6989. adminInfo := c.GetMobileAdminUserInfo()
  6990. timeLayout := "2006-01-02"
  6991. loc, _ := time.LoadLocation("Local")
  6992. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6993. record_time := theRecordTime.Unix()
  6994. // 查询信息规挡的设置天数
  6995. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6996. if infor.ID > 0 && infor.WeekDay > 0 {
  6997. var cha_time int64
  6998. timeNowStr := time.Now().Format("2006-01-02")
  6999. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7000. //今日的日期减去设置的日期
  7001. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7002. if cha_time >= record_time {
  7003. //查询审核是否允许
  7004. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7005. //申请状态不允许的情况 拒绝修改
  7006. if infor.ApplicationStatus != 1 {
  7007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7008. return
  7009. }
  7010. }
  7011. }
  7012. dataBody := make(map[string]interface{}, 0)
  7013. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7014. if err != nil {
  7015. utils.ErrorLog(err.Error())
  7016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7017. return
  7018. }
  7019. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7020. var beforePrepares []*models.DialysisBeforePrepareGoods
  7021. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7022. var cancelbefor []*models.DialysisBeforePrepareGoods
  7023. var outbefor []*models.DialysisBeforePrepareGoods
  7024. //判断是否开启自动出库
  7025. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7026. if record.IsOpen == 1 {
  7027. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7028. goods, _ := dataBody["goods"].([]interface{})
  7029. if len(goods) > 0 {
  7030. for _, item := range goods {
  7031. items := item.(map[string]interface{})
  7032. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7033. utils.ErrorLog("good_id")
  7034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7035. return
  7036. }
  7037. good_id := int64(items["good_id"].(float64))
  7038. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7039. utils.ErrorLog("good_type_id")
  7040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7041. return
  7042. }
  7043. good_type_id := int64(items["good_type_id"].(float64))
  7044. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7045. utils.ErrorLog("count")
  7046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7047. return
  7048. }
  7049. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7050. commdity_code := items["commdity_code"].(string)
  7051. fmt.Println(commdity_code)
  7052. prepareGoods := &models.DialysisBeforePrepareGoods{
  7053. GoodTypeId: good_type_id,
  7054. GoodId: good_id,
  7055. Count: count,
  7056. StorehouseId: houseConfig.StorehouseOutInfo,
  7057. }
  7058. beforePrepares = append(beforePrepares, prepareGoods)
  7059. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  7060. GoodTypeId: good_type_id,
  7061. GoodId: good_id,
  7062. Count: count,
  7063. StorehouseId: houseConfig.StorehouseOutInfo,
  7064. }
  7065. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  7066. }
  7067. for _, item := range beforePrepares {
  7068. //1.查看该患者该耗材型号最后一次出库数量
  7069. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7070. //判断当前出库数量和最后一次出库数量的大小
  7071. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  7072. if item.Count < goodInfo.Count {
  7073. cancelbefor = append(cancelbefor, item)
  7074. }
  7075. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  7076. if item.Count > goodInfo.Count {
  7077. outbefor = append(outbefor, item)
  7078. }
  7079. //处理编辑耗材新增不了的问题
  7080. if goodInfo.Count == item.Count {
  7081. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  7082. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  7083. }
  7084. }
  7085. if len(cancelbefor) > 0 {
  7086. //退库
  7087. for _, item := range cancelbefor {
  7088. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7089. creater := adminInfo.AdminUser.Id
  7090. //查询该患者当天已经出库的耗材信息
  7091. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  7092. var delete_count int64 = 0
  7093. delete_count = warehouseOutInfos.Count - item.Count
  7094. //增加库存数量
  7095. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  7096. //减少实际出库库存数量
  7097. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  7098. // 删除出库完成后,要增加对应批次的库存数量
  7099. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  7100. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7101. //更新剩余库存
  7102. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7103. var flush_count int64
  7104. for _, it := range goodListOne {
  7105. flush_count += it.StockCount
  7106. }
  7107. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7108. //查询剩余库存
  7109. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7110. var sum_count int64
  7111. for _, item := range goodList {
  7112. sum_count += item.StockCount
  7113. }
  7114. // 在出库记录表里记录退库详情
  7115. warehouseOutInfo := &models.WarehouseOutInfo{
  7116. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7117. WarehouseOutId: warehouseOut.ID,
  7118. Status: 1,
  7119. Ctime: time.Now().Unix(),
  7120. OrgId: adminInfo.Org.Id,
  7121. Type: 1,
  7122. IsSys: 1,
  7123. SysRecordTime: record_time,
  7124. GoodTypeId: item.GoodTypeId,
  7125. GoodId: item.GoodId,
  7126. PatientId: patient_id,
  7127. ConsumableType: 2,
  7128. StorehouseId: houseConfig.StorehouseOutInfo,
  7129. IsCheck: 1,
  7130. OverCount: sum_count,
  7131. }
  7132. warehouseOutInfo.Count = item.Count
  7133. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7134. warehouseOutInfo.Price = stockInInfo.Price
  7135. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7136. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7137. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7138. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7139. warehouseOutInfo.Number = warehouseOutInfos.Number
  7140. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7141. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7142. //查找当天是否存在出库记录
  7143. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7144. if errcod == gorm.ErrRecordNotFound {
  7145. service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  7146. //插入详情明细表
  7147. stockFlow := models.VmStockFlow{
  7148. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7149. WarehouseOutId: warehouseOut.ID,
  7150. GoodId: item.GoodId,
  7151. Number: warehouseOutInfos.Number,
  7152. ProductDate: stockInInfo.ProductDate,
  7153. ExpireDate: stockInInfo.ExpiryDate,
  7154. Count: item.Count,
  7155. Price: stockInInfo.Price,
  7156. Status: 1,
  7157. Ctime: record_time,
  7158. UserOrgId: adminInfo.Org.Id,
  7159. Manufacturer: stockInInfo.Manufacturer,
  7160. Dealer: stockInInfo.Dealer,
  7161. LicenseNumber: stockInInfo.LicenseNumber,
  7162. IsEdit: 2,
  7163. Creator: creater,
  7164. SystemTime: record_time,
  7165. ConsumableType: 3,
  7166. WarehousingDetailId: 0,
  7167. IsSys: 1,
  7168. UpdateCreator: creater,
  7169. PatientId: patient_id,
  7170. StorehouseId: houseConfig.StorehouseOutInfo,
  7171. }
  7172. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7173. if errflow == gorm.ErrRecordNotFound {
  7174. //创建流水表
  7175. err := service.CreateStockFlowOne(stockFlow)
  7176. fmt.Println("err", err)
  7177. } else if errflow == nil {
  7178. //插入详情明细表
  7179. stockFlow := models.VmStockFlow{
  7180. ID: exsit.ID,
  7181. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7182. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7183. WarehouseOutId: warehouseOut.ID,
  7184. GoodId: item.GoodId,
  7185. Number: warehouseOutInfos.Number,
  7186. ProductDate: stockInInfo.ProductDate,
  7187. ExpireDate: stockInInfo.ExpiryDate,
  7188. Count: exsit.Count - delete_count,
  7189. Price: stockInInfo.Price,
  7190. Status: 1,
  7191. Ctime: record_time,
  7192. UserOrgId: adminInfo.Org.Id,
  7193. Manufacturer: stockInInfo.Manufacturer,
  7194. Dealer: stockInInfo.Dealer,
  7195. LicenseNumber: stockInInfo.LicenseNumber,
  7196. IsEdit: 2,
  7197. Creator: creater,
  7198. SystemTime: record_time,
  7199. ConsumableType: 3,
  7200. WarehousingDetailId: 0,
  7201. IsSys: 1,
  7202. UpdateCreator: creater,
  7203. PatientId: patient_id,
  7204. StorehouseId: houseConfig.StorehouseOutInfo,
  7205. }
  7206. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7207. }
  7208. } else if errcod == nil {
  7209. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7210. //查询剩余库存
  7211. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7212. var sum_count int64
  7213. for _, item := range goodList {
  7214. sum_count += item.StockCount
  7215. }
  7216. //创建退库单,生成退库数据
  7217. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7218. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7219. operation_time := time.Now().Unix()
  7220. creater := adminInfo.AdminUser.Id
  7221. //创建退库单
  7222. timeStr := time.Now().Format("2006-01-02")
  7223. timeArr := strings.Split(timeStr, "-")
  7224. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7225. total = total + 1
  7226. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7227. cancelStock := models.CancelStock{
  7228. OrderNumber: orderNumber,
  7229. OperaTime: operation_time,
  7230. OrgId: adminInfo.Org.Id,
  7231. Creater: creater,
  7232. Ctime: time.Now().Unix(),
  7233. Status: 1,
  7234. ReturnTime: record_time,
  7235. Type: 1,
  7236. StorehouseId: houseConfig.StorehouseOutInfo,
  7237. IsCheck: 1,
  7238. }
  7239. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7240. if msgerrkonde == gorm.ErrRecordNotFound {
  7241. service.AddSigleCancelStock(&cancelStock)
  7242. }
  7243. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7244. //查询是否有出库
  7245. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7246. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7247. deaerler, _ := service.GetDealerById(info.Dealer)
  7248. if info.ID > 0 {
  7249. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7250. cancelStockInfo := models.CancelStockInfo{
  7251. GoodId: item.GoodId,
  7252. CancelStockId: cancel.ID,
  7253. GoodTypeId: good.GoodTypeId,
  7254. Count: delete_count,
  7255. Price: info.Price,
  7256. Total: 0,
  7257. ProductDate: info.ProductDate,
  7258. ExpiryDate: info.ExpiryDate,
  7259. Ctime: time.Now().Unix(),
  7260. Status: 1,
  7261. OrgId: adminInfo.Org.Id,
  7262. OrderNumber: cancel.OrderNumber,
  7263. Type: 0,
  7264. Dealer: deaerler.DealerName,
  7265. Manufacturer: manufacturer.ManufacturerName,
  7266. Number: info.Number,
  7267. RegisterAccount: "",
  7268. Remark: "",
  7269. WarehouseInfoId: info.WarehouseInfotId,
  7270. PatientId: info.PatientId,
  7271. RecordDate: info.SysRecordTime,
  7272. StorehouseId: houseConfig.StorehouseOutInfo,
  7273. IsCheck: 1,
  7274. }
  7275. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7276. //退库数量增加
  7277. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7278. //查询剩余库存
  7279. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7280. var over_count int64
  7281. for _, it := range goodList {
  7282. over_count += it.StockCount
  7283. }
  7284. flow := models.VmStockFlow{
  7285. WarehousingId: info.WarehouseInfotId,
  7286. GoodId: item.GoodId,
  7287. Number: info.Number,
  7288. LicenseNumber: info.LicenseNumber,
  7289. Count: delete_count,
  7290. UserOrgId: adminInfo.Org.Id,
  7291. PatientId: patient_id,
  7292. SystemTime: info.SysRecordTime,
  7293. ConsumableType: 7,
  7294. IsSys: 0,
  7295. WarehousingOrder: "",
  7296. WarehouseOutId: info.WarehouseOutId,
  7297. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7298. IsEdit: 0,
  7299. CancelStockId: cancel.ID,
  7300. CancelOrderNumber: cancel.OrderNumber,
  7301. Manufacturer: manufacturer.ID,
  7302. Dealer: 0,
  7303. Creator: adminInfo.AdminUser.Id,
  7304. UpdateCreator: 0,
  7305. Status: 1,
  7306. Ctime: record_time,
  7307. Mtime: 0,
  7308. Price: info.Price,
  7309. WarehousingDetailId: info.WarehouseInfotId,
  7310. WarehouseOutDetailId: info.ID,
  7311. CancelOutDetailId: cancelInfo.ID,
  7312. ProductDate: info.ProductDate,
  7313. ExpireDate: info.ExpiryDate,
  7314. StorehouseId: houseConfig.StorehouseOutInfo,
  7315. OverCount: over_count,
  7316. }
  7317. service.CreateStockFlowOne(flow)
  7318. }
  7319. }
  7320. //更改自动出库的表格
  7321. details := models.BloodAutomaticReduceDetail{
  7322. WarehouseOutId: warehouseOutInfo.ID,
  7323. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7324. PatientId: patient_id,
  7325. Ctime: time.Now().Unix(),
  7326. Mtime: time.Now().Unix(),
  7327. Status: 1,
  7328. RecordTime: record_time,
  7329. OrgId: adminInfo.Org.Id,
  7330. GoodId: item.GoodId,
  7331. GoodTypeId: item.GoodTypeId,
  7332. Count: item.Count,
  7333. StorehouseId: houseConfig.StorehouseOutInfo,
  7334. }
  7335. //查询当天耗材是否已经存在数据
  7336. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7337. if errcode == gorm.ErrRecordNotFound {
  7338. service.CreateAutoReduceRecord(&details)
  7339. } else if errcode == nil {
  7340. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7341. service.CreateAutoReduceRecord(&details)
  7342. }
  7343. //查询默认仓库
  7344. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7345. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7346. var total_count int64
  7347. for _, it := range stockList {
  7348. total_count += it.StockCount
  7349. }
  7350. //基础库插入数据
  7351. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7352. }
  7353. }
  7354. if len(outbefor) > 0 {
  7355. //出库
  7356. for _, item := range outbefor {
  7357. var last_total int64
  7358. //1.查看该患者该耗材型号最后一次出库数量
  7359. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7360. //计算当前出库和最后一次出库数据相差数据
  7361. last_total = item.Count - goodInfoOne.Count
  7362. //查询该耗材的总库存
  7363. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7364. // 如果库存差大于剩余库存则提示库存不足
  7365. if last_total > wareinfo.StockCount {
  7366. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7367. c.ServeSuccessJSON(map[string]interface{}{
  7368. "message": "1",
  7369. "good_name": goodObj.GoodName,
  7370. "specification_name": goodObj.SpecificationName,
  7371. })
  7372. return
  7373. } else {
  7374. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7375. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7376. if err == gorm.ErrRecordNotFound {
  7377. //没有记录,则创建出库单
  7378. timeStr := time.Now().Format("2006-01-02")
  7379. timeArr := strings.Split(timeStr, "-")
  7380. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7381. total = total + 1
  7382. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7383. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7384. number = number + total
  7385. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7386. warehouseOut := models.WarehouseOut{
  7387. WarehouseOutOrderNumber: warehousing_out_order,
  7388. OperationTime: time.Now().Unix(),
  7389. OrgId: adminInfo.Org.Id,
  7390. Creater: adminInfo.AdminUser.Id,
  7391. Ctime: time.Now().Unix(),
  7392. Status: 1,
  7393. WarehouseOutTime: record_time,
  7394. Dealer: 0,
  7395. Manufacturer: 0,
  7396. Type: 1,
  7397. IsSys: 1,
  7398. StorehouseId: houseConfig.StorehouseOutInfo,
  7399. IsCheck: 1,
  7400. }
  7401. service.AddSigleWarehouseOutOne(&warehouseOut)
  7402. }
  7403. //出库
  7404. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7405. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7406. //1.查看该患者该耗材型号最后一次出库数量
  7407. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7408. prepare := models.DialysisBeforePrepare{
  7409. UserOrgId: adminInfo.Org.Id,
  7410. PatientId: patient_id,
  7411. RecordDate: record_time,
  7412. GoodId: item.GoodId,
  7413. GoodTypeId: item.GoodTypeId,
  7414. Count: item.Count - goodInfoTwo.Count,
  7415. Ctime: time.Now().Unix(),
  7416. Mtime: 0,
  7417. Creater: adminInfo.AdminUser.Id,
  7418. Modifier: adminInfo.AdminUser.Id,
  7419. Status: 1,
  7420. CommdityCode: "",
  7421. NewCount: 0,
  7422. ProjectId: 0,
  7423. StorehouseId: houseConfig.StorehouseOutInfo,
  7424. }
  7425. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7426. //增加出库数量
  7427. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7428. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7429. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7430. var total_count int64
  7431. for _, it := range stockList {
  7432. total_count += it.StockCount
  7433. }
  7434. //基础库插入数据
  7435. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7436. //剩余库存
  7437. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7438. var flush_count int64
  7439. for _, it := range goodList {
  7440. flush_count += it.StockCount
  7441. }
  7442. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7443. }
  7444. }
  7445. }
  7446. //查询今日出库数据
  7447. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7448. for _, it := range list {
  7449. prepare := models.DialysisBeforePrepare{
  7450. UserOrgId: it.OrgId,
  7451. PatientId: patient_id,
  7452. RecordDate: it.RecordTime,
  7453. GoodId: it.GoodId,
  7454. GoodTypeId: it.GoodTypeId,
  7455. Count: it.Count,
  7456. Ctime: time.Now().Unix(),
  7457. Creater: adminInfo.AdminUser.Id,
  7458. Status: 1,
  7459. StorehouseId: houseConfig.StorehouseOutInfo,
  7460. ProjectId: it.ProjectId,
  7461. }
  7462. //删除准备表数据
  7463. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7464. service.CreateDialysisBeforePrepareOne(&prepare)
  7465. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7466. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7467. var total_count int64
  7468. for _, it := range stockList {
  7469. total_count += it.StockCount
  7470. }
  7471. //基础库插入数据
  7472. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7473. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7474. var flush_count int64
  7475. for _, it := range goodList {
  7476. flush_count += it.StockCount
  7477. }
  7478. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7479. }
  7480. }
  7481. }
  7482. //更新自动出库的地方
  7483. var errs error
  7484. if errs == nil {
  7485. c.ServeSuccessJSON(map[string]interface{}{
  7486. "msg": "修改成功",
  7487. "message": "2",
  7488. "good_name": "",
  7489. "specification_name": "",
  7490. })
  7491. return
  7492. } else {
  7493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7494. return
  7495. }
  7496. }
  7497. }
  7498. func (c *DialysisAPIController) GetDialysisGoods() {
  7499. schedualDate := c.GetString("schedule_date")
  7500. schedule_type, _ := c.GetInt64("schedule_type")
  7501. partition_id, _ := c.GetInt64("partition_id")
  7502. page, _ := c.GetInt("page")
  7503. patient_id, _ := c.GetInt64("patient_id")
  7504. schedualEndDate := int64(0)
  7505. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7506. if parseDateErr != nil && len(schedualDate) != 0 {
  7507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7508. return
  7509. }
  7510. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7511. if parseDateErr != nil && len(schedualDate) != 0 {
  7512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7513. return
  7514. }
  7515. schedualEndDate = endDate.Unix()
  7516. adminUser := c.GetMobileAdminUserInfo()
  7517. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7518. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7519. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7520. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7521. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7522. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7523. //获取当天该病人的透析处方
  7524. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7525. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7526. if err == gorm.ErrRecordNotFound {
  7527. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7528. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7529. if patient_id != 0 {
  7530. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7531. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7532. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7533. //获取患者总的出库数据
  7534. item.LastAutomaticReduceDetail = goodUser
  7535. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7536. item.Project = project
  7537. for _, it := range item.AutomaticReduceDetail {
  7538. var total int64
  7539. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7540. for _, its := range auto {
  7541. total += its.Count
  7542. }
  7543. it.Count = total
  7544. }
  7545. }
  7546. }
  7547. c.ServeSuccessJSON(map[string]interface{}{
  7548. "dialysis_goods": dialysisGoods,
  7549. "good_type": goodTypes,
  7550. "total": total,
  7551. "prescribe": prescribe,
  7552. "good_info": good_info,
  7553. "warehouseOutList": warehouseOutList,
  7554. "config": config,
  7555. "outConfig": outConfig,
  7556. "settleConfig": settleConfig,
  7557. })
  7558. return
  7559. } else if err == nil {
  7560. //获取当天排班的每个患者的库存使用情况
  7561. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7562. //获取患者总的出库数据
  7563. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7564. if patient_id != 0 {
  7565. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7566. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7567. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7568. item.Project = project
  7569. item.LastAutomaticReduceDetail = goodUser
  7570. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7571. for _, it := range item.AutomaticReduceDetail {
  7572. var total int64
  7573. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7574. for _, its := range auto {
  7575. total += its.Count
  7576. }
  7577. it.Count = total
  7578. }
  7579. }
  7580. }
  7581. if err == nil {
  7582. c.ServeSuccessJSON(map[string]interface{}{
  7583. "dialysis_goods": dialysisGoods,
  7584. "good_type": goodTypes,
  7585. "total": total,
  7586. "prescribe": prescribe,
  7587. "good_info": good_info,
  7588. "project": project,
  7589. "warehouseOutList": warehouseOutList,
  7590. "config": config,
  7591. "outConfig": outConfig,
  7592. "settleConfig": settleConfig,
  7593. })
  7594. return
  7595. } else {
  7596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7597. return
  7598. }
  7599. } else if err != nil {
  7600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7601. return
  7602. }
  7603. }
  7604. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7605. start_time := c.GetString("start_time")
  7606. end_time := c.GetString("end_time")
  7607. timeLayout := "2006-01-02"
  7608. loc, _ := time.LoadLocation("Local")
  7609. var theStartTime int64
  7610. if len(start_time) > 0 {
  7611. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7612. if err != nil {
  7613. utils.ErrorLog(err.Error())
  7614. }
  7615. theStartTime = theTime.Unix()
  7616. }
  7617. var theEndtTime int64
  7618. if len(end_time) > 0 {
  7619. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7620. if err != nil {
  7621. utils.ErrorLog(err.Error())
  7622. }
  7623. theEndtTime = theTime.Unix()
  7624. }
  7625. adminUser := c.GetMobileAdminUserInfo()
  7626. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7627. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7628. if err == nil {
  7629. c.ServeSuccessJSON(map[string]interface{}{
  7630. "stock_out": outInfo,
  7631. "stockCount": stockCount,
  7632. })
  7633. return
  7634. } else {
  7635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7636. return
  7637. }
  7638. }
  7639. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7640. patient_id, _ := c.GetInt64("patient_id", 0)
  7641. record_time := c.GetString("record_time")
  7642. adminUser := c.GetMobileAdminUserInfo()
  7643. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7644. if parseDateErr != nil && len(record_time) != 0 {
  7645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7646. return
  7647. }
  7648. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7649. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7650. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7651. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7652. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7653. //获取今日患者的透析处方参数
  7654. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7655. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7656. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7657. c.ServeSuccessJSON(map[string]interface{}{
  7658. "good_type": goodTypes,
  7659. "good_user": goodUser,
  7660. "good_info": good_info,
  7661. "last_good_user": lastGoodUserDetial,
  7662. "project": project,
  7663. "prescription": prescribe,
  7664. "outInfo": outInfo,
  7665. "configs": configs,
  7666. })
  7667. return
  7668. }
  7669. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7670. patient_id, _ := c.GetInt64("patient_id", 0)
  7671. record_date := c.GetString("record_time")
  7672. timeLayout := "2006-01-02"
  7673. loc, _ := time.LoadLocation("Local")
  7674. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7675. record_time := theRecordTime.Unix()
  7676. adminInfo := c.GetMobileAdminUserInfo()
  7677. dataBody := make(map[string]interface{}, 0)
  7678. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7679. if err != nil {
  7680. utils.ErrorLog(err.Error())
  7681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7682. return
  7683. }
  7684. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7685. var beforePrepares []*models.DialysisBeforePrepareGoods
  7686. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7687. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7688. goods, _ := dataBody["goods"].([]interface{})
  7689. if len(goods) > 0 {
  7690. for _, item := range goods {
  7691. items := item.(map[string]interface{})
  7692. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7693. utils.ErrorLog("good_id")
  7694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7695. return
  7696. }
  7697. good_id := int64(items["good_id"].(float64))
  7698. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7699. utils.ErrorLog("good_type_id")
  7700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7701. return
  7702. }
  7703. good_type_id := int64(items["good_type_id"].(float64))
  7704. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7705. utils.ErrorLog("count")
  7706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7707. return
  7708. }
  7709. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7710. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7711. utils.ErrorLog("project_id")
  7712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7713. return
  7714. }
  7715. project_id := int64(items["project_id"].(float64))
  7716. new_count := int64(items["new_count"].(float64))
  7717. old_count := int64(items["old_count"].(float64))
  7718. prepare := &models.DialysisBeforePrepareGoods{
  7719. GoodId: good_id,
  7720. GoodTypeId: good_type_id,
  7721. Count: count,
  7722. ProjectId: project_id,
  7723. StorehouseId: houseConfig.StorehouseOutInfo,
  7724. NewCount: new_count,
  7725. OldCount: old_count,
  7726. }
  7727. beforePrepares = append(beforePrepares, prepare)
  7728. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7729. GoodId: good_id,
  7730. GoodTypeId: good_type_id,
  7731. Count: count,
  7732. ProjectId: project_id,
  7733. StorehouseId: houseConfig.StorehouseOutInfo,
  7734. NewCount: new_count,
  7735. OldCount: old_count,
  7736. }
  7737. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7738. }
  7739. }
  7740. }
  7741. //查询是否有库存
  7742. for _, item := range beforePrepares {
  7743. if item.NewCount > 0 {
  7744. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7745. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7746. if item.Count > warehouse.Count {
  7747. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7748. c.ServeSuccessJSON(map[string]interface{}{
  7749. "message": "1",
  7750. "good_name": goodObj.GoodName,
  7751. "specification_name": goodObj.SpecificationName,
  7752. })
  7753. return
  7754. }
  7755. }
  7756. }
  7757. // 查询信息规挡的设置天数
  7758. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7759. if infor.ID > 0 && infor.WeekDay > 0 {
  7760. var cha_time int64
  7761. timeNowStr := time.Now().Format("2006-01-02")
  7762. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7763. //今日的日期减去设置的日期
  7764. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7765. if cha_time >= record_time {
  7766. //查询审核是否允许
  7767. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7768. //申请状态不允许的情况 拒绝修改
  7769. if infor.ApplicationStatus != 1 {
  7770. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7771. return
  7772. }
  7773. }
  7774. }
  7775. //出库逻辑
  7776. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7777. if err != nil {
  7778. utils.ErrorLog(err.Error())
  7779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7780. return
  7781. }
  7782. finish := models.XtDialysisFinish{
  7783. IsFinish: 1,
  7784. UserOrgId: adminInfo.Org.Id,
  7785. Status: 1,
  7786. Ctime: time.Now().Unix(),
  7787. Mtime: 0,
  7788. Module: 11,
  7789. RecordDate: record_time,
  7790. Sourse: 1,
  7791. PatientId: patient_id,
  7792. }
  7793. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7794. if dialysisFinish.ID == 0 {
  7795. service.CreateDialysisFinish(finish)
  7796. }
  7797. //查询当天出库的数据
  7798. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7799. for _, item := range list {
  7800. prepare := models.DialysisBeforePrepare{
  7801. UserOrgId: item.OrgId,
  7802. PatientId: item.PatientId,
  7803. RecordDate: item.RecordTime,
  7804. GoodId: item.GoodId,
  7805. GoodTypeId: item.GoodTypeId,
  7806. Count: item.Count,
  7807. Creater: adminInfo.AdminUser.Id,
  7808. Status: 1,
  7809. Ctime: time.Now().Unix(),
  7810. ProjectId: item.ProjectId,
  7811. StorehouseId: houseConfig.StorehouseOutInfo,
  7812. }
  7813. //清空准备表的数据
  7814. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7815. //插入准备表数据
  7816. service.CreateDialysisBeforePrepareOne(&prepare)
  7817. //查询默认仓库
  7818. //查询默认仓库
  7819. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7820. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7821. var total_count int64
  7822. for _, it := range stockList {
  7823. total_count += it.StockCount
  7824. }
  7825. //基础库插入数据
  7826. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7827. ////更新剩余库存
  7828. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7829. var flush_count int64
  7830. for _, it := range goodList {
  7831. flush_count += it.StockCount
  7832. }
  7833. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7834. if errs != nil {
  7835. goodErrcode := models.XtGoodErrcode{
  7836. UserOrgId: item.OrgId,
  7837. Errcode: "手动出库更新剩余出库失败",
  7838. GoodId: item.GoodId,
  7839. Status: 1,
  7840. Ctime: time.Now().Unix(),
  7841. Mtime: 0,
  7842. Count: 0,
  7843. StockCount: 0,
  7844. Creater: adminInfo.AdminUser.Id,
  7845. BatchNumberId: 0,
  7846. WarehouseOutId: 0,
  7847. }
  7848. service.CreateGoodErrcode(goodErrcode)
  7849. }
  7850. }
  7851. //更新自动出库的地方
  7852. var errs error
  7853. if errs == nil {
  7854. c.ServeSuccessJSON(map[string]interface{}{
  7855. "msg": "修改成功",
  7856. "message": "2",
  7857. "good_name": "",
  7858. "specification_name": "",
  7859. })
  7860. return
  7861. } else {
  7862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7863. return
  7864. }
  7865. }
  7866. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7867. newArr = make([]*models.DialysisBeforePrepare, 0)
  7868. for i := 0; i < len(arr); i++ {
  7869. repeat := false
  7870. for j := i + 1; j < len(arr); j++ {
  7871. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7872. repeat = true
  7873. break
  7874. }
  7875. }
  7876. if !repeat {
  7877. newArr = append(newArr, arr[i])
  7878. }
  7879. }
  7880. return
  7881. }
  7882. func (c *DialysisAPIController) GetAllDrug() {
  7883. patient_id, _ := c.GetInt64("patient_id", 0)
  7884. adminInfo := c.GetMobileAdminUserInfo()
  7885. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7886. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7887. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7888. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7889. c.ServeSuccessJSON(map[string]interface{}{
  7890. "base_drug_config": drugStockConfig,
  7891. "private_drug_config": privateDrugConfig,
  7892. "base_drug_list": drugList,
  7893. "private_drug_list": privateDrugList,
  7894. })
  7895. }
  7896. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7897. newArr = make([]*models.DialysisBeforePrepare, 0)
  7898. for i := 0; i < len(arr); i++ {
  7899. repeat := false
  7900. for j := i + 1; j < len(arr); j++ {
  7901. if arr[i].GoodId == arr[j].GoodId {
  7902. repeat = true
  7903. break
  7904. }
  7905. }
  7906. if !repeat {
  7907. newArr = append(newArr, arr[i])
  7908. }
  7909. }
  7910. return
  7911. }
  7912. func (c *DialysisAPIController) GetDepartment() {
  7913. adminInfo := c.GetMobileAdminUserInfo()
  7914. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7915. if err == nil {
  7916. c.ServeSuccessJSON(map[string]interface{}{
  7917. "departments": departments,
  7918. })
  7919. } else {
  7920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7921. return
  7922. }
  7923. }
  7924. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7925. types, _ := c.GetInt("type", 0)
  7926. start_time := c.GetString("start_time")
  7927. end_time := c.GetString("end_time")
  7928. orgId := c.GetMobileAdminUserInfo().Org.Id
  7929. timeLayout := "2006-01-02"
  7930. loc, _ := time.LoadLocation("Local")
  7931. var startTime int64
  7932. if len(start_time) > 0 {
  7933. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7934. if err != nil {
  7935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7936. return
  7937. }
  7938. startTime = theTime.Unix()
  7939. }
  7940. var endTime int64
  7941. if len(end_time) > 0 {
  7942. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7943. if err != nil {
  7944. utils.ErrorLog(err.Error())
  7945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7946. return
  7947. }
  7948. endTime = theTime.Unix()
  7949. }
  7950. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7951. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7952. if err != nil {
  7953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7954. } else {
  7955. c.ServeSuccessJSON(map[string]interface{}{
  7956. "list": list,
  7957. "type": types,
  7958. "stockTotal": stockTotal,
  7959. })
  7960. }
  7961. }
  7962. func (c *DialysisAPIController) GetPrescriptionList() {
  7963. start_time := c.GetString("start_time")
  7964. end_time := c.GetString("end_time")
  7965. schedule_type, _ := c.GetInt64("schedule_type")
  7966. partion_id, _ := c.GetInt64("partion_id")
  7967. orgId := c.GetMobileAdminUserInfo().Org.Id
  7968. timeLayout := "2006-01-02"
  7969. loc, _ := time.LoadLocation("Local")
  7970. var startTime int64
  7971. if len(start_time) > 0 {
  7972. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7973. if err != nil {
  7974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7975. return
  7976. }
  7977. startTime = theTime.Unix()
  7978. }
  7979. var endTime int64
  7980. if len(end_time) > 0 {
  7981. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7982. if err != nil {
  7983. utils.ErrorLog(err.Error())
  7984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7985. return
  7986. }
  7987. endTime = theTime.Unix()
  7988. }
  7989. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7990. fmt.Println("schedulelist22222222", schedulelist)
  7991. c.ServeSuccessJSON(map[string]interface{}{
  7992. "list": schedulelist,
  7993. })
  7994. return
  7995. }
  7996. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7997. ids := c.GetString("ids")
  7998. //patient_id, _ := c.GetInt64("patient_id")
  7999. //monitoring_date, _ := c.GetInt64("monitoring_date")
  8000. idArray := strings.Split(ids, ",")
  8001. err := service.BatchDeleteMonitor(idArray)
  8002. fmt.Print("err", err)
  8003. //orgid := c.GetMobileAdminUserInfo().Org.Id
  8004. //redis := service.RedisClient()
  8005. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  8006. //redis.Set(key, "", time.Second)
  8007. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  8008. //redis.Set(keyOne, "", time.Second)
  8009. //fmt.Println("keyo呢32332322332332232332",keyOne)
  8010. //redis.Close()
  8011. c.ServeSuccessJSON(map[string]interface{}{
  8012. "msg": "批量删除成功",
  8013. })
  8014. return
  8015. }
  8016. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  8017. id, _ := c.GetInt64("id")
  8018. timeLayout := "2006-01-02"
  8019. loc, _ := time.LoadLocation("Local")
  8020. //start_time := time.Now().Format("2006-01-02")
  8021. start_time := c.GetString("start_time")
  8022. end_time := c.GetString("end_time")
  8023. var startdateunix int64
  8024. if len(start_time) > 0 {
  8025. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8026. if err != nil {
  8027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8028. return
  8029. }
  8030. startdateunix = theTime.Unix()
  8031. }
  8032. var enddateunix int64
  8033. if len(end_time) > 0 {
  8034. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8035. if err != nil {
  8036. utils.ErrorLog(err.Error())
  8037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8038. return
  8039. }
  8040. enddateunix = theTime.Unix()
  8041. }
  8042. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8043. //nowTime := time.Now()
  8044. //endTime := nowTime.AddDate(-30, 0, 0)
  8045. //endTimes := endTime.Format("2006-01-02")
  8046. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8047. org_id := c.GetMobileAdminUserInfo().Org.Id
  8048. //if org_id == 10579 {
  8049. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8050. // c.ServeSuccessJSON(map[string]interface{}{
  8051. // "list": list,
  8052. // })
  8053. // return
  8054. //} else {
  8055. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8056. // c.ServeSuccessJSON(map[string]interface{}{
  8057. // "list": list,
  8058. // })
  8059. // return
  8060. //}
  8061. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  8062. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8063. c.ServeSuccessJSON(map[string]interface{}{
  8064. "list": list,
  8065. })
  8066. return
  8067. } else {
  8068. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8069. c.ServeSuccessJSON(map[string]interface{}{
  8070. "list": list,
  8071. })
  8072. }
  8073. return
  8074. }
  8075. func (c *DialysisAPIController) BathDeleteAdviceList() {
  8076. dataBody := make(map[string]interface{}, 0)
  8077. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8078. ids := c.GetString("ids")
  8079. idArray := strings.Split(ids, ",")
  8080. origin, _ := c.GetInt64("origin")
  8081. if origin == 1 {
  8082. err = service.BatchDeleteAdvice(idArray)
  8083. fmt.Print("err", err)
  8084. c.ServeSuccessJSON(map[string]interface{}{
  8085. "msg": "批量删除成功",
  8086. })
  8087. return
  8088. }
  8089. if origin == 2 {
  8090. service.BatchDeleteHisAdvice(idArray)
  8091. }
  8092. }
  8093. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  8094. good_id, _ := c.GetInt64("good_id")
  8095. count, _ := c.GetInt64("count")
  8096. record_time, _ := c.GetInt64("record_time")
  8097. patient_id, _ := c.GetInt64("patient_id")
  8098. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  8099. c.ServeSuccessJSON(map[string]interface{}{
  8100. "detail": detail,
  8101. })
  8102. return
  8103. }
  8104. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  8105. good_id, _ := c.GetInt64("good_id")
  8106. record_time, _ := c.GetInt64("record_time")
  8107. patient_id, _ := c.GetInt64("patient_id")
  8108. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8109. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8110. fmt.Print("err", err)
  8111. c.ServeSuccessJSON(map[string]interface{}{
  8112. "msg": "批量删除成功",
  8113. })
  8114. return
  8115. }
  8116. func (c *DialysisAPIController) BatchAdviceCheck() {
  8117. ids := c.GetString("ids")
  8118. idArray := strings.Split(ids, ",")
  8119. creator, _ := c.GetInt64("creator")
  8120. origin, _ := c.GetInt64("origin")
  8121. if origin == 1 {
  8122. err := service.BatchAdviceCheck(idArray, creator)
  8123. fmt.Println(err)
  8124. list, _ := service.GetAdviceExecutionById(idArray)
  8125. c.ServeSuccessJSON(map[string]interface{}{
  8126. "list": list,
  8127. })
  8128. return
  8129. }
  8130. if origin == 2 {
  8131. service.BatchHisAdviceCheck(idArray, creator)
  8132. list, _ := service.GetHisAdviceExecutionById(idArray)
  8133. c.ServeSuccessJSON(map[string]interface{}{
  8134. "list": list,
  8135. })
  8136. return
  8137. }
  8138. }
  8139. func (c *DialysisAPIController) BatchAdviceExecution() {
  8140. ids := c.GetString("ids")
  8141. idArray := strings.Split(ids, ",")
  8142. executionTime := c.GetString("execution_time")
  8143. creator, _ := c.GetInt64("creator")
  8144. timeLayout := "2006-01-02 15:04:05"
  8145. loc, _ := time.LoadLocation("Local")
  8146. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8147. orgin, _ := c.GetInt64("origin")
  8148. if orgin == 1 {
  8149. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8150. list, _ := service.GetAdviceExecutionById(idArray)
  8151. fmt.Println(err)
  8152. c.ServeSuccessJSON(map[string]interface{}{
  8153. "list": list,
  8154. })
  8155. return
  8156. }
  8157. if orgin == 2 {
  8158. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8159. list, _ := service.GetHisAdviceExecutionById(idArray)
  8160. fmt.Println(err)
  8161. c.ServeSuccessJSON(map[string]interface{}{
  8162. "list": list,
  8163. })
  8164. return
  8165. }
  8166. }
  8167. func (c *DialysisAPIController) UpdateStockGoods() {
  8168. good_id, _ := c.GetInt64("good_id")
  8169. record_time, _ := c.GetInt64("record_time")
  8170. patient_id, _ := c.GetInt64("patient_id")
  8171. count, _ := c.GetInt64("count")
  8172. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8173. fmt.Print("err", err)
  8174. c.ServeSuccessJSON(map[string]interface{}{
  8175. "msg": "更新成功",
  8176. })
  8177. return
  8178. }
  8179. // 当前数据比上一次出库数据少
  8180. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8181. //查询该患者当天已经出库的耗材信息
  8182. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8183. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8184. for i := len(goods_yc) - 1; i >= 0; i-- {
  8185. goods_yc_temp := goods_yc[i]
  8186. for j := len(goods) - 1; j >= 0; j-- {
  8187. goods_temp := goods[j]
  8188. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8189. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8190. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8191. if goods_yc_temp.Count == goods_temp.Count {
  8192. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8193. goods = append(goods[:j], goods[j+1:]...)
  8194. break
  8195. }
  8196. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8197. if goods_yc_temp.Count > goods_temp.Count {
  8198. temp_count := goods_yc_temp.Count - goods_temp.Count
  8199. goods_yc[i].Count = temp_count
  8200. goods = append(goods[:j], goods[j+1:]...)
  8201. break
  8202. }
  8203. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8204. if goods_yc_temp.Count < goods_temp.Count {
  8205. temp_count := goods_temp.Count - goods_yc_temp.Count
  8206. goods[j].Count = temp_count
  8207. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8208. break
  8209. }
  8210. }
  8211. }
  8212. }
  8213. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8214. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8215. //退库
  8216. if len(goods_yc) > 0 {
  8217. for _, good_yc := range goods_yc {
  8218. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8219. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8220. }
  8221. }
  8222. return nil
  8223. }
  8224. // 耗材出库删除
  8225. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8226. // 先根据相关信息查询当天该耗材的出库信息
  8227. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8228. if err != nil {
  8229. return err
  8230. }
  8231. var delete_count int64 = 0
  8232. delete_count = warehouseOutInfos.Count - count
  8233. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8234. // 在出库记录表里记录退库详情
  8235. warehouseOutInfo := &models.WarehouseOutInfo{
  8236. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8237. WarehouseOutId: warehouseOut.ID,
  8238. Status: 1,
  8239. Ctime: time.Now().Unix(),
  8240. OrgId: orgID,
  8241. Type: 1,
  8242. IsSys: 1,
  8243. SysRecordTime: record_time,
  8244. GoodTypeId: good_yc.GoodTypeId,
  8245. GoodId: good_yc.GoodId,
  8246. PatientId: good_yc.PatientId,
  8247. ConsumableType: 2,
  8248. StorehouseId: houseConfig.StorehouseOutInfo,
  8249. IsCheck: 1,
  8250. }
  8251. warehouseOutInfo.Count = count
  8252. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8253. warehouseOutInfo.Price = stockInInfo.Price
  8254. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8255. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8256. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8257. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8258. warehouseOutInfo.Number = warehouseOutInfos.Number
  8259. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8260. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8261. //查找当天是否存在出库记录
  8262. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8263. if errcod == gorm.ErrRecordNotFound {
  8264. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8265. //插入详情明细表
  8266. stockFlow := models.VmStockFlow{
  8267. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8268. WarehouseOutId: warehouseOut.ID,
  8269. GoodId: good_yc.GoodId,
  8270. Number: warehouseOutInfos.Number,
  8271. ProductDate: stockInInfo.ProductDate,
  8272. ExpireDate: stockInInfo.ExpiryDate,
  8273. Count: count,
  8274. Price: stockInInfo.Price,
  8275. Status: 1,
  8276. Ctime: time.Now().Unix(),
  8277. UserOrgId: good_yc.OrgId,
  8278. Manufacturer: stockInInfo.Manufacturer,
  8279. Dealer: stockInInfo.Dealer,
  8280. LicenseNumber: stockInInfo.LicenseNumber,
  8281. IsEdit: 2,
  8282. Creator: creater,
  8283. SystemTime: record_time,
  8284. ConsumableType: 3,
  8285. WarehousingDetailId: 0,
  8286. IsSys: 1,
  8287. UpdateCreator: creater,
  8288. PatientId: patient_id,
  8289. StorehouseId: houseConfig.StorehouseOutInfo,
  8290. }
  8291. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8292. if errflow == gorm.ErrRecordNotFound {
  8293. //创建流水表
  8294. err := service.CreateStockFlowOne(stockFlow)
  8295. fmt.Println("err", err)
  8296. } else if errflow == nil {
  8297. //插入详情明细表
  8298. stockFlow := models.VmStockFlow{
  8299. ID: exsit.ID,
  8300. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8301. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8302. WarehouseOutId: warehouseOut.ID,
  8303. GoodId: good_yc.GoodId,
  8304. Number: warehouseOutInfos.Number,
  8305. ProductDate: stockInInfo.ProductDate,
  8306. ExpireDate: stockInInfo.ExpiryDate,
  8307. Count: exsit.Count - delete_count,
  8308. Price: stockInInfo.Price,
  8309. Status: 1,
  8310. Ctime: time.Now().Unix(),
  8311. UserOrgId: good_yc.OrgId,
  8312. Manufacturer: stockInInfo.Manufacturer,
  8313. Dealer: stockInInfo.Dealer,
  8314. LicenseNumber: stockInInfo.LicenseNumber,
  8315. IsEdit: 2,
  8316. Creator: creater,
  8317. SystemTime: record_time,
  8318. ConsumableType: 3,
  8319. WarehousingDetailId: 0,
  8320. IsSys: 1,
  8321. UpdateCreator: creater,
  8322. PatientId: patient_id,
  8323. StorehouseId: houseConfig.StorehouseOutInfo,
  8324. }
  8325. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8326. }
  8327. if errOne != nil {
  8328. return errOne
  8329. }
  8330. } else if errcod == nil {
  8331. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8332. //插入详情明细表
  8333. stockFlow := models.VmStockFlow{
  8334. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8335. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8336. WarehouseOutId: warehouseOut.ID,
  8337. GoodId: good_yc.GoodId,
  8338. Number: warehouseOutInfos.Number,
  8339. ProductDate: stockInInfo.ProductDate,
  8340. ExpireDate: stockInInfo.ExpiryDate,
  8341. Count: count,
  8342. Price: stockInInfo.Price,
  8343. Status: 1,
  8344. Ctime: time.Now().Unix(),
  8345. UserOrgId: good_yc.OrgId,
  8346. Manufacturer: stockInInfo.Manufacturer,
  8347. Dealer: stockInInfo.Dealer,
  8348. LicenseNumber: stockInInfo.LicenseNumber,
  8349. IsEdit: 2,
  8350. Creator: creater,
  8351. SystemTime: record_time,
  8352. ConsumableType: 3,
  8353. WarehousingDetailId: 0,
  8354. IsSys: 1,
  8355. UpdateCreator: creater,
  8356. PatientId: patient_id,
  8357. ReturnCount: delete_count,
  8358. StorehouseId: houseConfig.StorehouseOutInfo,
  8359. }
  8360. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8361. if errflows == gorm.ErrRecordNotFound {
  8362. //创建流水表
  8363. service.CreateStockFlowOne(stockFlow)
  8364. } else if errflows == nil {
  8365. stockFlow := models.VmStockFlow{
  8366. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8367. ID: exsit.ID,
  8368. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8369. WarehouseOutId: warehouseOut.ID,
  8370. GoodId: good_yc.GoodId,
  8371. Number: warehouseOutInfos.Number,
  8372. ProductDate: stockInInfo.ProductDate,
  8373. ExpireDate: stockInInfo.ExpiryDate,
  8374. Count: exsit.Count - delete_count,
  8375. Price: stockInInfo.Price,
  8376. Status: 1,
  8377. Ctime: time.Now().Unix(),
  8378. UserOrgId: good_yc.OrgId,
  8379. Manufacturer: stockInInfo.Manufacturer,
  8380. Dealer: stockInInfo.Dealer,
  8381. LicenseNumber: stockInInfo.LicenseNumber,
  8382. IsEdit: 2,
  8383. Creator: creater,
  8384. SystemTime: record_time,
  8385. ConsumableType: 3,
  8386. WarehousingDetailId: 0,
  8387. IsSys: 1,
  8388. UpdateCreator: creater,
  8389. PatientId: patient_id,
  8390. ReturnCount: delete_count,
  8391. StorehouseId: houseConfig.StorehouseOutInfo,
  8392. }
  8393. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8394. }
  8395. }
  8396. //更改自动出库的表格
  8397. details := models.BloodAutomaticReduceDetail{
  8398. WarehouseOutId: warehouseOutInfo.ID,
  8399. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8400. PatientId: patient_id,
  8401. Ctime: time.Now().Unix(),
  8402. Mtime: time.Now().Unix(),
  8403. Status: 1,
  8404. RecordTime: record_time,
  8405. OrgId: orgID,
  8406. GoodId: good_yc.GoodId,
  8407. GoodTypeId: good_yc.GoodTypeId,
  8408. Count: count,
  8409. StorehouseId: houseConfig.StorehouseOutInfo,
  8410. }
  8411. //查询当天耗材是否已经存在数据
  8412. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8413. if errcode == gorm.ErrRecordNotFound {
  8414. errTwo := service.CreateAutoReduceRecord(&details)
  8415. if errTwo != nil {
  8416. return errTwo
  8417. }
  8418. } else if errcode == nil {
  8419. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8420. service.CreateAutoReduceRecord(&details)
  8421. }
  8422. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8423. //增加出库库存数量
  8424. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8425. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8426. fmt.Println("errOne", errOne)
  8427. // 删除出库完成后,要增加对应批次的库存数量
  8428. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8429. if errThree != nil {
  8430. return errThree
  8431. }
  8432. if good_yc.Count == 0 {
  8433. return nil
  8434. } else {
  8435. return errors.New("退库和出库数据不匹配")
  8436. }
  8437. }
  8438. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8439. //查询该患者当天已经出库的耗材信息
  8440. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8441. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8442. for i := len(goods_yc) - 1; i >= 0; i-- {
  8443. goods_yc_temp := goods_yc[i]
  8444. for j := len(goods) - 1; j >= 0; j-- {
  8445. goods_temp := goods[j]
  8446. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8447. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8448. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8449. if goods_yc_temp.Count == goods_temp.Count {
  8450. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8451. goods = append(goods[:j], goods[j+1:]...)
  8452. break
  8453. }
  8454. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8455. if goods_yc_temp.Count > goods_temp.Count {
  8456. temp_count := goods_yc_temp.Count - goods_temp.Count
  8457. goods_yc[i].Count = temp_count
  8458. goods = append(goods[:j], goods[j+1:]...)
  8459. break
  8460. }
  8461. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8462. if goods_yc_temp.Count < goods_temp.Count {
  8463. temp_count := goods_temp.Count - goods_yc_temp.Count
  8464. goods[j].Count = temp_count
  8465. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8466. break
  8467. }
  8468. }
  8469. }
  8470. }
  8471. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8472. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8473. fmt.Println("剩余需要出库的", len(goods))
  8474. if len(goods) > 0 {
  8475. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8476. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8477. if err == gorm.ErrRecordNotFound {
  8478. //没有记录,则创建出库单
  8479. timeStr := time.Now().Format("2006-01-02")
  8480. timeArr := strings.Split(timeStr, "-")
  8481. total, _ := service.FindAllWarehouseOut(orgID)
  8482. total = total + 1
  8483. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8484. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8485. number = number + total
  8486. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8487. warehouseOut := models.WarehouseOut{
  8488. WarehouseOutOrderNumber: warehousing_out_order,
  8489. OperationTime: time.Now().Unix(),
  8490. OrgId: orgID,
  8491. Creater: creater,
  8492. Ctime: time.Now().Unix(),
  8493. Status: 1,
  8494. WarehouseOutTime: record_time,
  8495. Dealer: 0,
  8496. Manufacturer: 0,
  8497. Type: 1,
  8498. IsSys: 1,
  8499. StorehouseId: houseConfig.StorehouseOutInfo,
  8500. IsCheck: 1,
  8501. }
  8502. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  8503. if err != nil {
  8504. utils.TraceLog("创建出库单失败 err = %v", err)
  8505. return err
  8506. } else {
  8507. out = warehouseOut
  8508. }
  8509. }
  8510. for _, item := range goods {
  8511. var newCount int64 = 0
  8512. for _, it := range goodOne {
  8513. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8514. newCount = it.Count
  8515. }
  8516. }
  8517. prepare := models.DialysisBeforePrepare{
  8518. GoodTypeId: item.GoodTypeId,
  8519. GoodId: item.GoodId,
  8520. Count: item.Count,
  8521. StorehouseId: houseConfig.StorehouseOutInfo,
  8522. }
  8523. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8524. //增加出库数量
  8525. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8526. }
  8527. }
  8528. if len(goods_yc) > 0 {
  8529. for _, good_yc := range goods_yc {
  8530. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8531. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8532. }
  8533. }
  8534. return nil
  8535. }
  8536. // 耗材出库删除
  8537. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8538. // 先根据相关信息查询当天该耗材的出库信息
  8539. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8540. if err != nil {
  8541. return err
  8542. }
  8543. var delete_count int64 = 0
  8544. for _, ware := range warehouseOutInfos {
  8545. // 判断当前出库的数据和删除出库数量
  8546. if good_yc.Count <= ware.Count {
  8547. delete_count = good_yc.Count
  8548. } else {
  8549. delete_count = ware.Count
  8550. }
  8551. warehouseOutInfo := &models.WarehouseOutInfo{
  8552. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8553. WarehouseOutId: warehouseOut.ID,
  8554. Status: 1,
  8555. Ctime: time.Now().Unix(),
  8556. Remark: "",
  8557. OrgId: orgID,
  8558. Type: 1,
  8559. Manufacturer: 0,
  8560. Dealer: 0,
  8561. IsSys: 0,
  8562. SysRecordTime: record_time,
  8563. GoodTypeId: good_yc.GoodTypeId,
  8564. GoodId: good_yc.GoodId,
  8565. StorehouseId: warehouseOut.StorehouseId,
  8566. IsCheck: 1,
  8567. }
  8568. warehouseOutInfo.Count = delete_count
  8569. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8570. warehouseOutInfo.Price = stockInInfo.Price
  8571. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8572. if errOne != nil {
  8573. return errOne
  8574. }
  8575. // 删除出库完成后,要改变流水库存(有疑问)
  8576. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8577. fmt.Println("errOne", errOne)
  8578. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8579. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8580. //扣减出库数量
  8581. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8582. if errThree != nil {
  8583. return errThree
  8584. }
  8585. }
  8586. if good_yc.Count == 0 {
  8587. return nil
  8588. } else {
  8589. return errors.New("退库和出库数据不匹配")
  8590. }
  8591. }
  8592. func (this *DialysisAPIController) GetMobileScheduleList() {
  8593. limit, _ := this.GetInt64("limit")
  8594. page, _ := this.GetInt64("page")
  8595. type_options_visible, _ := this.GetInt64("type_options_visible")
  8596. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8597. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8598. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8599. }
  8600. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8601. newArr = make([]*models.HisPrescriptionProject, 0)
  8602. for i := 0; i < len(arr); i++ {
  8603. repeat := false
  8604. for j := i + 1; j < len(arr); j++ {
  8605. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8606. repeat = true
  8607. break
  8608. }
  8609. }
  8610. if !repeat {
  8611. newArr = append(newArr, arr[i])
  8612. }
  8613. }
  8614. return
  8615. }
  8616. func (this *DialysisAPIController) GetRoleList() {
  8617. admin_user_id, _ := this.GetInt64("admin_user_id")
  8618. orgid := this.GetMobileAdminUserInfo().Org.Id
  8619. list, err := service.GetRoleList(orgid, admin_user_id)
  8620. fmt.Println(err)
  8621. this.ServeSuccessJSON(map[string]interface{}{
  8622. "list": list,
  8623. })
  8624. return
  8625. }
  8626. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8627. // 先根据相关信息查询当天该耗材的出库信息
  8628. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8629. if err != nil {
  8630. return err
  8631. }
  8632. var delete_count int64 = 0
  8633. delete_count = warehouseOutInfos.Count - count
  8634. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8635. // 删除出库完成后,要增加对应批次的库存数量
  8636. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8637. if errThree != nil {
  8638. return errThree
  8639. }
  8640. //增加退库数量
  8641. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8642. //扣减出库数量
  8643. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8644. //查询剩余库存
  8645. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8646. var sum_count int64
  8647. for _, item := range goodList {
  8648. sum_count += item.StockCount
  8649. }
  8650. // 在出库记录表里记录退库详情
  8651. warehouseOutInfo := &models.WarehouseOutInfo{
  8652. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8653. WarehouseOutId: warehouseOut.ID,
  8654. Status: 1,
  8655. Ctime: time.Now().Unix(),
  8656. OrgId: orgID,
  8657. Type: 1,
  8658. IsSys: 1,
  8659. SysRecordTime: record_time,
  8660. GoodTypeId: good_yc.GoodTypeId,
  8661. GoodId: good_yc.GoodId,
  8662. PatientId: good_yc.PatientId,
  8663. ConsumableType: 2,
  8664. StorehouseId: houseConfig.StorehouseOutInfo,
  8665. IsCheck: 1,
  8666. OverCount: sum_count,
  8667. }
  8668. warehouseOutInfo.Count = count
  8669. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8670. warehouseOutInfo.Price = stockInInfo.Price
  8671. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8672. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8673. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8674. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8675. warehouseOutInfo.Number = warehouseOutInfos.Number
  8676. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8677. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8678. //查找当天是否存在出库记录
  8679. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8680. if errcod == gorm.ErrRecordNotFound {
  8681. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8682. //插入详情明细表
  8683. if errOne != nil {
  8684. return errOne
  8685. }
  8686. //插入详情明细表
  8687. stockFlow := models.VmStockFlow{
  8688. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8689. WarehouseOutId: warehouseOut.ID,
  8690. GoodId: good_yc.GoodId,
  8691. Number: warehouseOutInfos.Number,
  8692. ProductDate: stockInInfo.ProductDate,
  8693. ExpireDate: stockInInfo.ExpiryDate,
  8694. Count: count,
  8695. Price: stockInInfo.Price,
  8696. Status: 1,
  8697. Ctime: record_time,
  8698. UserOrgId: good_yc.OrgId,
  8699. Manufacturer: stockInInfo.Manufacturer,
  8700. Dealer: stockInInfo.Dealer,
  8701. LicenseNumber: stockInInfo.LicenseNumber,
  8702. IsEdit: 2,
  8703. Creator: creater,
  8704. SystemTime: record_time,
  8705. ConsumableType: 3,
  8706. WarehousingDetailId: 0,
  8707. IsSys: 1,
  8708. UpdateCreator: creater,
  8709. PatientId: patient_id,
  8710. StorehouseId: houseConfig.StorehouseOutInfo,
  8711. OverCount: sum_count,
  8712. ProjectId: good_yc.ProjectId,
  8713. }
  8714. err := service.CreateStockFlowOne(stockFlow)
  8715. fmt.Println("err", err)
  8716. } else if errcod == nil {
  8717. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8718. }
  8719. //创建退库单
  8720. operation_time := time.Now().Unix()
  8721. //创建退库单
  8722. timeStr := time.Now().Format("2006-01-02")
  8723. timeArr := strings.Split(timeStr, "-")
  8724. total, _ := service.FindAllCancelStockTotal(orgID)
  8725. total = total + 1
  8726. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8727. cancelStock := models.CancelStock{
  8728. OrderNumber: orderNumber,
  8729. OperaTime: operation_time,
  8730. OrgId: orgID,
  8731. Creater: warehouseOut.Creater,
  8732. Ctime: time.Now().Unix(),
  8733. Status: 1,
  8734. ReturnTime: record_time,
  8735. Type: 1,
  8736. StorehouseId: stockInInfo.StorehouseId,
  8737. IsCheck: 1,
  8738. }
  8739. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8740. if msgerrkonde == gorm.ErrRecordNotFound {
  8741. service.AddSigleCancelStock(&cancelStock)
  8742. }
  8743. cancel, _ := service.GetLastCancelStockById(orgID)
  8744. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8745. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8746. cancelStockInfo := models.CancelStockInfo{
  8747. GoodId: stockInInfo.GoodId,
  8748. CancelStockId: cancel.ID,
  8749. GoodTypeId: stockInInfo.GoodTypeId,
  8750. Count: delete_count,
  8751. Price: stockInInfo.PackingPrice,
  8752. Total: 0,
  8753. ProductDate: stockInInfo.ProductDate,
  8754. ExpiryDate: stockInInfo.ExpiryDate,
  8755. Ctime: record_time,
  8756. Status: 1,
  8757. OrgId: orgID,
  8758. OrderNumber: cancel.OrderNumber,
  8759. Type: 0,
  8760. Dealer: deaerler.DealerName,
  8761. Manufacturer: manufacturer.ManufacturerName,
  8762. Number: stockInInfo.Number,
  8763. RegisterAccount: "",
  8764. Remark: "",
  8765. WarehouseInfoId: stockInInfo.ID,
  8766. PatientId: patient_id,
  8767. RecordDate: record_time,
  8768. StorehouseId: stockInInfo.StorehouseId,
  8769. IsCheck: 1,
  8770. }
  8771. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8772. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8773. flow := models.VmStockFlow{
  8774. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8775. GoodId: good_yc.GoodId,
  8776. Number: warehouseOutInfos.Number,
  8777. LicenseNumber: stockInInfo.LicenseNumber,
  8778. Count: delete_count,
  8779. UserOrgId: orgID,
  8780. PatientId: patient_id,
  8781. SystemTime: record_time,
  8782. ConsumableType: 7,
  8783. IsSys: 0,
  8784. WarehousingOrder: "",
  8785. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8786. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8787. IsEdit: 0,
  8788. CancelStockId: cancel.ID,
  8789. CancelOrderNumber: cancel.OrderNumber,
  8790. Manufacturer: manufacturer.ID,
  8791. Dealer: 0,
  8792. Creator: warehouseOut.Creater,
  8793. UpdateCreator: 0,
  8794. Status: 1,
  8795. Ctime: record_time,
  8796. Mtime: 0,
  8797. Price: stockInInfo.Price,
  8798. WarehousingDetailId: stockInInfo.ID,
  8799. WarehouseOutDetailId: warehouseOutInfos.ID,
  8800. CancelOutDetailId: cancelInfo.ID,
  8801. ProductDate: stockInInfo.ProductDate,
  8802. ExpireDate: stockInInfo.ExpiryDate,
  8803. StorehouseId: houseConfig.StorehouseOutInfo,
  8804. OverCount: sum_count,
  8805. }
  8806. service.CreateStockFlowOne(flow)
  8807. //更改自动出库的表格
  8808. details := models.BloodAutomaticReduceDetail{
  8809. WarehouseOutId: warehouseOutInfo.ID,
  8810. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8811. PatientId: patient_id,
  8812. Ctime: time.Now().Unix(),
  8813. Mtime: time.Now().Unix(),
  8814. Status: 1,
  8815. RecordTime: record_time,
  8816. OrgId: orgID,
  8817. GoodId: good_yc.GoodId,
  8818. GoodTypeId: good_yc.GoodTypeId,
  8819. Count: count,
  8820. StorehouseId: houseConfig.StorehouseOutInfo,
  8821. }
  8822. //查询当天耗材是否已经存在数据
  8823. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8824. if errcode == gorm.ErrRecordNotFound {
  8825. errTwo := service.CreateAutoReduceRecord(&details)
  8826. if errTwo != nil {
  8827. return errTwo
  8828. }
  8829. } else if errcode == nil {
  8830. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8831. service.CreateAutoReduceRecord(&details)
  8832. }
  8833. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8834. //增加出库库存数量
  8835. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8836. if good_yc.Count == 0 {
  8837. return nil
  8838. } else {
  8839. return errors.New("退库和出库数据不匹配")
  8840. }
  8841. }
  8842. func (this *DialysisAPIController) SavePatientSign() {
  8843. adminUserInfo := this.GetMobileAdminUserInfo()
  8844. patient_id, _ := this.GetInt64("patient_id")
  8845. dialysis_date, _ := this.GetInt64("dialysis_date")
  8846. orgid := adminUserInfo.Org.Id
  8847. var esdata models.DialysisOrder
  8848. var err error
  8849. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8850. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8851. return
  8852. }
  8853. esdata.Hash = esdata.Hash
  8854. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8855. order := models.DialysisOrder{
  8856. Hash: esdata.Hash,
  8857. Url: esdata.Url,
  8858. }
  8859. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8860. redis := service.RedisClient()
  8861. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8862. redis.Set(key, "", time.Second)
  8863. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8864. //清空key 值
  8865. redis.Set(keyOne, "", time.Second)
  8866. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8867. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8868. //redis.Set(keyTwo, "", time.Second)
  8869. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8870. redis.Set(keyThree, "", time.Second)
  8871. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8872. redis.Set(keyFour, "", time.Second)
  8873. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8874. redis.Set(keyFive, "", time.Second)
  8875. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8876. redis.Set(keySix, "", time.Second)
  8877. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8878. redis.Set(keySeven, "", time.Second)
  8879. if err != nil {
  8880. fmt.Println(err)
  8881. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8882. return
  8883. }
  8884. this.ServeSuccessJSON(map[string]interface{}{
  8885. "electronic_signature": esdata,
  8886. })
  8887. }
  8888. func (this *DialysisAPIController) GetPatientSign() {
  8889. patient_id, _ := this.GetInt64("patient_id")
  8890. dialysis_date, _ := this.GetInt64("dialysis_date")
  8891. adminUserInfo := this.GetMobileAdminUserInfo()
  8892. orgId := adminUserInfo.Org.Id
  8893. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8894. if err != nil {
  8895. fmt.Println(err)
  8896. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8897. return
  8898. }
  8899. this.ServeSuccessJSON(map[string]interface{}{
  8900. "dialysisOrder": dialysisOrder,
  8901. })
  8902. }
  8903. func (this *DialysisAPIController) GetScheduleByPatient() {
  8904. patient_id, _ := this.GetInt64("patient_id")
  8905. schedule_date, _ := this.GetInt64("schedule_date")
  8906. orgid := this.GetMobileAdminUserInfo().Org.Id
  8907. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8908. this.ServeSuccessJSON(map[string]interface{}{
  8909. "schedule": schedule,
  8910. })
  8911. }
  8912. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8913. org_id := this.GetMobileAdminUserInfo().Org.Id
  8914. patient_id, _ := this.GetInt64("patient_id")
  8915. schedule_date, _ := this.GetInt64("schedule_date")
  8916. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8917. this.ServeSuccessJSON(map[string]interface{}{
  8918. "order": order,
  8919. })
  8920. }
  8921. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8922. org_id := this.GetMobileAdminUserInfo().Org.Id
  8923. schedule_date := this.GetString("schedule_date")
  8924. schedule_type, _ := this.GetInt64("schedule_type")
  8925. timeLayout := "2006-01-02"
  8926. loc, _ := time.LoadLocation("Local")
  8927. var startdateunix int64
  8928. if len(schedule_date) > 0 {
  8929. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8930. if err != nil {
  8931. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8932. return
  8933. }
  8934. startdateunix = theTime.Unix()
  8935. }
  8936. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8937. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8938. devices, _ := service.GetAllDevicetByListSix(org_id)
  8939. for key, item := range scheduals {
  8940. // 床位信息
  8941. for _, device := range devices {
  8942. if item.BedId == device.ID {
  8943. scheduals[key].DeviceNumber = device
  8944. break
  8945. }
  8946. }
  8947. }
  8948. this.ServeSuccessJSON(map[string]interface{}{
  8949. "list": list,
  8950. "scheduals": scheduals,
  8951. })
  8952. }
  8953. func (this *DialysisAPIController) SavePatientPicture() {
  8954. patient_id, _ := this.GetInt64("patient_id")
  8955. dialysis_date, _ := this.GetInt64("schedule_date")
  8956. avatar := this.GetString("avatar")
  8957. fmt.Println("patient_id", patient_id)
  8958. orgId := this.GetMobileAdminUserInfo().Org.Id
  8959. order := models.DialysisOrder{
  8960. Url: avatar,
  8961. }
  8962. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8963. redis := service.RedisClient()
  8964. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8965. redis.Set(key, "", time.Second)
  8966. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8967. //清空key 值
  8968. redis.Set(keyOne, "", time.Second)
  8969. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8970. redis.Set(keyThree, "", time.Second)
  8971. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8972. redis.Set(keyFour, "", time.Second)
  8973. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8974. redis.Set(keyFive, "", time.Second)
  8975. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8976. redis.Set(keySix, "", time.Second)
  8977. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8978. redis.Set(keySeven, "", time.Second)
  8979. if err != nil {
  8980. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8981. return
  8982. }
  8983. this.ServeSuccessJSON(map[string]interface{}{
  8984. "order": order,
  8985. })
  8986. }
  8987. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8988. ids := this.GetString("ids")
  8989. idSplit := strings.Split(ids, ",")
  8990. orgId := this.GetMobileAdminUserInfo().Org.Id
  8991. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8992. execution_time := this.GetString("exce_time")
  8993. timeLayout2 := "2006-01-02 15:04:05"
  8994. loc, _ := time.LoadLocation("Local")
  8995. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8996. if errs != nil {
  8997. utils.ErrorLog(errs.Error())
  8998. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8999. return
  9000. }
  9001. //his客户
  9002. if config.IsOpen == 1 {
  9003. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  9004. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  9005. for _, item := range list {
  9006. for _, it := range adviceList {
  9007. if item.DrugId == it.DrugId {
  9008. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9009. }
  9010. }
  9011. }
  9012. for _, item := range list {
  9013. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9014. var sum_out_count int64
  9015. for _, itemThree := range item.ChildDoctorAdvice {
  9016. var prescribing_number int64
  9017. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9018. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9019. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9020. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9021. }
  9022. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9023. prescribing_number = parseIntPrescribingNumber
  9024. }
  9025. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9026. prescribing_number = parseIntPrescribingNumber
  9027. }
  9028. sum_out_count += prescribing_number
  9029. }
  9030. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9031. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9032. //库存不足
  9033. if sum_out_count > drugStockOut.FlushCount {
  9034. this.ServeSuccessJSON(map[string]interface{}{
  9035. "msg": "2",
  9036. "drug": medical,
  9037. "ids": ids,
  9038. })
  9039. return
  9040. }
  9041. }
  9042. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9043. //执行医嘱
  9044. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9045. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  9046. for _, item := range advices {
  9047. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9048. redis := service.RedisClient()
  9049. //清空key 值
  9050. redis.Set(key, "", time.Second)
  9051. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9052. redis.Set(keyTwo, "", time.Second)
  9053. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9054. redis.Set(keyThree, "", time.Second)
  9055. recordDate := theTime.Format("2006-01-02")
  9056. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9057. redis.Set(keyFour, "", time.Second)
  9058. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9059. redis.Set(keyFive, "", time.Second)
  9060. defer redis.Close()
  9061. }
  9062. if errs == nil {
  9063. //药品管理信息
  9064. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9065. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9066. if drugStockConfig.IsOpen == 1 {
  9067. for _, item := range advices {
  9068. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  9069. config, _ := service.GetDrugOpenConfigOne(orgId)
  9070. if config.IsOpen != 1 {
  9071. //查询该药品是否有库存
  9072. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9073. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  9074. if medical.IsUse == 2 {
  9075. if config.IsOpen != 1 {
  9076. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9077. service.HisDrugsDelivery(orgId, creater, &advice)
  9078. if orgId == 3877 || orgId == 10265 {
  9079. //查询该药品是否有出库记录
  9080. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9081. if len(flowMap) == 0 {
  9082. errs := service.UpdateHisAdviceById(advice.ID)
  9083. if errs != nil {
  9084. drugError := models.XtDrugError{
  9085. UserOrgId: orgId,
  9086. DrugId: item.DrugId,
  9087. RecordDate: item.AdviceDate,
  9088. PatientId: item.PatientId,
  9089. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9090. Status: 1,
  9091. Ctime: time.Now().Unix(),
  9092. Mtime: 0,
  9093. SumCount: 0,
  9094. Prescribingnumber: advice.PrescribingNumber,
  9095. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9096. }
  9097. service.CreateDrugError(drugError)
  9098. }
  9099. this.ServeSuccessJSON(map[string]interface{}{
  9100. "msg": "2",
  9101. "drug": medical,
  9102. "ids": ids,
  9103. })
  9104. return
  9105. }
  9106. }
  9107. }
  9108. if pharmacyConfig.IsOpen != 1 {
  9109. service.HisDrugsDelivery(orgId, creater, &advice)
  9110. if orgId == 3877 || orgId == 10265 {
  9111. //查询该药品是否有出库记录
  9112. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9113. if len(flowMap) == 0 {
  9114. errs := service.UpdateHisAdviceById(advice.ID)
  9115. if errs != nil {
  9116. drugError := models.XtDrugError{
  9117. UserOrgId: orgId,
  9118. DrugId: item.DrugId,
  9119. RecordDate: item.AdviceDate,
  9120. PatientId: item.PatientId,
  9121. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9122. Status: 1,
  9123. Ctime: time.Now().Unix(),
  9124. Mtime: 0,
  9125. SumCount: 0,
  9126. Prescribingnumber: advice.PrescribingNumber,
  9127. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9128. }
  9129. service.CreateDrugError(drugError)
  9130. }
  9131. this.ServeSuccessJSON(map[string]interface{}{
  9132. "msg": "2",
  9133. "drug": medical,
  9134. "ids": ids,
  9135. })
  9136. return
  9137. }
  9138. }
  9139. }
  9140. //更新字典里面的库存
  9141. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9142. var sum_count int64
  9143. for _, its := range stockInfo {
  9144. if its.MaxUnit == medical.MaxUnit {
  9145. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9146. }
  9147. sum_count += its.StockMaxNumber + its.StockMinNumber
  9148. }
  9149. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9150. //剩余库存
  9151. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9152. }
  9153. }
  9154. }
  9155. }
  9156. }
  9157. this.ServeSuccessJSON(map[string]interface{}{
  9158. "msg": "1",
  9159. "ids": ids,
  9160. })
  9161. return
  9162. } else {
  9163. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9164. }
  9165. }
  9166. //血透客户
  9167. if config.IsOpen == 2 || config.IsOpen == 0 {
  9168. //药品管理信息
  9169. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9170. if drugStockConfig.IsOpen == 1 {
  9171. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9172. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9173. for _, item := range list {
  9174. for _, it := range adviceList {
  9175. if item.DrugId == it.DrugId {
  9176. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9177. }
  9178. }
  9179. }
  9180. for _, item := range list {
  9181. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9182. var sum_out_count int64
  9183. for _, itemThree := range item.ChildDoctorAdvice {
  9184. var prescribing_number int64
  9185. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9186. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9187. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9188. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9189. }
  9190. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9191. prescribing_number = parseIntPrescribingNumber
  9192. }
  9193. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9194. prescribing_number = parseIntPrescribingNumber
  9195. }
  9196. sum_out_count += prescribing_number
  9197. }
  9198. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9199. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9200. //库存不足
  9201. if sum_out_count > drugStockOut.FlushCount {
  9202. this.ServeSuccessJSON(map[string]interface{}{
  9203. "msg": "2",
  9204. "drug": medical,
  9205. "ids": ids,
  9206. })
  9207. return
  9208. }
  9209. }
  9210. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9211. //执行医嘱
  9212. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9213. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9214. for _, item := range advices {
  9215. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9216. redis := service.RedisClient()
  9217. //清空key 值
  9218. redis.Set(key, "", time.Second)
  9219. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9220. redis.Set(keyTwo, "", time.Second)
  9221. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9222. redis.Set(keyThree, "", time.Second)
  9223. recordDate := theTime.Format("2006-01-02")
  9224. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9225. redis.Set(keyFour, "", time.Second)
  9226. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9227. redis.Set(keyFive, "", time.Second)
  9228. defer redis.Close()
  9229. }
  9230. if errs == nil {
  9231. for _, item := range advices {
  9232. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9233. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9234. //查询是否出库按钮开启
  9235. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9236. if adviceSetting.IsAdviceOpen == 1 {
  9237. //查询是否出库按钮开启
  9238. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9239. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9240. if prescriptionConfig.IsOpen == 1 {
  9241. if medical.IsUse == 2 {
  9242. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9243. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9244. }
  9245. if pharmacyConfig.IsOpen != 1 {
  9246. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9247. }
  9248. //更新字典里面的库存
  9249. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9250. var sum_count int64
  9251. for _, its := range stockInfo {
  9252. if its.MaxUnit == medical.MaxUnit {
  9253. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9254. }
  9255. sum_count += its.StockMaxNumber + its.StockMinNumber
  9256. }
  9257. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9258. //剩余库存
  9259. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9260. }
  9261. }
  9262. } else {
  9263. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9264. if medical.IsUse == 2 {
  9265. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9266. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9267. }
  9268. if pharmacyConfig.IsOpen != 1 {
  9269. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9270. }
  9271. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9272. var sum_count int64
  9273. for _, its := range stockInfo {
  9274. if its.MaxUnit == medical.MaxUnit {
  9275. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9276. }
  9277. sum_count += its.StockMaxNumber + its.StockMinNumber
  9278. }
  9279. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9280. //剩余库存
  9281. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9282. }
  9283. }
  9284. }
  9285. }
  9286. this.ServeSuccessJSON(map[string]interface{}{
  9287. "msg": "1",
  9288. "ids": ids,
  9289. })
  9290. return
  9291. } else {
  9292. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9293. //执行医嘱
  9294. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9295. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9296. for _, item := range advices {
  9297. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9298. redis := service.RedisClient()
  9299. //清空key 值
  9300. redis.Set(key, "", time.Second)
  9301. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9302. redis.Set(keyTwo, "", time.Second)
  9303. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9304. redis.Set(keyThree, "", time.Second)
  9305. recordDate := theTime.Format("2006-01-02")
  9306. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9307. redis.Set(keyFour, "", time.Second)
  9308. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9309. redis.Set(keyFive, "", time.Second)
  9310. defer redis.Close()
  9311. }
  9312. this.ServeSuccessJSON(map[string]interface{}{
  9313. "msg": "1",
  9314. "ids": ids,
  9315. })
  9316. return
  9317. }
  9318. }
  9319. }
  9320. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9321. ids := this.GetString("ids")
  9322. idSplit := strings.Split(ids, ",")
  9323. orgId := this.GetMobileAdminUserInfo().Org.Id
  9324. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9325. if config.IsOpen == 1 {
  9326. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9327. this.ServeSuccessJSON(map[string]interface{}{
  9328. "msg": "1",
  9329. "ids": ids,
  9330. })
  9331. return
  9332. }
  9333. if config.IsOpen == 0 || config.IsOpen == 2 {
  9334. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9335. this.ServeSuccessJSON(map[string]interface{}{
  9336. "msg": "1",
  9337. "ids": ids,
  9338. })
  9339. return
  9340. }
  9341. }
  9342. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9343. ids := this.GetString("ids")
  9344. idSplit := strings.Split(ids, ",")
  9345. orgId := this.GetMobileAdminUserInfo().Org.Id
  9346. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9347. //his
  9348. if config.IsOpen == 1 {
  9349. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9350. theTime := time.Now()
  9351. advices := models.HisDoctorAdviceThirty{
  9352. CheckTime: theTime.Unix(),
  9353. Checker: checker,
  9354. UpdatedTime: time.Now().Unix(),
  9355. }
  9356. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9357. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9358. for _, item := range list {
  9359. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9360. redis := service.RedisClient()
  9361. //清空key 值
  9362. redis.Set(key, "", time.Second)
  9363. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9364. redis.Set(keyTwo, "", time.Second)
  9365. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9366. redis.Set(keyThree, "", time.Second)
  9367. recordDate := theTime.Format("2006-01-02")
  9368. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9369. redis.Set(keyFour, "", time.Second)
  9370. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9371. redis.Set(keyFive, "", time.Second)
  9372. defer redis.Close()
  9373. }
  9374. this.ServeSuccessJSON(map[string]interface{}{
  9375. "msg": "1",
  9376. "ids": ids,
  9377. })
  9378. return
  9379. }
  9380. //血透
  9381. if config.IsOpen == 0 || config.IsOpen == 2 {
  9382. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9383. theTime := time.Now()
  9384. advices := models.DoctorAdvice{
  9385. CheckTime: theTime.Unix(),
  9386. Checker: checker,
  9387. UpdatedTime: time.Now().Unix(),
  9388. }
  9389. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9390. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9391. for _, item := range list {
  9392. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9393. redis := service.RedisClient()
  9394. //清空key 值
  9395. redis.Set(key, "", time.Second)
  9396. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9397. redis.Set(keyTwo, "", time.Second)
  9398. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9399. redis.Set(keyThree, "", time.Second)
  9400. recordDate := theTime.Format("2006-01-02")
  9401. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9402. redis.Set(keyFour, "", time.Second)
  9403. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9404. redis.Set(keyFive, "", time.Second)
  9405. defer redis.Close()
  9406. }
  9407. this.ServeSuccessJSON(map[string]interface{}{
  9408. "msg": "1",
  9409. "ids": ids,
  9410. })
  9411. return
  9412. }
  9413. }
  9414. func (this *DialysisAPIController) CheckSchedule() {
  9415. patientID, _ := this.GetInt64("patient_id")
  9416. recordDateStr := this.GetString("record_date")
  9417. nurseID, _ := this.GetInt64("start_nurse")
  9418. schedual_type, _ := this.GetInt64("schedual_type")
  9419. bedID, _ := this.GetInt64("bed")
  9420. start_time := this.GetString("start_time")
  9421. fmt.Println("patientID", patientID)
  9422. fmt.Println("recordDateStr", recordDateStr)
  9423. fmt.Println("nurseID", nurseID)
  9424. fmt.Println("schedual_type------", schedual_type)
  9425. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9426. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9427. return
  9428. }
  9429. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9430. if parseStartDateErr != nil {
  9431. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9432. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9433. return
  9434. }
  9435. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9436. if parseErr != nil {
  9437. this.ErrorLog("时间解析失败:%v", parseErr)
  9438. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9439. return
  9440. }
  9441. adminUserInfo := this.GetMobileAdminUserInfo()
  9442. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9443. if getPatientErr != nil {
  9444. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9445. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9446. return
  9447. } else if patient == nil {
  9448. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9449. return
  9450. }
  9451. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9452. if getNurseErr != nil {
  9453. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9454. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9455. return
  9456. } else if nurse == nil {
  9457. this.ErrorLog("护士不存在")
  9458. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9459. return
  9460. }
  9461. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9462. if getDeviceNumberErr != nil {
  9463. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9464. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9465. return
  9466. } else if deviceNumber == nil {
  9467. this.ErrorLog("床位号不存在")
  9468. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9469. return
  9470. }
  9471. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9472. if getRecordErr != nil {
  9473. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9474. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9475. return
  9476. } else if dialysisRecord != nil {
  9477. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9478. return
  9479. }
  9480. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9481. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9482. timeLayout := "2006-01-02 15:04:05"
  9483. loc, _ := time.LoadLocation("Local")
  9484. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9485. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9486. schedulestartTime := theStartTime.Unix()
  9487. scheduleendTime := theEndTime.Unix()
  9488. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9489. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9490. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9491. //查询该床位是否有人用了
  9492. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9493. if err == nil {
  9494. if schedule.ID == 0 {
  9495. this.ServeSuccessJSON(map[string]interface{}{
  9496. "status": 0,
  9497. "msg": "请求失败",
  9498. })
  9499. } else {
  9500. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9501. if order.ID > 0 { //该机位被其他人占用了
  9502. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9503. return
  9504. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9505. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9506. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9507. this.ServeSuccessJSON(map[string]interface{}{
  9508. "status": 1,
  9509. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9510. })
  9511. return
  9512. } else {
  9513. this.ServeSuccessJSON(map[string]interface{}{
  9514. "status": 0,
  9515. "msg": "",
  9516. })
  9517. }
  9518. }
  9519. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9520. this.ServeSuccessJSON(map[string]interface{}{
  9521. "status": 2,
  9522. "msg": "当前机位已有患者在使用,请重新选择!",
  9523. })
  9524. }
  9525. }
  9526. } else {
  9527. this.ServeSuccessJSON(map[string]interface{}{
  9528. "status": 0,
  9529. "msg": "",
  9530. })
  9531. }
  9532. }
  9533. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9534. orgId := this.GetMobileAdminUserInfo().Org.Id
  9535. schedule_type, _ := this.GetInt64("schedule_type")
  9536. partion_type, _ := this.GetInt64("partion_type")
  9537. start_time := this.GetString("start_time")
  9538. timeLayout := "2006-01-02"
  9539. loc, _ := time.LoadLocation("Local")
  9540. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9541. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9542. _, config := service.FindXTHisRecordByOrgId(orgId)
  9543. appId := this.GetMobileAdminUserInfo().App.Id
  9544. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9545. if err == nil {
  9546. this.ServeSuccessJSON(map[string]interface{}{
  9547. "list": list,
  9548. "config": config,
  9549. "doctorList": doctorList,
  9550. })
  9551. return
  9552. } else {
  9553. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9554. return
  9555. }
  9556. }
  9557. func (this *DialysisAPIController) SaveMobileInformation() {
  9558. patient_id, _ := this.GetInt64("patient_id")
  9559. record_date, _ := this.GetInt64("record_date")
  9560. startTime := this.GetString("start_time")
  9561. module, _ := this.GetInt64("module")
  9562. remark := this.GetString("remark")
  9563. timeLayout := "2006-01-02 15:04"
  9564. loc, _ := time.LoadLocation("Local")
  9565. if len(startTime) == 0 {
  9566. utils.ErrorLog("len(start_time) == 0")
  9567. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9568. return
  9569. }
  9570. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9571. if err != nil {
  9572. utils.ErrorLog(err.Error())
  9573. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9574. return
  9575. }
  9576. StartTime := theTime.Unix()
  9577. fmt.Println("startime-------------", StartTime)
  9578. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9579. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9580. information := models.XtDialysisInformation{
  9581. Module: module,
  9582. PatientId: patient_id,
  9583. RecordDate: record_date,
  9584. ApplicationDate: StartTime,
  9585. Creater: creater,
  9586. ApplicationStatus: 2,
  9587. Checker: 0,
  9588. CheckTime: 0,
  9589. Remark: remark,
  9590. UserOrgId: user_org_id,
  9591. Ctime: time.Now().Unix(),
  9592. Status: 1,
  9593. Mtime: 0,
  9594. }
  9595. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9596. if infor.ID == 0 {
  9597. service.SaveDialysisInformation(information)
  9598. }
  9599. if infor.ID > 0 {
  9600. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9601. }
  9602. this.ServeSuccessJSON(map[string]interface{}{
  9603. "information": information,
  9604. })
  9605. return
  9606. }
  9607. func (this *DialysisAPIController) GetMobileInformation() {
  9608. limit, _ := this.GetInt64("limit")
  9609. page, _ := this.GetInt64("page")
  9610. orgid := this.GetMobileAdminUserInfo().Org.Id
  9611. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9612. appid := this.GetMobileAdminUserInfo().App.Id
  9613. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9614. patients, _ := service.GetAllpatientThirty(orgid)
  9615. this.ServeSuccessJSON(map[string]interface{}{
  9616. "information": information,
  9617. "total": total,
  9618. "doclist": doclist,
  9619. "patients": patients,
  9620. })
  9621. return
  9622. }
  9623. func (this *DialysisAPIController) GetMobileInformationOne() {
  9624. limit, _ := this.GetInt64("limit")
  9625. page, _ := this.GetInt64("page")
  9626. orgid := this.GetMobileAdminUserInfo().Org.Id
  9627. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9628. appid := this.GetMobileAdminUserInfo().App.Id
  9629. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9630. patients, _ := service.GetAllpatientThirty(orgid)
  9631. this.ServeSuccessJSON(map[string]interface{}{
  9632. "information": information,
  9633. "total": total,
  9634. "doclist": doclist,
  9635. "patients": patients,
  9636. })
  9637. return
  9638. }
  9639. func (this *DialysisAPIController) CheckMobileInformation() {
  9640. id, _ := this.GetInt64("id")
  9641. application_status, _ := this.GetInt64("application_status")
  9642. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9643. checktime := time.Now().Unix()
  9644. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9645. if err == nil {
  9646. this.ServeSuccessJSON(map[string]interface{}{
  9647. "msg": "ok",
  9648. })
  9649. return
  9650. }
  9651. }
  9652. func (c *DialysisAPIController) GetControlMonitorList() {
  9653. partition, _ := c.GetInt64("partition")
  9654. monitorDate := c.GetString("date")
  9655. patient_id, _ := c.GetInt64("patient_id")
  9656. pat_type, _ := c.GetInt64("pat_type")
  9657. timeLayout := "2006-01-02"
  9658. loc, _ := time.LoadLocation("Local")
  9659. var theStartTime int64
  9660. if len(monitorDate) > 0 {
  9661. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9662. if err != nil {
  9663. theStartTime = 0
  9664. }
  9665. theStartTime = theTime.Unix()
  9666. }
  9667. adminInfo := c.GetMobileAdminUserInfo()
  9668. orgID := adminInfo.Org.Id
  9669. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9670. if err != nil {
  9671. c.ErrorLog("获取排班信息失败:%v", err)
  9672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9673. } else {
  9674. if len(monitor) > 0 {
  9675. //获取所有床位
  9676. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9677. //获取所有分区
  9678. zoneList, _ := service.GetAllZoneByList(orgID)
  9679. //获取透析处方
  9680. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9681. //获取透前评估
  9682. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9683. //获取上机
  9684. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9685. //获取透后
  9686. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9687. //获取透后监测
  9688. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9689. //获取所有的患者
  9690. patients, _ := service.GetAllPatientListByListOne(orgID)
  9691. //获取所有透析模式
  9692. treatments, _ := service.GetAllTreatModeByList(orgID)
  9693. //获取所有医嘱
  9694. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9695. //获取双人核对
  9696. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9697. //治疗小结
  9698. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9699. //待消毒
  9700. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9701. for key, item := range monitor {
  9702. // 获取床位信息
  9703. for _, it := range numberList {
  9704. if item.BedId == it.ID {
  9705. monitor[key].DeviceNumber = it
  9706. break
  9707. }
  9708. }
  9709. //获取分区信息
  9710. for _, it := range zoneList {
  9711. if item.PartitionId == it.ID {
  9712. monitor[key].DeviceZone = it
  9713. }
  9714. }
  9715. for _, prescription := range prescriptions {
  9716. if item.PatientId == prescription.PatientId {
  9717. monitor[key].Prescription = prescription
  9718. break
  9719. }
  9720. }
  9721. for _, it := range checkList {
  9722. if item.PatientId == it.PatientId {
  9723. monitor[key].DoubleCheck = it
  9724. break
  9725. }
  9726. }
  9727. for _, it := range summaryList {
  9728. if item.PatientId == it.PatientId {
  9729. monitor[key].TreatmentSummaryForList = it
  9730. break
  9731. }
  9732. }
  9733. // 透前评估
  9734. for _, assessmentBefore := range assessmentBefores {
  9735. if item.PatientId == assessmentBefore.PatientId {
  9736. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9737. break
  9738. }
  9739. }
  9740. // 透析上下机
  9741. for _, dialysisOrder := range dialysisOrders {
  9742. if item.PatientId == dialysisOrder.PatientId {
  9743. monitor[key].DialysisOrder = dialysisOrder
  9744. break
  9745. }
  9746. }
  9747. // 治疗小节
  9748. for _, afterDislysis := range AssessmentAfterDislysis {
  9749. if item.PatientId == afterDislysis.PatientId {
  9750. monitor[key].AssessmentAfterDislysis = afterDislysis
  9751. break
  9752. }
  9753. }
  9754. for _, it := range monitorlist {
  9755. if item.PatientId == it.PatientId {
  9756. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9757. }
  9758. }
  9759. for _, it := range adviceList {
  9760. if item.PatientId == it.PatientId {
  9761. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9762. }
  9763. }
  9764. for _, patient := range patients {
  9765. if item.PatientId == patient.ID {
  9766. monitor[key].MonitorPatients = patient
  9767. break
  9768. }
  9769. }
  9770. for _, treatment := range treatments {
  9771. if item.ModeId == treatment.ID {
  9772. monitor[key].TreatmentMode = treatment
  9773. break
  9774. }
  9775. }
  9776. for _, infor := range informationList {
  9777. if item.PatientId == infor.PatientId {
  9778. monitor[key].NewDeviceInformation = infor
  9779. break
  9780. }
  9781. }
  9782. }
  9783. }
  9784. }
  9785. patients, err := service.GetAllpatientFourty(orgID)
  9786. var mds []*models.NewMonitorDialysisScheduleList
  9787. if pat_type == 0 {
  9788. for _, item := range monitor {
  9789. mds = append(mds, item)
  9790. }
  9791. }
  9792. //待医嘱核对
  9793. if pat_type == 1 {
  9794. for _, item := range monitor {
  9795. if len(item.AdviceList) > 0 {
  9796. mds = append(mds, item)
  9797. }
  9798. }
  9799. }
  9800. //待开小结
  9801. if pat_type == 2 {
  9802. for _, item := range monitor {
  9803. if item.TreatmentSummaryForList == nil {
  9804. mds = append(mds, item)
  9805. }
  9806. }
  9807. }
  9808. //待下机
  9809. if pat_type == 3 {
  9810. for _, item := range monitor {
  9811. if item.DialysisOrder != nil {
  9812. if item.DialysisOrder.ID > 0 {
  9813. mds = append(mds, item)
  9814. }
  9815. }
  9816. }
  9817. }
  9818. //待消毒
  9819. if pat_type == 4 {
  9820. for _, item := range monitor {
  9821. if item.NewDeviceInformation == nil {
  9822. mds = append(mds, item)
  9823. }
  9824. }
  9825. }
  9826. //待双人核对
  9827. if pat_type == 5 {
  9828. for _, item := range monitor {
  9829. if item.DoubleCheck == nil {
  9830. mds = append(mds, item)
  9831. }
  9832. }
  9833. }
  9834. //医嘱未执行
  9835. if pat_type == 6 {
  9836. for _, item := range monitor {
  9837. if len(item.AdviceList) > 0 {
  9838. mds = append(mds, item)
  9839. }
  9840. }
  9841. }
  9842. //患者未签名
  9843. if pat_type == 7 {
  9844. for _, item := range monitor {
  9845. if item.DialysisOrder != nil {
  9846. if item.DialysisOrder.ID > 0 {
  9847. mds = append(mds, item)
  9848. }
  9849. }
  9850. }
  9851. }
  9852. //目标超滤于实际超滤不同
  9853. if pat_type == 8 {
  9854. for _, item := range monitor {
  9855. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9856. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9857. mds = append(mds, item)
  9858. }
  9859. }
  9860. }
  9861. }
  9862. //血压少于5次
  9863. if pat_type == 9 {
  9864. for _, item := range monitor {
  9865. if len(item.MonitoringRecord) < 5 {
  9866. mds = append(mds, item)
  9867. }
  9868. }
  9869. }
  9870. if pat_type == 10 {
  9871. for _, item := range monitor {
  9872. if len(item.MonitoringRecord) == 0 {
  9873. mds = append(mds, item)
  9874. }
  9875. }
  9876. }
  9877. if pat_type == 11 {
  9878. for _, item := range monitor {
  9879. if len(item.MonitoringRecord) > 0 {
  9880. mds = append(mds, item)
  9881. }
  9882. }
  9883. }
  9884. if pat_type == 12 {
  9885. for _, item := range monitor {
  9886. if len(item.MonitoringRecord) > 0 {
  9887. mds = append(mds, item)
  9888. }
  9889. }
  9890. }
  9891. if err == nil {
  9892. c.ServeSuccessJSON(map[string]interface{}{
  9893. "monitor": mds,
  9894. "patients": patients,
  9895. })
  9896. } else {
  9897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9898. }
  9899. }
  9900. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9901. admin_user_id, _ := c.GetInt64("admin_user_id")
  9902. timeStr := time.Now().Format("2006-01-02")
  9903. timeLayout := "2006-01-02 15:04:05"
  9904. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9905. timenow := timeStringToTime.Unix()
  9906. orgId := c.GetMobileAdminUserInfo().Org.Id
  9907. //查询当前护士的患者
  9908. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9909. var patientIds []int64
  9910. for _, item := range orderList {
  9911. patientIds = append(patientIds, item.PatientId)
  9912. }
  9913. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9914. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9915. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9916. //药品管理信息
  9917. _, drugStockConfig := service.FindHisConfig(orgId)
  9918. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9919. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9920. c.ServeSuccessJSON(map[string]interface{}{
  9921. "adviceList": adviceList,
  9922. "hisAdviceList": hisAdviceList,
  9923. "projectList": projectList,
  9924. "drugStockConfig": drugStockConfig,
  9925. "patientList": patientList,
  9926. "projectConfig": projectConfig,
  9927. })
  9928. }
  9929. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9930. patient_id, _ := c.GetInt64("patient_id")
  9931. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9932. c.ServeSuccessJSON(map[string]interface{}{
  9933. "recrods": recrods,
  9934. })
  9935. }
  9936. func (c *DialysisAPIController) ExMobileChangeSch() {
  9937. id_one, _ := c.GetInt64("id_one")
  9938. id_two, _ := c.GetInt64("id_two")
  9939. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9940. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9941. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9942. //if order2.ID > 0 {
  9943. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9944. // return
  9945. //}
  9946. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9947. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9948. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9949. if count > 0 {
  9950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9951. return
  9952. }
  9953. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9954. if count1 > 0 {
  9955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9956. return
  9957. }
  9958. }
  9959. err := service.UpdateScheduleThree(sch, sch_two)
  9960. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  9961. if order.ID > 0 {
  9962. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  9963. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9964. redis := service.RedisClient()
  9965. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  9966. redis.Set(key, "", time.Second)
  9967. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9968. //清空key 值
  9969. redis.Set(keyOne, "", time.Second)
  9970. }
  9971. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  9972. if orderOne.ID > 0 {
  9973. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  9974. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  9975. redis := service.RedisClient()
  9976. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9977. redis.Set(key, "", time.Second)
  9978. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9979. //清空key 值
  9980. redis.Set(keyOne, "", time.Second)
  9981. }
  9982. if err == nil {
  9983. //去除当天患者排班中重复数据,保留最后一条数据
  9984. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9985. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9986. c.ServeSuccessJSON(map[string]interface{}{
  9987. "msg": "交换成功",
  9988. })
  9989. } else {
  9990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9991. return
  9992. }
  9993. }
  9994. func (c *DialysisAPIController) MobileCoverSch() {
  9995. id_one, _ := c.GetInt64("id_one")
  9996. id_two, _ := c.GetInt64("id_two")
  9997. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9998. //针对凤凰医院
  9999. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  10000. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10001. if len(advice) > 0 {
  10002. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10003. }
  10004. }
  10005. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  10006. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10007. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10008. if len(hisAdvice) > 0 {
  10009. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10010. }
  10011. if len(project) > 0 {
  10012. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10013. }
  10014. }
  10015. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10016. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10017. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10018. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10019. if count > 0 {
  10020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10021. return
  10022. }
  10023. }
  10024. var new_sch models.Schedule
  10025. new_sch = sch
  10026. new_sch.BedId = sch_two.BedId
  10027. new_sch.ScheduleDate = sch_two.ScheduleDate
  10028. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  10029. new_sch.PartitionId = sch_two.PartitionId
  10030. new_sch.ScheduleType = sch_two.ScheduleType
  10031. new_sch.ID = 0
  10032. //删除原来的排班
  10033. err := service.SaveSchTwo(sch, sch_two)
  10034. //生成新的排班
  10035. if err == nil {
  10036. err2 := service.SaveSch(&new_sch)
  10037. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10038. if order.ID > 0 {
  10039. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10040. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10041. redis := service.RedisClient()
  10042. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10043. redis.Set(key, "", time.Second)
  10044. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10045. //清空key 值
  10046. redis.Set(keyOne, "", time.Second)
  10047. }
  10048. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10049. if orderOne.ID > 0 {
  10050. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10051. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10052. redis := service.RedisClient()
  10053. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10054. redis.Set(key, "", time.Second)
  10055. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10056. //清空key 值
  10057. redis.Set(keyOne, "", time.Second)
  10058. }
  10059. if err2 == nil {
  10060. //去除当天患者排班中重复数据,保留最后一条数据
  10061. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10062. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10063. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  10064. c.ServeSuccessJSON(map[string]interface{}{
  10065. "msg": "覆盖成功",
  10066. "new_sch": new_sch,
  10067. })
  10068. } else {
  10069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10070. return
  10071. }
  10072. } else {
  10073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10074. return
  10075. }
  10076. }
  10077. func (c *DialysisAPIController) BatchCheckAdvice() {
  10078. patient_id, _ := c.GetInt64("patient_id")
  10079. advice_date, _ := c.GetInt64("advice_date")
  10080. org_id := c.GetMobileAdminUserInfo().Org.Id
  10081. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  10082. //查询是his系统还是血透系统
  10083. _, configs := service.FindXTHisRecordByOrgId(org_id)
  10084. //his客户
  10085. if configs.IsOpen == 1 {
  10086. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  10087. for _, item := range adviceList {
  10088. service.BatchCheckHisAdvice(item.ID, creater)
  10089. }
  10090. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10091. for _, item := range projectList {
  10092. service.BatchCheckProject(item.ID, creater)
  10093. }
  10094. c.ServeSuccessJSON(map[string]interface{}{
  10095. "adviceList": adviceList,
  10096. "projectList": projectList,
  10097. })
  10098. }
  10099. if configs.IsOpen != 1 {
  10100. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  10101. for _, item := range adviceList {
  10102. service.BatchAdviceList(item.ID, creater)
  10103. }
  10104. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10105. for _, item := range projectList {
  10106. service.BatchCheckProject(item.ID, creater)
  10107. }
  10108. c.ServeSuccessJSON(map[string]interface{}{
  10109. "adviceList": adviceList,
  10110. "projectList": projectList,
  10111. })
  10112. }
  10113. return
  10114. }
  10115. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10116. org_id := c.GetMobileAdminUserInfo().Org.Id
  10117. drugList, _ := service.GetAllDrugList(org_id)
  10118. c.ServeSuccessJSON(map[string]interface{}{
  10119. "drugList": drugList,
  10120. })
  10121. }
  10122. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10123. org_id := c.GetMobileAdminUserInfo().Org.Id
  10124. dataBody := make(map[string]interface{}, 0)
  10125. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10126. if err != nil {
  10127. utils.ErrorLog(err.Error())
  10128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10129. return
  10130. }
  10131. timeLayout := "2006-01-02"
  10132. loc, _ := time.LoadLocation("Local")
  10133. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10134. utils.ErrorLog("advice_type")
  10135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10136. return
  10137. }
  10138. adviceType := int64(dataBody["advice_type"].(float64))
  10139. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10140. utils.ErrorLog("start_time")
  10141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10142. return
  10143. }
  10144. startTime2, _ := dataBody["start_time"].(string)
  10145. time_arr := strings.Split(startTime2, " ")
  10146. if len(time_arr) > 0 {
  10147. startTime2 = time_arr[0]
  10148. }
  10149. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10150. utils.ErrorLog("advice_date")
  10151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10152. return
  10153. }
  10154. advice_date, _ := dataBody["advice_date"].(string)
  10155. var advicedateunix int64
  10156. if len(advice_date) > 0 {
  10157. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10158. if err != nil {
  10159. fmt.Println(err)
  10160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10161. return
  10162. }
  10163. advicedateunix = theTime.Unix()
  10164. }
  10165. adviceDate := startTime2
  10166. if len(adviceDate) == 0 {
  10167. utils.ErrorLog("len(adviceDate) == 0")
  10168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10169. return
  10170. }
  10171. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10172. if err != nil {
  10173. utils.ErrorLog(err.Error())
  10174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10175. return
  10176. }
  10177. AdviceDate := advicedateunix
  10178. RecordDate := advicedateunix
  10179. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10180. utils.ErrorLog("start_time")
  10181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10182. return
  10183. }
  10184. startTime, _ := dataBody["start_time"].(string)
  10185. if len(startTime) == 0 {
  10186. utils.ErrorLog("len(start_time) == 0")
  10187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10188. return
  10189. }
  10190. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10191. if err != nil {
  10192. utils.ErrorLog(err.Error())
  10193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10194. return
  10195. }
  10196. StartTime := theTime.Unix()
  10197. advice_name, _ := dataBody["advice_name"].(string)
  10198. advice_desc, _ := dataBody["advice_desc"].(string)
  10199. delivery_way, _ := dataBody["delivery_way"].(string)
  10200. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10201. frequency_type := int64(dataBody["frequency_type"].(float64))
  10202. frequency_week, _ := dataBody["frequency_week"].(string)
  10203. prescribing_number := dataBody["prescribing_number"].(float64)
  10204. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10205. remark := dataBody["remark"].(string)
  10206. single_dose := dataBody["single_dose"].(float64)
  10207. single_dose_unit := dataBody["single_dose_unit"].(string)
  10208. patient_id := int64(dataBody["patient_id"].(float64))
  10209. day_count := int64(dataBody["day_count"].(float64))
  10210. groupNo := int64(dataBody["group_no"].(float64))
  10211. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10212. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10213. if groupNo <= 0 {
  10214. group := service.GetMaxAdviceGroupID(org_id)
  10215. groupNo = group + 1
  10216. }
  10217. var template_id = ""
  10218. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10219. template_id = "M" + adviceLastId
  10220. advice := models.DoctorAdvice{
  10221. UserOrgId: org_id,
  10222. PatientId: patient_id,
  10223. AdviceType: adviceType,
  10224. AdviceDate: AdviceDate,
  10225. StartTime: StartTime,
  10226. AdviceName: advice_name,
  10227. AdviceDesc: advice_desc,
  10228. ReminderDate: 0,
  10229. SingleDose: single_dose,
  10230. SingleDoseUnit: single_dose_unit,
  10231. DrugSpec: 0,
  10232. DrugSpecUnit: "",
  10233. PrescribingNumber: prescribing_number,
  10234. PrescribingNumberUnit: prescribing_number_unit,
  10235. DeliveryWay: delivery_way,
  10236. ExecutionFrequency: execution_frequency,
  10237. AdviceDoctor: advice_doctor,
  10238. Status: 1,
  10239. CreatedTime: time.Now().Unix(),
  10240. UpdatedTime: 0,
  10241. AdviceAffirm: "",
  10242. Remark: remark,
  10243. StopTime: 0,
  10244. StopReason: "",
  10245. StopDoctor: 0,
  10246. StopState: 0,
  10247. ParentId: 0,
  10248. ExecutionTime: 0,
  10249. ExecutionStaff: 0,
  10250. ExecutionState: 0,
  10251. Checker: 0,
  10252. RecordDate: RecordDate,
  10253. DialysisOrderId: 0,
  10254. CheckTime: 0,
  10255. CheckState: 0,
  10256. AdviceId: 0,
  10257. RemindType: 0,
  10258. FrequencyType: frequency_type,
  10259. DayCount: day_count,
  10260. WeekDay: frequency_week,
  10261. ChildDoctorAdvice: nil,
  10262. TemplateId: template_id,
  10263. Modifier: 0,
  10264. IsCheck: 0,
  10265. Way: 0,
  10266. DrugId: 0,
  10267. DrugNameId: 0,
  10268. IsMedicine: 0,
  10269. PushStartTime: 0,
  10270. IsSettle: 0,
  10271. IsPrescription: 0,
  10272. GroupNo: groupNo,
  10273. }
  10274. service.CreateMobileAdivce(advice)
  10275. c.ServeSuccessJSON(map[string]interface{}{
  10276. "msg": "保存成功!",
  10277. })
  10278. }
  10279. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10280. patient_id, _ := c.GetInt64("patient_id")
  10281. org_id := c.GetMobileAdminUserInfo().Org.Id
  10282. app_id := c.GetMobileAdminUserInfo().App.Id
  10283. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10284. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10285. c.ServeSuccessJSON(map[string]interface{}{
  10286. "adviceList": adviceList,
  10287. "adminRoles": adminRoles,
  10288. })
  10289. }
  10290. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10291. org_id := c.GetMobileAdminUserInfo().Org.Id
  10292. dataBody := make(map[string]interface{}, 0)
  10293. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10294. if err != nil {
  10295. utils.ErrorLog(err.Error())
  10296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10297. return
  10298. }
  10299. timeLayout := "2006-01-02"
  10300. loc, _ := time.LoadLocation("Local")
  10301. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10302. utils.ErrorLog("start_time")
  10303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10304. return
  10305. }
  10306. startTime2, _ := dataBody["start_time"].(string)
  10307. time_arr := strings.Split(startTime2, " ")
  10308. if len(time_arr) > 0 {
  10309. startTime2 = time_arr[0]
  10310. }
  10311. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10312. utils.ErrorLog("advice_date")
  10313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10314. return
  10315. }
  10316. advice_date, _ := dataBody["advice_date"].(string)
  10317. var advicedateunix int64
  10318. if len(advice_date) > 0 {
  10319. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10320. if err != nil {
  10321. fmt.Println(err)
  10322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10323. return
  10324. }
  10325. advicedateunix = theTime.Unix()
  10326. }
  10327. adviceDate := startTime2
  10328. if len(adviceDate) == 0 {
  10329. utils.ErrorLog("len(adviceDate) == 0")
  10330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10331. return
  10332. }
  10333. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10334. if err != nil {
  10335. utils.ErrorLog(err.Error())
  10336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10337. return
  10338. }
  10339. AdviceDate := advicedateunix
  10340. RecordDate := advicedateunix
  10341. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10342. utils.ErrorLog("start_time")
  10343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10344. return
  10345. }
  10346. startTime, _ := dataBody["start_time"].(string)
  10347. if len(startTime) == 0 {
  10348. utils.ErrorLog("len(start_time) == 0")
  10349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10350. return
  10351. }
  10352. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10353. if err != nil {
  10354. utils.ErrorLog(err.Error())
  10355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10356. return
  10357. }
  10358. StartTime := theTime.Unix()
  10359. advice_name, _ := dataBody["advice_name"].(string)
  10360. advice_desc, _ := dataBody["advice_desc"].(string)
  10361. delivery_way, _ := dataBody["delivery_way"].(string)
  10362. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10363. prescribing_number := dataBody["prescribing_number"].(float64)
  10364. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10365. remark := dataBody["remark"].(string)
  10366. single_dose := dataBody["single_dose"].(float64)
  10367. single_dose_unit := dataBody["single_dose_unit"].(string)
  10368. patient_id := int64(dataBody["patient_id"].(float64))
  10369. groupNo := int64(dataBody["group_no"].(float64))
  10370. parent_id := int64(dataBody["parent_id"].(float64))
  10371. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10372. advice := models.XtDoctorAdviceOne{
  10373. UserOrgId: org_id,
  10374. PatientId: patient_id,
  10375. AdviceType: 1,
  10376. AdviceDate: AdviceDate,
  10377. StartTime: StartTime,
  10378. AdviceName: advice_name,
  10379. AdviceDesc: advice_desc,
  10380. ReminderDate: 0,
  10381. SingleDose: single_dose,
  10382. SingleDoseUnit: single_dose_unit,
  10383. PrescribingNumber: prescribing_number,
  10384. PrescribingNumberUnit: prescribing_number_unit,
  10385. DeliveryWay: delivery_way,
  10386. ExecutionFrequency: execution_frequency,
  10387. AdviceDoctor: advice_doctor,
  10388. Status: 1,
  10389. CreatedTime: time.Now().Unix(),
  10390. UpdatedTime: time.Now().Unix(),
  10391. AdviceAffirm: "",
  10392. Remark: remark,
  10393. StopTime: 0,
  10394. StopReason: "",
  10395. StopDoctor: 0,
  10396. StopState: 0,
  10397. ParentId: parent_id,
  10398. ExecutionTime: 0,
  10399. ExecutionStaff: 0,
  10400. ExecutionState: 0,
  10401. Checker: 0,
  10402. RecordDate: RecordDate,
  10403. DialysisOrderId: 0,
  10404. CheckTime: 0,
  10405. CheckState: 0,
  10406. DrugSpec: 0,
  10407. DrugSpecUnit: "",
  10408. Groupno: groupNo,
  10409. RemindType: 0,
  10410. FrequencyType: 0,
  10411. DayCount: 0,
  10412. WeekDay: "",
  10413. TemplateId: "",
  10414. Modifier: 0,
  10415. }
  10416. service.CreateMobileAdivceOne(advice)
  10417. c.ServeSuccessJSON(map[string]interface{}{
  10418. "msg": "保存成功!",
  10419. })
  10420. }
  10421. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10422. id, _ := c.GetInt64("id")
  10423. service.DeleteSelfAdviceSubAdvice(id)
  10424. c.ServeSuccessJSON(map[string]interface{}{
  10425. "msg": "保存成功!",
  10426. })
  10427. }
  10428. func (c *DialysisAPIController) GetEditAdviceAction() {
  10429. id, _ := c.GetInt64("id")
  10430. org_id := c.GetMobileAdminUserInfo().Org.Id
  10431. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10432. drugList, _ := service.GetAllDrugList(org_id)
  10433. c.ServeSuccessJSON(map[string]interface{}{
  10434. "advice": advice,
  10435. "drugList": drugList,
  10436. })
  10437. }
  10438. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10439. dataBody := make(map[string]interface{}, 0)
  10440. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10441. if err != nil {
  10442. utils.ErrorLog(err.Error())
  10443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10444. return
  10445. }
  10446. timeLayout := "2006-01-02"
  10447. loc, _ := time.LoadLocation("Local")
  10448. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10449. utils.ErrorLog("start_time")
  10450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10451. return
  10452. }
  10453. startTime2, _ := dataBody["start_time"].(string)
  10454. time_arr := strings.Split(startTime2, " ")
  10455. if len(time_arr) > 0 {
  10456. startTime2 = time_arr[0]
  10457. }
  10458. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10459. utils.ErrorLog("advice_date")
  10460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10461. return
  10462. }
  10463. advice_date, _ := dataBody["advice_date"].(string)
  10464. var advicedateunix int64
  10465. if len(advice_date) > 0 {
  10466. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10467. if err != nil {
  10468. fmt.Println(err)
  10469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10470. return
  10471. }
  10472. advicedateunix = theTime.Unix()
  10473. }
  10474. adviceDate := startTime2
  10475. if len(adviceDate) == 0 {
  10476. utils.ErrorLog("len(adviceDate) == 0")
  10477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10478. return
  10479. }
  10480. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10481. if err != nil {
  10482. utils.ErrorLog(err.Error())
  10483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10484. return
  10485. }
  10486. AdviceDate := advicedateunix
  10487. RecordDate := advicedateunix
  10488. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10489. utils.ErrorLog("start_time")
  10490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10491. return
  10492. }
  10493. startTime, _ := dataBody["start_time"].(string)
  10494. if len(startTime) == 0 {
  10495. utils.ErrorLog("len(start_time) == 0")
  10496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10497. return
  10498. }
  10499. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10500. if err != nil {
  10501. utils.ErrorLog(err.Error())
  10502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10503. return
  10504. }
  10505. StartTime := theTime.Unix()
  10506. advice_name, _ := dataBody["advice_name"].(string)
  10507. advice_desc, _ := dataBody["advice_desc"].(string)
  10508. delivery_way, _ := dataBody["delivery_way"].(string)
  10509. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10510. prescribing_number := dataBody["prescribing_number"].(float64)
  10511. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10512. remark := dataBody["remark"].(string)
  10513. single_dose := dataBody["single_dose"].(float64)
  10514. single_dose_unit := dataBody["single_dose_unit"].(string)
  10515. id := int64(dataBody["id"].(float64))
  10516. frequency_type := int64(dataBody["frequency_type"].(float64))
  10517. frequency_week, _ := dataBody["frequency_week"].(string)
  10518. day_count := int64(dataBody["day_count"].(float64))
  10519. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10520. advice := models.XtDoctorAdviceOne{
  10521. AdviceDate: AdviceDate,
  10522. StartTime: StartTime,
  10523. AdviceName: advice_name,
  10524. AdviceDesc: advice_desc,
  10525. SingleDose: single_dose,
  10526. SingleDoseUnit: single_dose_unit,
  10527. PrescribingNumber: prescribing_number,
  10528. PrescribingNumberUnit: prescribing_number_unit,
  10529. DeliveryWay: delivery_way,
  10530. ExecutionFrequency: execution_frequency,
  10531. AdviceDoctor: advice_doctor,
  10532. Remark: remark,
  10533. RecordDate: RecordDate,
  10534. FrequencyType: frequency_type,
  10535. DayCount: day_count,
  10536. WeekDay: frequency_week,
  10537. }
  10538. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10539. c.ServeSuccessJSON(map[string]interface{}{
  10540. "advice": advice,
  10541. })
  10542. }
  10543. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10544. dataBody := make(map[string]interface{}, 0)
  10545. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10546. if err != nil {
  10547. utils.ErrorLog(err.Error())
  10548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10549. return
  10550. }
  10551. timeLayout := "2006-01-02"
  10552. loc, _ := time.LoadLocation("Local")
  10553. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10554. utils.ErrorLog("start_time")
  10555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10556. return
  10557. }
  10558. startTime2, _ := dataBody["start_time"].(string)
  10559. time_arr := strings.Split(startTime2, " ")
  10560. if len(time_arr) > 0 {
  10561. startTime2 = time_arr[0]
  10562. }
  10563. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10564. utils.ErrorLog("advice_date")
  10565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10566. return
  10567. }
  10568. advice_date, _ := dataBody["advice_date"].(string)
  10569. var advicedateunix int64
  10570. if len(advice_date) > 0 {
  10571. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10572. if err != nil {
  10573. fmt.Println(err)
  10574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10575. return
  10576. }
  10577. advicedateunix = theTime.Unix()
  10578. }
  10579. adviceDate := startTime2
  10580. if len(adviceDate) == 0 {
  10581. utils.ErrorLog("len(adviceDate) == 0")
  10582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10583. return
  10584. }
  10585. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10586. if err != nil {
  10587. utils.ErrorLog(err.Error())
  10588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10589. return
  10590. }
  10591. AdviceDate := advicedateunix
  10592. RecordDate := advicedateunix
  10593. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10594. utils.ErrorLog("start_time")
  10595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10596. return
  10597. }
  10598. startTime, _ := dataBody["start_time"].(string)
  10599. if len(startTime) == 0 {
  10600. utils.ErrorLog("len(start_time) == 0")
  10601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10602. return
  10603. }
  10604. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10605. if err != nil {
  10606. utils.ErrorLog(err.Error())
  10607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10608. return
  10609. }
  10610. StartTime := theTime.Unix()
  10611. advice_name, _ := dataBody["advice_name"].(string)
  10612. advice_desc, _ := dataBody["advice_desc"].(string)
  10613. delivery_way, _ := dataBody["delivery_way"].(string)
  10614. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10615. prescribing_number := dataBody["prescribing_number"].(float64)
  10616. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10617. remark := dataBody["remark"].(string)
  10618. single_dose := dataBody["single_dose"].(float64)
  10619. single_dose_unit := dataBody["single_dose_unit"].(string)
  10620. id := int64(dataBody["id"].(float64))
  10621. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10622. advice := models.XtDoctorAdviceOne{
  10623. AdviceDate: AdviceDate,
  10624. StartTime: StartTime,
  10625. AdviceName: advice_name,
  10626. AdviceDesc: advice_desc,
  10627. SingleDose: single_dose,
  10628. SingleDoseUnit: single_dose_unit,
  10629. PrescribingNumber: prescribing_number,
  10630. PrescribingNumberUnit: prescribing_number_unit,
  10631. DeliveryWay: delivery_way,
  10632. ExecutionFrequency: execution_frequency,
  10633. AdviceDoctor: advice_doctor,
  10634. Remark: remark,
  10635. RecordDate: RecordDate,
  10636. }
  10637. service.UpdateMobileDoctorAdviceById(id, advice)
  10638. c.ServeSuccessJSON(map[string]interface{}{
  10639. "advice": advice,
  10640. })
  10641. }
  10642. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10643. dataBody := make(map[string]interface{}, 0)
  10644. timeLayout := "2006-01-02"
  10645. loc, _ := time.LoadLocation("Local")
  10646. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10647. if err != nil {
  10648. utils.ErrorLog(err.Error())
  10649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10650. return
  10651. }
  10652. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10653. utils.ErrorLog("start_time")
  10654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10655. return
  10656. }
  10657. startTime2, _ := dataBody["start_time"].(string)
  10658. time_arr := strings.Split(startTime2, " ")
  10659. if len(time_arr) > 0 {
  10660. startTime2 = time_arr[0]
  10661. }
  10662. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10663. utils.ErrorLog("advice_date")
  10664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10665. return
  10666. }
  10667. advice_date, _ := dataBody["advice_date"].(string)
  10668. var advicedateunix int64
  10669. if len(advice_date) > 0 {
  10670. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10671. if err != nil {
  10672. fmt.Println(err)
  10673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10674. return
  10675. }
  10676. advicedateunix = theTime.Unix()
  10677. }
  10678. adviceDate := startTime2
  10679. if len(adviceDate) == 0 {
  10680. utils.ErrorLog("len(adviceDate) == 0")
  10681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10682. return
  10683. }
  10684. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10685. if err != nil {
  10686. utils.ErrorLog(err.Error())
  10687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10688. return
  10689. }
  10690. RecordDate := advicedateunix
  10691. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10692. utils.ErrorLog("start_time")
  10693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10694. return
  10695. }
  10696. startTime, _ := dataBody["start_time"].(string)
  10697. if len(startTime) == 0 {
  10698. utils.ErrorLog("len(start_time) == 0")
  10699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10700. return
  10701. }
  10702. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10703. if err != nil {
  10704. utils.ErrorLog(err.Error())
  10705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10706. return
  10707. }
  10708. StartTime := theTime.Unix()
  10709. patient_id := int64(dataBody["patient_id"].(float64))
  10710. group_no := int64(dataBody["group_no"].(float64))
  10711. org_id := c.GetMobileAdminUserInfo().Org.Id
  10712. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10713. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10714. utils.ErrorLog("advices")
  10715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10716. return
  10717. }
  10718. adviceNames := dataBody["advices"].([]interface{})
  10719. var advices []*models.GroupAdvice
  10720. for _, adviceNameMap := range adviceNames {
  10721. var advice models.GroupAdvice
  10722. adviceNameM := adviceNameMap.(map[string]interface{})
  10723. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10724. utils.ErrorLog("advice_name")
  10725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10726. return
  10727. }
  10728. adviceName, _ := adviceNameM["advice_name"].(string)
  10729. if len(adviceName) == 0 {
  10730. utils.ErrorLog("len(advice_name) == 0")
  10731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10732. return
  10733. }
  10734. advice.AdviceName = adviceName
  10735. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10736. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10737. advice.DrugSpec = drugSpec
  10738. }
  10739. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10740. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10741. advice.AdviceDesc = adviceDesc
  10742. }
  10743. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10744. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10745. advice.DrugSpecUnit = drugSpecUnit
  10746. }
  10747. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10748. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10749. advice.SingleDose = singleDose
  10750. }
  10751. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10752. singleDose := adviceNameM["single_dose"].(float64)
  10753. advice.SingleDose = singleDose
  10754. }
  10755. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10756. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10757. advice.SingleDoseUnit = singleDoseUnit
  10758. }
  10759. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10760. tmp := adviceNameM["single_dose_unit"].(float64)
  10761. singleDoseUnit := service.TypeConversion(tmp)
  10762. advice.SingleDoseUnit = singleDoseUnit
  10763. }
  10764. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10765. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10766. advice.PrescribingNumber = prescribingNumber
  10767. }
  10768. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10769. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10770. advice.PrescribingNumber = prescribingNumber
  10771. }
  10772. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10773. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10774. advice.PrescribingNumberUnit = prescribingNumberUnit
  10775. }
  10776. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10777. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10778. advice.DeliveryWay = deliveryWay
  10779. }
  10780. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10781. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10782. advice.ExecutionFrequency = executionFrequency
  10783. }
  10784. remark, _ := adviceNameM["remark"].(string)
  10785. advice.Remark = remark
  10786. advice.AdviceType = 1
  10787. advice.StartTime = StartTime
  10788. advice.RecordDate = RecordDate
  10789. advice.PatientId = patient_id
  10790. advice.UserOrgId = org_id
  10791. advice.AdviceDoctor = advice_doctor
  10792. advices = append(advices, &advice)
  10793. }
  10794. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10795. c.ServeSuccessJSON(map[string]interface{}{
  10796. "advice": newAdvices,
  10797. })
  10798. }
  10799. func (c *DialysisAPIController) StopLongAdvice() {
  10800. stop_time := c.GetString("execution_time")
  10801. id, _ := c.GetInt64("id")
  10802. if len(stop_time) <= 0 {
  10803. utils.ErrorLog("stop_time")
  10804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10805. return
  10806. }
  10807. timeLayout2 := "2006-01-02 15:04:05"
  10808. loc, _ := time.LoadLocation("Local")
  10809. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  10810. if errs != nil {
  10811. utils.ErrorLog(errs.Error())
  10812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10813. return
  10814. }
  10815. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  10816. c.ServeSuccessJSON(map[string]interface{}{
  10817. "advice": advice,
  10818. })
  10819. }