dialysis_api_controller.go 428KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041
  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. fmt.Print("projectOne------------------------", projectsOne)
  468. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  469. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  470. var team_projects []*models.HisPrescriptionProject
  471. //var index int64 = 0
  472. for _, item := range temp_team_projects {
  473. //组套里面非检验项目的
  474. if item.HisProject.CostClassify != 3 {
  475. projects = append(projects, item)
  476. }
  477. //组套里面检验项目的
  478. if item.HisProject.CostClassify == 3 {
  479. team_projects = append(team_projects, item)
  480. }
  481. }
  482. //针对茂名舒和
  483. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  484. if len(projects) > 0 {
  485. for _, item := range projects {
  486. if item.Type == 2 {
  487. if item.HisProject.IsShow == 1 {
  488. projectsOne = append(projectsOne, item)
  489. }
  490. }
  491. if item.Type == 3 {
  492. if item.GoodInfo.IsShow == 1 {
  493. projectsOne = append(projectsOne, item)
  494. }
  495. }
  496. }
  497. }
  498. } else {
  499. for _, item := range projects {
  500. projectsOne = append(projectsOne, item)
  501. }
  502. }
  503. team_projects = RemoveRepeatedCheckRecod(team_projects)
  504. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  505. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  506. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  507. var his_advices []*models.HisDoctorAdviceInfo
  508. var his_advices_one []*models.HisDoctorAdviceInfo
  509. if is_open_config.IsOpen == 1 {
  510. // 先走redis,没有走数据库
  511. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  512. }
  513. //针对茂名舒和
  514. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  515. if len(his_advices) > 0 {
  516. for _, item := range his_advices {
  517. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  518. if drug.IsShow == 1 {
  519. his_advices_one = append(his_advices_one, item)
  520. }
  521. }
  522. }
  523. } else {
  524. if len(his_advices) > 0 {
  525. for _, item := range his_advices {
  526. his_advices_one = append(his_advices_one, item)
  527. }
  528. }
  529. }
  530. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  531. if is_advice_open.IsAdviceOpen == 1 {
  532. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  533. }
  534. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  535. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  536. var remind_lists []models.XtCheckRemind
  537. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  538. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  539. }
  540. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  541. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  542. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  543. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  544. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  545. returnData := map[string]interface{}{
  546. "patient": patient,
  547. "schedual": schedual,
  548. "prescription": dialysisPrescribe,
  549. "solution": dialysisSolution,
  550. "last_prescription": lastDialysisPrescribe,
  551. "receiver_treatment_access": receiverTreatmentAccess,
  552. "predialysis_evaluation": predialysisEvaluation,
  553. "doctor_advices": doctorAdvices,
  554. "double_check": doubleCheck,
  555. "assessment_after_dislysis": assessmentAfterDislysis,
  556. "treatment_summary": treatmentSummary,
  557. "monitor_records": monitorRecords,
  558. "dialysis_order": dialysisOrder,
  559. "operators": operators,
  560. "last_predialysis_evaluation": lastPredialysisEvaluation,
  561. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  562. "last_monitor_record": lastMonitorRecord,
  563. "config": gobalConfig,
  564. "dry_weight": lastDryWeightDislysis,
  565. "system_prescription": systemDialysisPrescribe,
  566. "his_advices": his_advices_one,
  567. "is_open_config": is_open_config,
  568. "stockType": stockType,
  569. "prepare": prepare,
  570. "lastAssessment": lastAssessment,
  571. "prescribeOne": prescribeOne,
  572. "is_project_open_config": is_project_open_config,
  573. "project": projectsOne,
  574. "team_projects": team_projects,
  575. "is_advice_open": is_advice_open,
  576. "prescription_open": prescriptionConfig.IsOpen,
  577. "lastOrder": lastOrder,
  578. "remind_lists": remind_lists,
  579. "lastDialysisPrescription": lastDialysisPrescription,
  580. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  581. "dryWeightList": dryWeightList,
  582. "firstMonitor": firstMonitor,
  583. "lastMonitor": lastMonitor,
  584. }
  585. this.ServeSuccessJSON(returnData)
  586. }
  587. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  588. adminInfo := c.GetMobileAdminUserInfo()
  589. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  590. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  591. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  592. returnData := map[string]interface{}{
  593. "admin_users": adminUsers,
  594. "devices": devices,
  595. "device_numbers": device_numbers,
  596. }
  597. c.ServeSuccessJSON(returnData)
  598. }
  599. func (c *DialysisAPIController) PostAtreatmentInfo() {
  600. id, _ := c.GetInt64("patient", 0)
  601. recordDateStr := c.GetString("record_date")
  602. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  603. summaryContent := c.GetString("summaryContent")
  604. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  605. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  606. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  607. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  608. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  609. nursingRecord := c.GetString("nursing_record")
  610. fmt.Println("护理记录", nursingRecord)
  611. specialRecord := c.GetString("special_record")
  612. fmt.Println("特殊记录", specialRecord)
  613. adminUserInfo := c.GetMobileAdminUserInfo()
  614. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  615. checkStaffId = adminUserInfo.AdminUser.Id
  616. deboardNurseId = adminUserInfo.AdminUser.Id
  617. treatDoctor = adminUserInfo.AdminUser.Id
  618. if id <= 0 {
  619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  620. return
  621. }
  622. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  623. if patient.ID == 0 {
  624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  625. return
  626. }
  627. if len(recordDateStr) == 0 {
  628. recordDateStr = time.Now().Format("2006-01-02")
  629. }
  630. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  631. if parseDateErr != nil {
  632. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  634. return
  635. }
  636. summary := models.TreatmentSummary{
  637. UserOrgId: adminUserInfo.Org.Id,
  638. PatientId: id,
  639. AssessmentDate: recordDate.Unix(),
  640. Mission: propagandaAndEducationContent,
  641. DialysisSummary: summaryContent,
  642. SjNurse: changeMedicalNurseId,
  643. ZlNurse: treatNurseId,
  644. HdNurse: checkStaffId,
  645. XjNurse: deboardNurseId,
  646. ZlDoctor: treatDoctor,
  647. CreatedTime: time.Now().Unix(),
  648. Status: 1,
  649. NursingRecord: nursingRecord,
  650. SpecialRecord: specialRecord,
  651. }
  652. // 查询信息规挡的设置天数
  653. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  654. if infor.ID > 0 && infor.WeekDay > 0 {
  655. var cha_time int64
  656. timeNowStr := time.Now().Format("2006-01-02")
  657. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  658. //今日的日期减去设置的日期
  659. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  660. if cha_time >= recordDate.Unix() {
  661. //查询审核是否允许
  662. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  663. //申请状态不允许的情况 拒绝修改
  664. if infor.ApplicationStatus != 1 {
  665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  666. return
  667. }
  668. }
  669. }
  670. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  671. if treatmentSummary.ID == 0 { //新增
  672. summary.Creater = adminUserInfo.AdminUser.Id
  673. service.AddSigleSummaryRecord(&summary)
  674. finish := models.XtDialysisFinish{
  675. IsFinish: 1,
  676. UserOrgId: adminUserInfo.Org.Id,
  677. Status: 1,
  678. Ctime: time.Now().Unix(),
  679. Mtime: 0,
  680. Module: 10,
  681. RecordDate: recordDate.Unix(),
  682. Sourse: 1,
  683. PatientId: id,
  684. }
  685. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  686. if dialysisFinish.ID == 0 {
  687. service.CreateDialysisFinish(finish)
  688. }
  689. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  690. redis := service.RedisClient()
  691. //清空key 值
  692. redis.Set(key, "", time.Second)
  693. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  694. redis.Set(keyOne, "", time.Second)
  695. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  696. redis.Set(keyThree, "", time.Second)
  697. defer redis.Close()
  698. c.ServeSuccessJSON(map[string]interface{}{
  699. "summary": summary,
  700. })
  701. } else { //修改
  702. summary.Creater = treatmentSummary.Creater
  703. summary.CreatedTime = treatmentSummary.CreatedTime
  704. summary.Modifier = adminUserInfo.AdminUser.Id
  705. summary.ID = treatmentSummary.ID
  706. service.UpdateSummeRecord(&summary)
  707. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  708. redis := service.RedisClient()
  709. //清空key 值
  710. redis.Set(key, "", time.Second)
  711. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  712. redis.Set(keyOne, "", time.Second)
  713. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  714. redis.Set(keyThree, "", time.Second)
  715. defer redis.Close()
  716. c.ServeSuccessJSON(map[string]interface{}{
  717. "summary": summary,
  718. })
  719. }
  720. }
  721. func (c *DialysisAPIController) PostDoubleCheck() {
  722. id, _ := c.GetInt64("patient", 0)
  723. recordDateStr := c.GetString("record_date")
  724. checkTimeStr := c.GetString("check_time")
  725. firstCheckTimeStr := c.GetString("first_check_time")
  726. creater, _ := c.GetInt64("creater", 0)
  727. modifier, _ := c.GetInt64("modifier", 0)
  728. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  729. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  730. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  731. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  732. dialysis_item_desc := c.GetString("dialysis_item_desc")
  733. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  734. vascular_access_desc := c.GetString("vascular_access_desc")
  735. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  736. collator, _ := c.GetInt64("collator", 0)
  737. employee_number := c.GetString("employee_number")
  738. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  739. needle_batch_number := c.GetString("needle_batch_number")
  740. if id <= 0 {
  741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  742. return
  743. }
  744. adminUserInfo := c.GetMobileAdminUserInfo()
  745. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  746. if patient.ID == 0 {
  747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  748. return
  749. }
  750. if len(recordDateStr) == 0 {
  751. recordDateStr = time.Now().Format("2006-01-02")
  752. }
  753. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  754. if parseDateErr != nil {
  755. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  757. return
  758. }
  759. var checkDate int64
  760. if len(checkTimeStr) == 0 {
  761. checkDate = 0
  762. } else {
  763. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  764. checkDate = checkDateUnix.Unix()
  765. }
  766. var firstCheckDate int64
  767. if len(firstCheckTimeStr) == 0 {
  768. firstCheckDate = 0
  769. } else {
  770. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  771. firstCheckDate = firstCheckDateUnix.Unix()
  772. }
  773. if adminUserInfo.Org.Id == 10644 {
  774. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  775. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  776. if check.ID == 0 {
  777. if employee_number != list.JobNumber {
  778. c.ServeSuccessJSON(map[string]interface{}{
  779. "doubleCheck": check,
  780. "msg": "2",
  781. })
  782. return
  783. }
  784. }
  785. if check.ID > 0 {
  786. if employee_number != list.JobNumber {
  787. c.ServeSuccessJSON(map[string]interface{}{
  788. "doubleCheck": check,
  789. "msg": "2",
  790. })
  791. return
  792. }
  793. }
  794. }
  795. doubleCheck := models.DoubleCheck{
  796. UserOrgId: adminUserInfo.Org.Id,
  797. PatientId: id,
  798. DialysisItemCheck: dialysis_item_check,
  799. DialysisParameterCheck: dialysis_parameter_check,
  800. VascularAccessVerification: vascular_access_verification,
  801. PipelineConnectionCheck: pipeline_connection_check,
  802. DialysisItemDesc: dialysis_item_desc,
  803. DialysisParameterDesc: dialysis_parameter_desc,
  804. VascularAccessDesc: vascular_access_desc,
  805. PipelineConnectionDesc: pipeline_connection_desc,
  806. Collator: collator,
  807. Status: 1,
  808. CreatedTime: time.Now().Unix(),
  809. CheckDate: recordDate.Unix(),
  810. UpdatedTime: time.Now().Unix(),
  811. EmployeeNumber: employee_number,
  812. DialyzerBatchNumber: dialyzer_batch_number,
  813. NeedleBatchNumber: needle_batch_number,
  814. }
  815. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  816. if check.ID == 0 { //新增
  817. doubleCheck.FirstCheckTime = firstCheckDate
  818. doubleCheck.CheckTime = checkDate
  819. doubleCheck.Creater = creater
  820. doubleCheck.Modifier = modifier
  821. if adminUserInfo.Org.Id == 10340 {
  822. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  823. doubleCheck.Creater = order.StartNurse
  824. }
  825. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  826. //查询未核对的医嘱
  827. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  828. for _, advice := range doctorList {
  829. if advice.ExecutionStaff == modifier {
  830. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  831. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  832. return
  833. }
  834. }
  835. }
  836. // 查询信息规挡的设置天数
  837. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  838. if infor.ID > 0 && infor.WeekDay > 0 {
  839. var cha_time int64
  840. timeNowStr := time.Now().Format("2006-01-02")
  841. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  842. //今日的日期减去设置的日期
  843. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  844. if cha_time >= recordDate.Unix() {
  845. //查询审核是否允许
  846. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  847. //申请状态不允许的情况 拒绝修改
  848. if infor.ApplicationStatus != 1 {
  849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  850. return
  851. }
  852. }
  853. }
  854. err := service.AddSigleDoubleCheck(&doubleCheck)
  855. finish := models.XtDialysisFinish{
  856. IsFinish: 1,
  857. UserOrgId: adminUserInfo.Org.Id,
  858. Status: 1,
  859. Ctime: time.Now().Unix(),
  860. Mtime: 0,
  861. Module: 5,
  862. RecordDate: recordDate.Unix(),
  863. Sourse: 1,
  864. PatientId: id,
  865. }
  866. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  867. if dialysisFinish.ID == 0 {
  868. service.CreateDialysisFinish(finish)
  869. }
  870. //针对长沙南雅
  871. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  872. //查询未核对的医嘱
  873. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  874. if len(doctorList) > 0 && modifier > 0 {
  875. for _, advice := range doctorList {
  876. service.UpdateDoctorAdviceList(advice.ID, modifier)
  877. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  878. redis := service.RedisClient()
  879. //清空key 值
  880. redis.Set(key, "", time.Second)
  881. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  882. redis.Set(keyTwo, "", time.Second)
  883. theTime := time.Now()
  884. recordDate := theTime.Format("2006-01-02")
  885. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  886. redis.Set(keyFour, "", time.Second)
  887. defer redis.Close()
  888. }
  889. }
  890. }
  891. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  892. redis := service.RedisClient()
  893. //清空key 值
  894. redis.Set(key, "", time.Second)
  895. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  896. redis.Set(keyOne, "", time.Second)
  897. defer redis.Close()
  898. if err == nil {
  899. c.ServeSuccessJSON(map[string]interface{}{
  900. "doubleCheck": &doubleCheck,
  901. })
  902. }
  903. } else { //修改
  904. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  905. if infor.ID > 0 {
  906. var cha_time int64
  907. timeNowStr := time.Now().Format("2006-01-02")
  908. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  909. //今日的日期减去设置的日期
  910. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  911. if cha_time >= recordDate.Unix() {
  912. //查询审核是否允许
  913. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  914. //申请状态不允许的情况 拒绝修改
  915. if infor.ApplicationStatus != 1 {
  916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  917. return
  918. }
  919. }
  920. }
  921. doubleCheck.FirstCheckTime = firstCheckDate
  922. doubleCheck.CheckTime = checkDate
  923. doubleCheck.Creater = creater
  924. doubleCheck.Modifier = modifier
  925. doubleCheck.CreatedTime = check.CreatedTime
  926. doubleCheck.ID = check.ID
  927. doubleCheck.EmployeeNumber = employee_number
  928. doubleCheck.NeedleBatchNumber = needle_batch_number
  929. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  930. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  931. //查询未核对的医嘱
  932. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  933. for _, advice := range doctorList {
  934. if advice.ExecutionStaff == modifier {
  935. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  936. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  937. return
  938. }
  939. }
  940. }
  941. err := service.UpdateDoubleCheck(&doubleCheck)
  942. //针对长沙南雅
  943. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  944. //查询未核对的医嘱
  945. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  946. if len(doctorList) > 0 && modifier > 0 {
  947. for _, advice := range doctorList {
  948. service.UpdateDoctorAdviceList(advice.ID, modifier)
  949. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  950. redis := service.RedisClient()
  951. //清空key 值
  952. redis.Set(key, "", time.Second)
  953. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  954. redis.Set(keyTwo, "", time.Second)
  955. theTime := time.Now()
  956. recordDate := theTime.Format("2006-01-02")
  957. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  958. redis.Set(keyFour, "", time.Second)
  959. defer redis.Close()
  960. }
  961. }
  962. }
  963. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  964. redis := service.RedisClient()
  965. //清空key 值
  966. redis.Set(key, "", time.Second)
  967. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  968. redis.Set(keyOne, "", time.Second)
  969. defer redis.Close()
  970. if err == nil {
  971. c.ServeSuccessJSON(map[string]interface{}{
  972. "doubleCheck": &doubleCheck,
  973. "msg": "1",
  974. })
  975. }
  976. }
  977. }
  978. func (c *DialysisAPIController) PostAcceptsAssessment() {
  979. id, _ := c.GetInt64("patient", 0)
  980. recordDateStr := c.GetString("record_date")
  981. way, _ := c.GetInt64("way", 0)
  982. consciousness, _ := c.GetInt64("consciousness", 0)
  983. appetite, _ := c.GetInt64("appetite", 0)
  984. condition, _ := c.GetInt64("condition", 0)
  985. posture, _ := c.GetInt64("posture")
  986. sick_condition, _ := c.GetInt64("sick_condition", 0)
  987. danger_level, _ := c.GetInt64("danger_level", 0)
  988. intake, _ := c.GetInt64("intake", 0)
  989. nutrition, _ := c.GetInt64("nutrition", 0)
  990. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  991. psychological_assessment_other := c.GetString("psychological_assessment_other")
  992. score := c.GetString("score")
  993. sick_condition_other := c.GetString("sick_condition_other")
  994. //precaution, _ := c.GetInt64("precaution", 0)
  995. precaution := c.GetString("precaution")
  996. precaution_other := c.GetString("precaution_other")
  997. psychological_other := c.GetString("psychological_other")
  998. admission_number := c.GetString("admission_number")
  999. tumble, _ := c.GetInt64("tumble")
  1000. diacrisis := c.GetString("diacrisis")
  1001. his_department := c.GetString("his_department")
  1002. his_bed := c.GetString("his_bed")
  1003. if id <= 0 {
  1004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1005. return
  1006. }
  1007. adminUserInfo := c.GetMobileAdminUserInfo()
  1008. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1009. if patient.ID == 0 {
  1010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1011. return
  1012. }
  1013. //now := time.Now()
  1014. //year, month, day := now.Date()
  1015. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1016. //todayTimeStamp := today_time.Unix()
  1017. if len(recordDateStr) == 0 {
  1018. recordDateStr = time.Now().Format("2006-01-02")
  1019. }
  1020. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1021. if parseDateErr != nil {
  1022. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1024. return
  1025. }
  1026. // 查询信息规挡的设置天数
  1027. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1028. if infor.ID > 0 && infor.WeekDay > 0 {
  1029. var cha_time int64
  1030. timeNowStr := time.Now().Format("2006-01-02")
  1031. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1032. //今日的日期减去设置的日期
  1033. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1034. if cha_time >= recordDate.Unix() {
  1035. //查询审核是否允许
  1036. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1037. //申请状态不允许的情况 拒绝修改
  1038. if infor.ApplicationStatus != 1 {
  1039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1040. return
  1041. }
  1042. }
  1043. }
  1044. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1045. if adminUserInfo.Org.Id == 10340 {
  1046. if condition == 1 {
  1047. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1048. if admission_number == "" {
  1049. admission_number = lastAcceptTreatment.AdmissionNumber
  1050. }
  1051. }
  1052. }
  1053. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1054. UserOrgId: adminUserInfo.Org.Id,
  1055. PatientId: id,
  1056. RecordDate: recordDate.Unix(),
  1057. Way: way,
  1058. Consciousness: consciousness,
  1059. Appetite: appetite,
  1060. Condition: condition,
  1061. SickCondition: sick_condition,
  1062. DangerLevel: danger_level,
  1063. Intake: intake,
  1064. Nutrition: nutrition,
  1065. PsychologicalAssessment: psychological_assessment,
  1066. PsychologicalAssessmentOther: psychological_assessment_other,
  1067. SickConditionOther: sick_condition_other,
  1068. Posture: posture,
  1069. CreatedTime: time.Now().Unix(),
  1070. UpdateTime: time.Now().Unix(),
  1071. Status: 1,
  1072. Score: score,
  1073. Precaution: precaution,
  1074. PrecautionOther: precaution_other,
  1075. PsychologicalOther: psychological_other,
  1076. AdmissionNumber: admission_number,
  1077. Tumble: tumble,
  1078. Diacrisis: diacrisis,
  1079. HisBed: his_bed,
  1080. HisDepartment: his_department,
  1081. }
  1082. if receiveTreatment.ID == 0 { //新增
  1083. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1084. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1085. finish := models.XtDialysisFinish{
  1086. IsFinish: 1,
  1087. UserOrgId: adminUserInfo.Org.Id,
  1088. Status: 1,
  1089. Ctime: time.Now().Unix(),
  1090. Mtime: 0,
  1091. Module: 2,
  1092. RecordDate: recordDate.Unix(),
  1093. Sourse: 1,
  1094. PatientId: id,
  1095. }
  1096. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1097. if dialysisFinish.ID == 0 {
  1098. service.CreateDialysisFinish(finish)
  1099. }
  1100. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1101. redis := service.RedisClient()
  1102. defer redis.Close()
  1103. //清空key 值
  1104. redis.Set(key, "", time.Second)
  1105. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1106. redis.Set(keyOne, "", time.Second)
  1107. if err == nil {
  1108. c.ServeSuccessJSON(map[string]interface{}{
  1109. "receiveTreatmentAsses": receiveTreatmentAsses,
  1110. })
  1111. }
  1112. } else { //修改
  1113. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1114. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1115. // if getPermissionErr != nil {
  1116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1117. // return
  1118. // } else if headNursePermission == nil {
  1119. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1120. // return
  1121. // }
  1122. //}
  1123. // 查询信息规挡的设置天数
  1124. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1125. if infor.ID > 0 && infor.WeekDay > 0 {
  1126. var cha_time int64
  1127. timeNowStr := time.Now().Format("2006-01-02")
  1128. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1129. //今日的日期减去设置的日期
  1130. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1131. if cha_time >= recordDate.Unix() {
  1132. //查询审核是否允许
  1133. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1134. //申请状态不允许的情况 拒绝修改
  1135. if infor.ApplicationStatus != 1 {
  1136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1137. return
  1138. }
  1139. }
  1140. }
  1141. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1142. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1143. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1144. receiveTreatmentAsses.ID = receiveTreatment.ID
  1145. if adminUserInfo.Org.Id == 10340 {
  1146. if condition == 1 {
  1147. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1148. if receiveTreatmentAsses.AdmissionNumber == "" {
  1149. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1150. }
  1151. }
  1152. }
  1153. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1154. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1155. redis := service.RedisClient()
  1156. defer redis.Close()
  1157. //清空key 值
  1158. redis.Set(key, "", time.Second)
  1159. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1160. redis.Set(keyOne, "", time.Second)
  1161. if err == nil {
  1162. c.ServeSuccessJSON(map[string]interface{}{
  1163. "receiveTreatmentAsses": receiveTreatmentAsses,
  1164. })
  1165. }
  1166. }
  1167. }
  1168. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1169. id, _ := c.GetInt64("patient", 0)
  1170. recordDateStr := c.GetString("record_date")
  1171. weightAfter, _ := c.GetFloat("weight_after", 0)
  1172. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1173. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1174. fmt.Println("weight_loss", weightReduce)
  1175. temperature, _ := c.GetFloat("temperature", 0)
  1176. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1177. breathing_rate := c.GetString("breathing_rate")
  1178. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1179. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1180. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1181. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1182. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1183. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1184. cruor := c.GetString("cruor")
  1185. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1186. internalFistula := c.GetString("internal_fistula")
  1187. catheter := c.GetString("catheter")
  1188. complications := c.GetString("complication")
  1189. remark := c.GetString("remark")
  1190. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1191. dialysis_intakes := c.GetString("dialysis_intakes")
  1192. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1193. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1194. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1195. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1196. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1197. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1198. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1199. patientGose, _ := c.GetInt64("patient_gose", 0)
  1200. inpatientDepartment := c.GetString("inpatient_department")
  1201. observationContent := c.GetString("observation_content")
  1202. observationContentOther := c.GetString("observation_content_other")
  1203. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1204. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1205. in_advance_reason := c.GetString("in_advance_reason")
  1206. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1207. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1208. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1209. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1210. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1211. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1212. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1213. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1214. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1215. is_eat, _ := c.GetInt64("is_eat", 0)
  1216. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1217. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1218. channels, _ := c.GetInt64("channel", 0)
  1219. return_blood, _ := c.GetInt64("return_blood", 0)
  1220. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1221. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1222. dialysis_during, _ := c.GetFloat("dialysis_during")
  1223. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1224. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1225. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1226. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1227. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1228. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1229. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1230. setting_pressure := c.GetString("setting_pressure")
  1231. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1232. diastolic_pressure := c.GetString("diastolic_pressure")
  1233. other_complication := c.GetString("other_complication")
  1234. ktv := c.GetString("ktv")
  1235. urr := c.GetString("urr")
  1236. hypertenison, _ := c.GetInt64("hypertenison")
  1237. hypopiesia, _ := c.GetInt64("hypopiesia")
  1238. leave_office_method, _ := c.GetInt64("leave_office_method")
  1239. lapse, _ := c.GetInt64("lapse")
  1240. consciousness, _ := c.GetInt64("consciousness")
  1241. fallrisk, _ := c.GetInt64("fallrisk")
  1242. machine_run := c.GetString("machine_run")
  1243. after_urea := c.GetString("after_urea")
  1244. pip_coagulation := c.GetString("pip_coagulation")
  1245. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1246. transfusion_volume := c.GetString("transfusion_volume")
  1247. last_after_weight := c.GetString("last_after_weight")
  1248. displace_liqui_value := c.GetString("displace_liqui_value")
  1249. if id <= 0 {
  1250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1251. return
  1252. }
  1253. adminUserInfo := c.GetMobileAdminUserInfo()
  1254. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1255. if patient.ID == 0 {
  1256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1257. return
  1258. }
  1259. if len(recordDateStr) == 0 {
  1260. recordDateStr = time.Now().Format("2006-01-02")
  1261. }
  1262. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1263. fmt.Println("parseDateErr", parseDateErr)
  1264. if parseDateErr != nil {
  1265. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1267. return
  1268. }
  1269. //now := time.Now()
  1270. //year, month, day := now.Date()
  1271. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1272. //todayTimeStamp := today_time.Unix()
  1273. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1274. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1275. UserOrgId: adminUserInfo.Org.Id,
  1276. PatientId: id,
  1277. AssessmentDate: recordDate.Unix(),
  1278. Temperature: temperature,
  1279. PulseFrequency: pulse_frequency,
  1280. BreathingRate: breathing_rate,
  1281. SystolicBloodPressure: systolic_blood_pressure,
  1282. DiastolicBloodPressure: diastolic_blood_pressure,
  1283. ActualUltrafiltration: actual_ultrafiltration,
  1284. ActualDisplacement: actual_displacement,
  1285. ActualTreatmentHour: actualtreatHour,
  1286. ActualTreatmentMinute: actualtreatmin,
  1287. WeightAfter: weightAfter,
  1288. AdditionalWeight: additionalWeight,
  1289. WeightLoss: weightReduce,
  1290. Cruor: cruor,
  1291. SymptomAfterDialysis: symptomsAfterDialysi,
  1292. InternalFistula: internalFistula,
  1293. Catheter: catheter,
  1294. Complication: complications,
  1295. DialysisIntakes: dialysateVolume,
  1296. CreatedTime: time.Now().Unix(),
  1297. UpdatedTime: time.Now().Unix(),
  1298. Status: 1,
  1299. Remark: remark,
  1300. BloodAccessPartId: blood_access_part_id,
  1301. BloodAccessPartOperaId: blood_access_part_opera_id,
  1302. DialysisIntakesUnit: dialysis_intakes_unit,
  1303. PuncturePointOozingBlood: puncturePointOozingBlood,
  1304. PuncturePointHaematoma: puncturePointHaematoma,
  1305. InternalFistulaTremorAc: internalFistulaTremorAc,
  1306. PatientGose: patientGose,
  1307. InpatientDepartment: inpatientDepartment,
  1308. ObservationContent: observationContent,
  1309. ObservationContentOther: observationContentOther,
  1310. DialysisProcess: dialysis_process,
  1311. InAdvanceMinute: in_advance_minute,
  1312. InAdvanceReason: in_advance_reason,
  1313. HemostasisMinute: hemostasis_minute,
  1314. HemostasisOpera: hemostasis_opera,
  1315. TremorNoise: tremor_noise,
  1316. DisequilibriumSyndrome: disequilibrium_syndrome,
  1317. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1318. ArterialTube: arterial_tube,
  1319. IntravenousTube: intravenous_tube,
  1320. Dialyzer: dialyzer,
  1321. InAdvanceReasonOther: in_advance_reason_other,
  1322. IsEat: is_eat,
  1323. CvcA: cvc_a,
  1324. CvcV: cvc_v,
  1325. Channel: channels,
  1326. ReturnBlood: return_blood,
  1327. RehydrationVolume: rehydration_volume,
  1328. DialysisDuring: dialysis_during,
  1329. StrokeVolume: stroke_volume,
  1330. BloodFlow: blood_flow,
  1331. SealingFluidDispose: sealing_fluid_dispose,
  1332. SealingFluidSpecial: sealing_fluid_special,
  1333. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1334. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1335. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1336. SettingPressure: setting_pressure,
  1337. DiastolicPressure: diastolic_pressure,
  1338. OtherComplication: other_complication,
  1339. Ktv: ktv,
  1340. Urr: urr,
  1341. Hypopiesia: hypopiesia,
  1342. Hypertenison: hypertenison,
  1343. Lapse: lapse,
  1344. LeaveOfficeMethod: leave_office_method,
  1345. Consciousness: consciousness,
  1346. Fallrisk: fallrisk,
  1347. MachineRun: machine_run,
  1348. AfterUrea: after_urea,
  1349. PipCoagulation: pip_coagulation,
  1350. AccumulatedBloodVolume: accumulated_blood_volume,
  1351. TransfusionVolume: transfusion_volume,
  1352. LastAfterWeight: last_after_weight,
  1353. DisplaceLiquiValue: displace_liqui_value,
  1354. }
  1355. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1356. // 查询信息规挡的设置天数
  1357. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1358. if infor.ID > 0 && infor.WeekDay > 0 {
  1359. var cha_time int64
  1360. timeNowStr := time.Now().Format("2006-01-02")
  1361. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1362. //今日的日期减去设置的日期
  1363. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1364. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1365. if cha_time >= recordDate.Unix() {
  1366. //查询审核是否允许
  1367. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1368. //申请状态不允许的情况 拒绝修改
  1369. if infor.ApplicationStatus != 1 {
  1370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1371. return
  1372. }
  1373. }
  1374. }
  1375. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1376. if assessmentAfter.ID == 0 { //新增
  1377. if appRole.UserType == 2 || appRole.UserType == 1 {
  1378. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1379. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1380. } else {
  1381. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1382. }
  1383. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1384. if assessmentAfterDislysis.UserOrgId != 10340 {
  1385. if assessmentAfterDislysis.WeightAfter == 0 {
  1386. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1387. }
  1388. }
  1389. if adminUserInfo.Org.Id == 10693 {
  1390. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1391. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1392. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1393. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1394. }
  1395. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1396. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1397. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1398. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1399. }
  1400. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1401. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1402. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1403. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1404. }
  1405. if assessmentAfterDislysis.PulseFrequency == 0 {
  1406. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1407. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1408. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1409. }
  1410. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1411. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1412. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1413. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1414. }
  1415. }
  1416. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1417. //记录日志
  1418. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1419. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1420. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1421. PatientId: assessmentAfterDislysis.PatientId,
  1422. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1423. Status: 1,
  1424. ErrLog: string(byterequest),
  1425. AdminUserId: adminUserInfo.AdminUser.Id,
  1426. Ctime: 0,
  1427. Mtime: 0,
  1428. Source: "手机端保存透后评估",
  1429. }
  1430. service.CreateAfterDialysisLog(afterDialysisLog)
  1431. finish := models.XtDialysisFinish{
  1432. IsFinish: 1,
  1433. UserOrgId: adminUserInfo.Org.Id,
  1434. Status: 1,
  1435. Ctime: time.Now().Unix(),
  1436. Mtime: 0,
  1437. Module: 9,
  1438. RecordDate: recordDate.Unix(),
  1439. Sourse: 1,
  1440. PatientId: id,
  1441. }
  1442. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1443. if dialysisFinish.ID == 0 {
  1444. service.CreateDialysisFinish(finish)
  1445. }
  1446. redis := service.RedisClient()
  1447. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1448. redis.Set(keyTwo, "", time.Second)
  1449. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1450. //清空key 值
  1451. redis.Set(key, "", time.Second)
  1452. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1453. redis.Set(keyOne, "", time.Second)
  1454. defer redis.Close()
  1455. if err == nil {
  1456. c.ServeSuccessJSON(map[string]interface{}{
  1457. "assessmentAfterDislysis": assessmentAfterDislysis,
  1458. })
  1459. }
  1460. return
  1461. } else { //修改
  1462. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1463. if infor.ID > 0 && infor.WeekDay > 0 {
  1464. var cha_time int64
  1465. timeNowStr := time.Now().Format("2006-01-02")
  1466. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1467. //今日的日期减去设置的日期
  1468. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1469. if cha_time >= recordDate.Unix() {
  1470. //查询审核是否允许
  1471. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1472. //申请状态不允许的情况 拒绝修改
  1473. if infor.ApplicationStatus != 1 {
  1474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1475. return
  1476. }
  1477. }
  1478. }
  1479. if appRole.UserType == 2 || appRole.UserType == 1 {
  1480. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1481. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1482. } else {
  1483. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1484. if assessmentAfterDislysis.Creater == 0 {
  1485. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1486. }
  1487. }
  1488. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1489. assessmentAfterDislysis.ID = assessmentAfter.ID
  1490. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1491. if assessmentAfterDislysis.UserOrgId != 10340 {
  1492. if assessmentAfterDislysis.WeightAfter == 0 {
  1493. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1494. }
  1495. }
  1496. if adminUserInfo.Org.Id == 10693 {
  1497. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1498. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1499. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1500. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1501. }
  1502. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1503. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1504. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1505. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1506. }
  1507. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1508. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1509. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1510. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1511. }
  1512. if assessmentAfterDislysis.PulseFrequency == 0 {
  1513. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1514. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1515. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1516. }
  1517. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1518. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1519. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1520. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1521. }
  1522. }
  1523. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1524. //记录日志
  1525. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1526. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1527. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1528. PatientId: assessmentAfterDislysis.PatientId,
  1529. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1530. Status: 1,
  1531. ErrLog: string(byterequest),
  1532. AdminUserId: adminUserInfo.AdminUser.Id,
  1533. Ctime: time.Now().Unix(),
  1534. Mtime: 0,
  1535. Source: "手机端修改保存透后评估",
  1536. }
  1537. service.CreateAfterDialysisLog(afterDialysisLog)
  1538. redis := service.RedisClient()
  1539. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1540. redis.Set(keyTwo, "", time.Second)
  1541. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1542. //清空key 值
  1543. redis.Set(key, "", time.Second)
  1544. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1545. redis.Set(keyOne, "", time.Second)
  1546. if err == nil {
  1547. c.ServeSuccessJSON(map[string]interface{}{
  1548. "assessmentAfterDislysis": assessmentAfterDislysis,
  1549. })
  1550. return
  1551. }
  1552. }
  1553. return
  1554. }
  1555. func (c *DialysisAPIController) PostDialysisPrescription() {
  1556. id, _ := c.GetInt64("patient", 0)
  1557. recordDateStr := c.GetString("record_date")
  1558. if id <= 0 {
  1559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1560. return
  1561. }
  1562. adminUserInfo := c.GetMobileAdminUserInfo()
  1563. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1564. if patient.ID == 0 {
  1565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1566. return
  1567. }
  1568. if len(recordDateStr) == 0 {
  1569. recordDateStr = time.Now().Format("2006-01-02")
  1570. }
  1571. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1572. if parseDateErr != nil {
  1573. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1575. return
  1576. }
  1577. mode_id, _ := c.GetInt64("mode_id", 0)
  1578. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1579. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1580. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1581. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1582. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1583. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1584. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1585. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1586. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1587. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1588. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1589. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1590. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1591. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1592. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1593. kalium, _ := c.GetFloat("kalium", 0)
  1594. sodium, _ := c.GetFloat("sodium", 0)
  1595. calcium, _ := c.GetFloat("calcium", 0)
  1596. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1597. glucose, _ := c.GetFloat("glucose", 0)
  1598. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1599. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1600. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1601. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1602. conductivity, _ := c.GetFloat("conductivity", 0)
  1603. remark := c.GetString("remark")
  1604. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1605. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1606. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1607. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1608. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1609. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1610. special_medicine_other := c.GetString("special_medicine_other")
  1611. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1612. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1613. blood_access, _ := c.GetInt64("blood_access", 0)
  1614. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1615. body_fluid_other := c.GetString("body_fluid_other")
  1616. niprocart, _ := c.GetInt64("niprocart", 0)
  1617. jms, _ := c.GetInt64("jms", 0)
  1618. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1619. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1620. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1621. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1622. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1623. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1624. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1625. injector, _ := c.GetInt64("injector", 0)
  1626. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1627. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1628. safe_package, _ := c.GetInt64("package", 0)
  1629. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1630. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1631. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1632. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1633. blood := c.GetString("blood")
  1634. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1635. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1636. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1637. displace_speed := c.GetString("displace_speed")
  1638. illness, _ := c.GetInt64("illness")
  1639. amylaceum := c.GetString("amylaceum")
  1640. single_time := c.GetString("single_time")
  1641. single_water := c.GetString("single_water")
  1642. replacement_flow := c.GetString("replacement_flow")
  1643. plasma_separator := c.GetString("plasma_separator")
  1644. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1645. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1646. oxygen_flow := c.GetString("oxygen_flow")
  1647. oxygen_time := c.GetString("oxygen_time")
  1648. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1649. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1650. puncture_needle := c.GetString("puncture_needle")
  1651. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1652. epo := c.GetString("epo")
  1653. epo_count, _ := c.GetFloat("epo_count", 0)
  1654. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1655. admin_user_id, _ := c.GetInt64("admin_user_id")
  1656. is_water := c.GetString("is_water")
  1657. var is_war int64
  1658. if is_water == "是" {
  1659. is_war = 1
  1660. }
  1661. if is_water == "否" {
  1662. is_war = 2
  1663. }
  1664. if is_water == "请选择" {
  1665. is_war = 0
  1666. }
  1667. drhy_water := c.GetString("drhy_water")
  1668. dry_water_hour := c.GetString("dry_water_hour")
  1669. water_machine := c.GetString("water_machine")
  1670. add_amount, _ := c.GetFloat("add_amount")
  1671. reduce_amount, _ := c.GetFloat("reduce_amount")
  1672. dialysis_remark := c.GetString("dialysis_remark")
  1673. prescribing_number, _ := c.GetFloat("prescribing_number")
  1674. prescription_sodium := c.GetString("prescription_sodium")
  1675. start_sodium := c.GetString("start_sodium")
  1676. sodium_curve := c.GetString("sodium_curve")
  1677. treatment_remark := c.GetString("treatment_remark")
  1678. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1679. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1680. prescription_water, _ := c.GetFloat("prescription_water")
  1681. dialysis_strainer := c.GetString("dialysis_strainer")
  1682. chaptalization := c.GetString("chaptalization")
  1683. washing_time := c.GetString("washing_time")
  1684. warsh_count := c.GetString("warsh_count")
  1685. blood_access_part_id := c.GetString("blood_access_part_id")
  1686. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1687. dialyzate := c.GetString("dialyzate")
  1688. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1689. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1690. //
  1691. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1692. // if appRole.UserType == 3 {
  1693. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1694. // if getPermissionErr != nil {
  1695. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1696. // return
  1697. // } else if headNursePermission == nil {
  1698. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1699. // return
  1700. // }
  1701. // }
  1702. //}
  1703. // 查询信息规挡的设置天数
  1704. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1705. if infor.ID > 0 && infor.WeekDay > 0 {
  1706. var cha_time int64
  1707. timeNowStr := time.Now().Format("2006-01-02")
  1708. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1709. //今日的日期减去设置的日期
  1710. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1711. if cha_time >= recordDate.Unix() {
  1712. //查询审核是否允许
  1713. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1714. //申请状态不允许的情况 拒绝修改
  1715. if infor.ApplicationStatus != 1 {
  1716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1717. return
  1718. }
  1719. }
  1720. }
  1721. if mode_id > 0 {
  1722. var str string
  1723. //查找该机构用的是什么透析器
  1724. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1725. if filedConfig.ID > 0 {
  1726. str = dialyzerPerfusionApparatus
  1727. } else {
  1728. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1729. }
  1730. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1731. }
  1732. //TODO 需要根据角色去判断
  1733. prescription := models.DialysisPrescription{
  1734. UserOrgId: adminUserInfo.Org.Id,
  1735. PatientId: id,
  1736. RecordDate: recordDate.Unix(),
  1737. ModeId: mode_id,
  1738. DialysisDuration: dialysis_duration,
  1739. Dialyzer: dialyzer,
  1740. PerfusionApparatus: perfusion_apparatus,
  1741. BloodFlowVolume: blood_flow_volume,
  1742. DewaterAmount: dewater_amount,
  1743. DisplaceLiqui: displace_liqui,
  1744. ReplacementWay: replacement_way,
  1745. Anticoagulant: anticoagulant,
  1746. AnticoagulantShouji: anticoagulant_shouji,
  1747. AnticoagulantWeichi: anticoagulant_weichi,
  1748. AnticoagulantZongliang: anticoagulant_zongliang,
  1749. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1750. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1751. Kalium: kalium,
  1752. Sodium: sodium,
  1753. Calcium: calcium,
  1754. Bicarbonate: bicarbonate,
  1755. Glucose: glucose,
  1756. // DryWeight: dry_weight,
  1757. DialysateFlow: dialysate_flow,
  1758. DialysateTemperature: dialysate_temperature,
  1759. // PrescriptionDoctor: prescription_doctor,
  1760. ReplacementTotal: replacement_total,
  1761. Conductivity: conductivity,
  1762. Remark: remark,
  1763. Status: 1,
  1764. CreatedTime: time.Now().Unix(),
  1765. UpdatedTime: time.Now().Unix(),
  1766. DialysisDurationMinute: dialysisDurationMinute,
  1767. DialysisDurationHour: dialysisDurationHour,
  1768. TargetUltrafiltration: targetUltrafiltration,
  1769. DialysateFormulation: dialysateFormulation,
  1770. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1771. BodyFluid: body_fluid,
  1772. SpecialMedicine: special_medicine,
  1773. SpecialMedicineOther: special_medicine_other,
  1774. DisplaceLiquiPart: displace_liqui_part,
  1775. DisplaceLiquiValue: displace_liqui_value,
  1776. BloodAccess: blood_access,
  1777. Ultrafiltration: ultrafiltration,
  1778. BodyFluidOther: body_fluid_other,
  1779. Niprocart: niprocart,
  1780. Jms: jms,
  1781. FistulaNeedleSet: fistula_needle_set,
  1782. FistulaNeedleSet16: fistula_needle_set_16,
  1783. Hemoperfusion: hemoperfusion,
  1784. DialyserSterilised: dialyser_sterilised,
  1785. Filtryzer: filtryzer,
  1786. Dialyzers: dialyzers,
  1787. Injector: injector,
  1788. Bloodlines: bloodlines,
  1789. TubingHemodialysis: tubing_hemodialysis,
  1790. Package: safe_package,
  1791. ALiquid: a_liquid,
  1792. TargetKtv: target_ktv,
  1793. PreImpulse: pre_impulse,
  1794. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1795. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1796. Blood: blood,
  1797. DialysisDialyszers: dialysis_dialyszers,
  1798. DialysisIrrigation: dialysis_irrigation,
  1799. AntioxidantCommodityName: antioxidant_commodity_name,
  1800. DisplaceSpeed: displace_speed,
  1801. Illness: illness,
  1802. Amylaceum: amylaceum,
  1803. SingleTime: single_time,
  1804. SingleWater: single_water,
  1805. ReplacementFlow: replacement_flow,
  1806. PlasmaSeparator: plasma_separator,
  1807. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1808. OxygenUptake: oxygen_uptake,
  1809. OxygenFlow: oxygen_flow,
  1810. OxygenTime: oxygen_time,
  1811. HemodialysisPipelines: hemodialysis_pipelines,
  1812. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1813. PunctureNeedle: puncture_needle,
  1814. PunctureNeedleCount: puncture_needle_count,
  1815. Epo: epo,
  1816. EpoCount: epo_count,
  1817. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1818. AdminUserId: admin_user_id,
  1819. IsWater: is_war,
  1820. DrhyWater: drhy_water,
  1821. DryWaterHour: dry_water_hour,
  1822. WaterMachine: water_machine,
  1823. AddAmount: add_amount,
  1824. ReduceAmount: reduce_amount,
  1825. DialysisRemark: dialysis_remark,
  1826. PrescribingNumber: prescribing_number,
  1827. StartSodium: start_sodium,
  1828. SodiumCurve: sodium_curve,
  1829. TreatmentRemark: treatment_remark,
  1830. PrescriptionSodium: prescription_sodium,
  1831. DialysisFluidFlow: dialysis_fluid_flow,
  1832. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1833. PrescriptionWater: prescription_water,
  1834. DialysisStrainer: dialysis_strainer,
  1835. Chaptalization: chaptalization,
  1836. WashingTime: washing_time,
  1837. WarshCount: warsh_count,
  1838. BloodAccessPartId: blood_access_part_id,
  1839. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1840. Dialyzate: dialyzate,
  1841. }
  1842. //查询最近透析准备表里是否存在 透析器 灌流器
  1843. //
  1844. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1845. //
  1846. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1847. //
  1848. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1849. //if len(mation)>0{
  1850. // for _, item := range splitStr {
  1851. // for _,it := range mation{
  1852. // if(item == it.SpecificationName){
  1853. //
  1854. // //查询最近一次的透析器
  1855. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1856. //
  1857. // if errcode == gorm.ErrRecordNotFound{
  1858. // //插入数据
  1859. // prepare := models.DialysisBeforePrepare{
  1860. // UserOrgId: adminUserInfo.Org.Id,
  1861. // PatientId: id,
  1862. // RecordDate: recordDate.Unix(),
  1863. // GoodTypeId: it.GoodTypeId,
  1864. // GoodId: it.ID,
  1865. // Count: 1,
  1866. // Ctime: time.Now().Unix(),
  1867. // Creater: adminUserInfo.AdminUser.Id,
  1868. // Status:1,
  1869. //
  1870. // }
  1871. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1872. // fmt.Println("",errcode)
  1873. // }
  1874. // }
  1875. // }
  1876. //
  1877. // }
  1878. //
  1879. // for _, item := range splitIrrigation {
  1880. // for _,it := range mation{
  1881. // if(item == it.SpecificationName){
  1882. // //查询最近一次的透析器
  1883. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1884. // if errcode == gorm.ErrRecordNotFound{
  1885. // //插入数据
  1886. // prepare := models.DialysisBeforePrepare{
  1887. // UserOrgId: adminUserInfo.Org.Id,
  1888. // PatientId: id,
  1889. // RecordDate: recordDate.Unix(),
  1890. // GoodTypeId: it.GoodTypeId,
  1891. // GoodId: it.ID,
  1892. // Count: 1,
  1893. // Ctime: time.Now().Unix(),
  1894. // Creater: adminUserInfo.AdminUser.Id,
  1895. // Status:1,
  1896. //
  1897. // }
  1898. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1899. // fmt.Println(errcode)
  1900. // }
  1901. // }
  1902. // }
  1903. // }
  1904. //}
  1905. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1906. if dialysisPrescription.ID == 0 { //新增
  1907. if appRole.UserType == 2 || appRole.UserType == 1 {
  1908. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1909. }
  1910. prescription.Creater = adminUserInfo.AdminUser.Id
  1911. //针对河间咸得
  1912. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1913. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1914. prescription.DisplaceLiquiPart = 0
  1915. prescription.DisplaceLiquiValue = 0
  1916. }
  1917. }
  1918. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1919. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1920. }
  1921. err := service.AddSigleRecord(&prescription)
  1922. //记录日志
  1923. byterequest, _ := json.Marshal(prescription)
  1924. prescriptionLog := models.XtDialysisPrescriptionLog{
  1925. UserOrgId: prescription.UserOrgId,
  1926. Ctime: time.Now().Unix(),
  1927. Mtime: 0,
  1928. ErrLog: string(byterequest),
  1929. AdminUserId: adminUserInfo.AdminUser.Id,
  1930. RecordDate: prescription.RecordDate,
  1931. PatientId: prescription.PatientId,
  1932. Source: "手机端新增保存处方",
  1933. Status: 1,
  1934. }
  1935. service.CreatePrescriptionLog(prescriptionLog)
  1936. finish := models.XtDialysisFinish{
  1937. IsFinish: 1,
  1938. UserOrgId: adminUserInfo.Org.Id,
  1939. Status: 1,
  1940. Ctime: time.Now().Unix(),
  1941. Mtime: 0,
  1942. Module: 1,
  1943. RecordDate: recordDate.Unix(),
  1944. Sourse: 1,
  1945. PatientId: id,
  1946. }
  1947. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1948. if dialysisFinish.ID == 0 {
  1949. service.CreateDialysisFinish(finish)
  1950. }
  1951. //长沙南雅医院,自动生成抗凝剂的临时处方
  1952. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1953. if prescribing_number == 0 {
  1954. prescribing_number = 1
  1955. }
  1956. if prescribing_number == 0 && id == 14682 {
  1957. prescribing_number = 2
  1958. }
  1959. if prescribing_number == 0 && id == 18560 {
  1960. prescribing_number = 2
  1961. }
  1962. advice := models.DoctorAdvice{
  1963. UserOrgId: adminUserInfo.Org.Id,
  1964. PatientId: id,
  1965. GroupNo: 0,
  1966. AdviceType: 2,
  1967. RecordDate: recordDate.Unix(),
  1968. AdviceDate: recordDate.Unix(),
  1969. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1970. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1971. AdviceDesc: "",
  1972. ReminderDate: 0,
  1973. SingleDose: anticoagulant_zongliang,
  1974. SingleDoseUnit: "iu",
  1975. DrugSpec: 0,
  1976. DrugSpecUnit: "",
  1977. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1978. PrescribingNumberUnit: "支",
  1979. DeliveryWay: "静脉注射",
  1980. ExecutionFrequency: "上机前",
  1981. AdviceDoctor: 0,
  1982. Status: 1,
  1983. CreatedTime: time.Now().Unix(),
  1984. UpdatedTime: time.Now().Unix(),
  1985. IsPrescription: 1,
  1986. ExecutionState: 2,
  1987. StopState: 2,
  1988. IsSettle: 2,
  1989. }
  1990. // 查询排班信息
  1991. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1992. if schedulePatient.ID > 0 {
  1993. if schedulePatient.ScheduleType == 1 {
  1994. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1995. }
  1996. if schedulePatient.ScheduleType == 2 {
  1997. advice.StartTime = recordDate.Unix() + 9*60*60
  1998. }
  1999. }
  2000. // 抗凝剂名称
  2001. switch anticoagulant {
  2002. case 1:
  2003. advice.AdviceName = "无肝素"
  2004. break
  2005. case 2:
  2006. advice.AdviceName = "普通肝素"
  2007. break
  2008. case 3:
  2009. advice.AdviceName = "低分子肝素"
  2010. break
  2011. case 4:
  2012. advice.AdviceName = "阿加曲班"
  2013. break
  2014. case 5:
  2015. advice.AdviceName = "枸橼酸钠"
  2016. break
  2017. case 6:
  2018. advice.AdviceName = "低分子肝素钙"
  2019. break
  2020. case 7:
  2021. advice.AdviceName = "低分子肝素钠"
  2022. break
  2023. case 8:
  2024. advice.AdviceName = "依诺肝素"
  2025. break
  2026. case 9:
  2027. advice.AdviceName = "达肝素"
  2028. break
  2029. case 10:
  2030. advice.AdviceName = "体外抗凝"
  2031. break
  2032. case 11:
  2033. advice.AdviceName = "那曲肝素"
  2034. break
  2035. case 12:
  2036. advice.AdviceName = "无抗凝剂"
  2037. break
  2038. }
  2039. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2040. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2041. advice.AdviceDoctor = appRole.AdminUserId
  2042. }
  2043. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2044. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2045. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2046. advice.AdviceName = "低分子肝素钠注射液"
  2047. // 修改患者临时医嘱里的抗凝剂医嘱
  2048. advice.ID = advicePrescription.ID
  2049. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2050. } else {
  2051. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2052. advice.AdviceName = "低分子肝素钠注射液"
  2053. // 新增患者临时医嘱里的抗凝剂医嘱
  2054. service.CreateDoctorAdvice(&advice)
  2055. }
  2056. }
  2057. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2058. redis := service.RedisClient()
  2059. defer redis.Close()
  2060. //清空key 值
  2061. redis.Set(key, "", time.Second)
  2062. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2063. redis.Set(keyOne, "", time.Second)
  2064. }
  2065. //获取key,清空redis
  2066. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2067. redis := service.RedisClient()
  2068. //清空key 值
  2069. redis.Set(key, "", time.Second)
  2070. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2071. //清空key 值
  2072. redis.Set(keyOne, "", time.Second)
  2073. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2074. //清空key 值
  2075. redis.Set(keyTwo, "", time.Second)
  2076. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2077. redis.Set(keySix, "", time.Second)
  2078. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2079. redis.Set(keySeven, "", time.Second)
  2080. if err == nil {
  2081. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2082. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2083. //清空key 值
  2084. redis.Set(keyThree, "", time.Second)
  2085. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2086. //清空key 值
  2087. redis.Set(keyFour, "", time.Second)
  2088. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2089. redis.Set(keyFive, "", time.Second)
  2090. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2091. redis.Set(keySix, "", time.Second)
  2092. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2093. redis.Set(keySeven, "", time.Second)
  2094. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2095. //清空key 值
  2096. redis.Set(keyOne, "", time.Second)
  2097. if updateErr != nil {
  2098. utils.ErrorLog("%v", updateErr)
  2099. }
  2100. defer redis.Close()
  2101. c.ServeSuccessJSON(map[string]interface{}{
  2102. "prescription": prescription,
  2103. })
  2104. }
  2105. } else { //修改
  2106. //if mode_id > 0 {
  2107. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2108. //}
  2109. //if template.TemplateId == 1 {
  2110. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2111. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2112. // if getPermissionErr != nil {
  2113. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2114. // return
  2115. // } else if headNursePermission == nil {
  2116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2117. // return
  2118. // }
  2119. // }
  2120. //}
  2121. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2122. prescription.Modifier = adminUserInfo.AdminUser.Id
  2123. if appRole.UserType == 2 || appRole.UserType == 1 {
  2124. prescription_doctor := adminUserInfo.AdminUser.Id
  2125. prescription.PrescriptionDoctor = prescription_doctor
  2126. } else {
  2127. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2128. }
  2129. if dialysisPrescription.Creater == 0 { //体重称
  2130. prescription.Creater = adminUserInfo.AdminUser.Id
  2131. } else {
  2132. prescription.Creater = dialysisPrescription.Creater
  2133. if adminUserInfo.Org.Id == 9882 {
  2134. if appRole.UserType == 2 || appRole.UserType == 1 {
  2135. prescription_doctor := adminUserInfo.AdminUser.Id
  2136. prescription.PrescriptionDoctor = prescription_doctor
  2137. prescription.Creater = prescription_doctor
  2138. }
  2139. }
  2140. }
  2141. prescription.ID = dialysisPrescription.ID
  2142. service.UpDateDialysisPrescription(&prescription)
  2143. //记录日志
  2144. byterequest, _ := json.Marshal(prescription)
  2145. prescriptionLog := models.XtDialysisPrescriptionLog{
  2146. UserOrgId: prescription.UserOrgId,
  2147. Ctime: time.Now().Unix(),
  2148. Mtime: 0,
  2149. ErrLog: string(byterequest),
  2150. AdminUserId: adminUserInfo.AdminUser.Id,
  2151. RecordDate: prescription.RecordDate,
  2152. PatientId: prescription.PatientId,
  2153. Source: "手机端修改处方",
  2154. Status: 1,
  2155. }
  2156. service.CreatePrescriptionLog(prescriptionLog)
  2157. finish := models.XtDialysisFinish{
  2158. IsFinish: 1,
  2159. UserOrgId: adminUserInfo.Org.Id,
  2160. Status: 1,
  2161. Ctime: time.Now().Unix(),
  2162. Mtime: 0,
  2163. Module: 1,
  2164. RecordDate: recordDate.Unix(),
  2165. Sourse: 1,
  2166. PatientId: id,
  2167. }
  2168. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2169. if dialysisFinish.ID == 0 {
  2170. service.CreateDialysisFinish(finish)
  2171. }
  2172. //修改处方
  2173. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2174. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2175. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2176. if advicePrescription.ID > 0 {
  2177. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2178. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2179. redis := service.RedisClient()
  2180. defer redis.Close()
  2181. //清空key 值
  2182. redis.Set(key, "", time.Second)
  2183. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2184. redis.Set(keyOne, "", time.Second)
  2185. }
  2186. }
  2187. //获取key,清空redis
  2188. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2189. redis := service.RedisClient()
  2190. //清空key 值
  2191. redis.Set(key, "", time.Second)
  2192. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2193. //清空key 值
  2194. redis.Set(keyOne, "", time.Second)
  2195. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2196. redis.Set(keySix, "", time.Second)
  2197. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2198. redis.Set(keySeven, "", time.Second)
  2199. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2200. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2201. //清空key 值
  2202. redis.Set(keyTwoOne, "", time.Second)
  2203. defer redis.Close()
  2204. if updateErr != nil {
  2205. utils.ErrorLog("%v", updateErr)
  2206. }
  2207. c.ServeSuccessJSON(map[string]interface{}{
  2208. "prescription": prescription,
  2209. })
  2210. }
  2211. }
  2212. func (c *DialysisAPIController) Finish() {
  2213. id, _ := c.GetInt64("patient", 0)
  2214. recordDateStr := c.GetString("record_date")
  2215. nurseID, _ := c.GetInt64("nurse")
  2216. end_time := c.GetString("end_time")
  2217. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2218. internal_fistula := c.GetString("blood_access_internal_fistula")
  2219. catheter := c.GetString("catheter")
  2220. cruor := c.GetString("cruor")
  2221. mission := c.GetString("mission")
  2222. condenser := c.GetString("condenser")
  2223. if id <= 0 || nurseID <= 0 {
  2224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2225. return
  2226. }
  2227. adminUserInfo := c.GetMobileAdminUserInfo()
  2228. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2229. if patient.ID == 0 {
  2230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2231. return
  2232. }
  2233. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2234. if getNurseErr != nil {
  2235. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2237. return
  2238. } else if nurse == nil {
  2239. c.ErrorLog("护士不存在")
  2240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2241. return
  2242. }
  2243. if len(recordDateStr) == 0 {
  2244. recordDateStr = time.Now().Format("2006-01-02")
  2245. }
  2246. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2247. if parseDateErr != nil {
  2248. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2250. return
  2251. }
  2252. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2253. if parseEndDateErr != nil {
  2254. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2256. return
  2257. }
  2258. // 查询信息规挡的设置天数
  2259. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2260. if infor.ID > 0 && infor.WeekDay > 0 {
  2261. var cha_time int64
  2262. timeNowStr := time.Now().Format("2006-01-02")
  2263. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2264. //今日的日期减去设置的日期
  2265. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2266. if cha_time >= recordDate.Unix() {
  2267. //查询审核是否允许
  2268. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2269. //申请状态不允许的情况 拒绝修改
  2270. if infor.ApplicationStatus != 1 {
  2271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2272. return
  2273. }
  2274. }
  2275. }
  2276. //now := time.Now()
  2277. //year, month, day := now.Date()
  2278. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2279. //todayTimeStamp := today_time.Unix()
  2280. // 获取当天的第一条透析纪录
  2281. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2282. if getMonitorRecordsErr != nil {
  2283. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2285. return
  2286. }
  2287. // 获取当前的最后一条透析纪录
  2288. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2289. if getMonitorRecordsErr != nil {
  2290. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2292. return
  2293. }
  2294. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2295. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2296. if getAADErr != nil {
  2297. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2299. return
  2300. }
  2301. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2302. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2303. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2304. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2305. if assessmentAfterDislysis != nil {
  2306. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2307. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2308. } else {
  2309. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2310. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2311. tempassessmentAfterDislysis.Status = 1
  2312. tempassessmentAfterDislysis.PatientId = id
  2313. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2314. }
  2315. //长沙南雅
  2316. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2317. //获取最后一条透析处方数据
  2318. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2319. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2320. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2321. }
  2322. if dialysisOrder.Stage == 1 {
  2323. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2324. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2325. fmt.Println(value)
  2326. a, b := math.Modf(value)
  2327. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2328. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2329. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2330. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2331. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2332. }
  2333. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2334. //var num1 int64
  2335. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2336. //fmt.Println(num1)
  2337. //sub := float64(num1 / 3600)
  2338. //fmt.Println(sub)
  2339. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2340. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2341. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2342. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2343. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2344. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2345. if adminUserInfo.Org.Id != 10375 {
  2346. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2347. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2348. }
  2349. if adminUserInfo.Org.Id != 10445 {
  2350. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2351. }
  2352. //北方营口医院
  2353. if adminUserInfo.Org.Id == 10445 {
  2354. //获取最后一条透析处方数据
  2355. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2356. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2357. } else {
  2358. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2359. }
  2360. //新化博翔
  2361. if adminUserInfo.Org.Id == 10447 {
  2362. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2363. }
  2364. //阳春
  2365. if adminUserInfo.Org.Id == 10485 {
  2366. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2367. }
  2368. if adminUserInfo.Org.Id == 10551 {
  2369. //获取最后一条透析处方数据
  2370. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2371. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2372. }
  2373. if adminUserInfo.Org.Id == 10580 {
  2374. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2375. }
  2376. if adminUserInfo.Org.Id == 10612 {
  2377. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2378. }
  2379. //孝康
  2380. if adminUserInfo.Org.Id == 10693 {
  2381. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2382. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2383. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2384. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2385. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2386. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2387. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2388. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2389. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2390. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2391. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2392. }
  2393. if adminUserInfo.Org.Id == 10697 {
  2394. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2395. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2396. lastWeightAfter.LastAfterWeight = floatAfeter
  2397. }
  2398. }
  2399. 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 {
  2400. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2401. if evaluation.SystolicBloodPressure == 0 {
  2402. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2403. if adminUserInfo.Org.Id == 10693 {
  2404. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2405. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2406. }
  2407. pre := models.PredialysisEvaluation{
  2408. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2409. }
  2410. fmt.Println("prew", pre)
  2411. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2412. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2413. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2414. redis := service.RedisClient()
  2415. redis.Set(key, "", time.Second)
  2416. redis.Set(keyOne, "", time.Second)
  2417. defer redis.Close()
  2418. fmt.Println(getNurseErr)
  2419. }
  2420. if evaluation.DiastolicBloodPressure == 0 {
  2421. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2422. if adminUserInfo.Org.Id == 10693 {
  2423. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2424. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2425. }
  2426. pres := models.PredialysisEvaluation{
  2427. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2428. }
  2429. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2430. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2431. redis := service.RedisClient()
  2432. redis.Set(key, "", time.Second)
  2433. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2434. redis.Set(keyOne, "", time.Second)
  2435. defer redis.Close()
  2436. fmt.Println(getNurseErr)
  2437. }
  2438. if evaluation.PulseFrequency == 0 {
  2439. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2440. if adminUserInfo.Org.Id == 10693 {
  2441. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2442. evaluation.PulseFrequency = pulseFrequency
  2443. }
  2444. press := models.PredialysisEvaluation{
  2445. PulseFrequency: evaluation.PulseFrequency,
  2446. }
  2447. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2448. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2449. redis := service.RedisClient()
  2450. redis.Set(key, "", time.Second)
  2451. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2452. redis.Set(keyOne, "", time.Second)
  2453. defer redis.Close()
  2454. fmt.Println(getNurseErr)
  2455. }
  2456. if evaluation.Temperature == 0 {
  2457. evaluation.Temperature = fmonitorRecords.Temperature
  2458. press := models.PredialysisEvaluation{
  2459. Temperature: evaluation.Temperature,
  2460. }
  2461. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2462. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2463. redis := service.RedisClient()
  2464. redis.Set(key, "", time.Second)
  2465. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2466. redis.Set(keyOne, "", time.Second)
  2467. defer redis.Close()
  2468. fmt.Println(getNurseErr)
  2469. }
  2470. }
  2471. if adminUserInfo.Org.Id == 9583 {
  2472. //获取透析处方的最后一条数据
  2473. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2474. if diaerr != nil {
  2475. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2477. return
  2478. }
  2479. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2480. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2481. }
  2482. }
  2483. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2484. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2485. }
  2486. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2487. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2488. }
  2489. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2490. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2491. }
  2492. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2493. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2494. }
  2495. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2496. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2497. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2498. }
  2499. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2500. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2501. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2502. }
  2503. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2504. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2505. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2506. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2507. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2508. }
  2509. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2510. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2511. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2512. }
  2513. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2514. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2515. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2516. }
  2517. if lastAssessmentAfterDislysis != nil {
  2518. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2519. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2520. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2521. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2522. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2523. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2524. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2525. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2526. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2527. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2528. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2529. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2530. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2531. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2532. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2533. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2534. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2535. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2536. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2537. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2538. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2539. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2540. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2541. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2542. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2543. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2544. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2545. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2546. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2547. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2548. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2549. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2550. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2551. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2552. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2553. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2554. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2555. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2556. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2557. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2558. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2559. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2560. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2561. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2562. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2563. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2564. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2565. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2566. if tempassessmentAfterDislysis.PatientId == 18695 {
  2567. tempassessmentAfterDislysis.ActualDisplacement = 0
  2568. }
  2569. if adminUserInfo.Org.Id != 10375 {
  2570. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2571. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2572. }
  2573. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2574. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2575. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2576. }
  2577. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2578. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2579. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2580. }
  2581. }
  2582. finish := models.XtDialysisFinish{
  2583. IsFinish: 1,
  2584. UserOrgId: adminUserInfo.Org.Id,
  2585. Status: 1,
  2586. Ctime: time.Now().Unix(),
  2587. Mtime: 0,
  2588. Module: 9,
  2589. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2590. Sourse: 1,
  2591. PatientId: tempassessmentAfterDislysis.PatientId,
  2592. }
  2593. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2594. if dialysisFinish.ID == 0 {
  2595. service.CreateDialysisFinish(finish)
  2596. }
  2597. //孝康
  2598. if adminUserInfo.Org.Id == 10693 {
  2599. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2600. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2601. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2602. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2603. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2604. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2605. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2606. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2607. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2608. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2609. }
  2610. if adminUserInfo.Org.Id == 10697 {
  2611. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2612. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2613. lastWeightAfter.LastAfterWeight = floatAfeter
  2614. }
  2615. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2616. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2617. redis := service.RedisClient()
  2618. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2619. redis.Set(keyOne, "", time.Second)
  2620. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2621. redis.Set(keyTwo, "", time.Second)
  2622. defer redis.Close()
  2623. //清空key 值
  2624. redis.Set(key, "", time.Second)
  2625. if err != nil {
  2626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2627. return
  2628. }
  2629. if dialysisOrder == nil {
  2630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2631. return
  2632. }
  2633. if dialysisOrder.Stage == 2 {
  2634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2635. return
  2636. }
  2637. if dialysisOrder.Stage == 1 {
  2638. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2639. finish := models.XtDialysisFinish{
  2640. IsFinish: 1,
  2641. UserOrgId: adminUserInfo.Org.Id,
  2642. Status: 1,
  2643. Ctime: time.Now().Unix(),
  2644. Mtime: 0,
  2645. Module: 8,
  2646. RecordDate: recordDate.Unix(),
  2647. Sourse: 1,
  2648. PatientId: id,
  2649. }
  2650. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2651. if dialysisFinish.ID == 0 {
  2652. service.CreateDialysisFinish(finish)
  2653. }
  2654. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2655. redis := service.RedisClient()
  2656. defer redis.Close()
  2657. //清空key 值
  2658. redis.Set(key, "", time.Second)
  2659. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2660. redis.Set(keyOne, "", time.Second)
  2661. //结束时候透析次数加1
  2662. service.UpdateSolutionByPatientId(id)
  2663. //下机完自动消毒,针对长沙南雅
  2664. if dialysisOrder.Stage == 1 {
  2665. 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 {
  2666. //根据床位号获取设备型号
  2667. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2668. //查询使用消毒最后一条消毒记录
  2669. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2670. fmt.Println("err", err)
  2671. if err == gorm.ErrRecordNotFound {
  2672. //查找排班
  2673. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2674. //查询改设备是否有消毒计划
  2675. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2676. //根据床位号获取设备id
  2677. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2678. //查询病人信息
  2679. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2680. var con = ""
  2681. if patients.IsInfectious == 0 {
  2682. con = ""
  2683. }
  2684. if patients.IsInfectious == 1 {
  2685. con = "无"
  2686. }
  2687. if patients.IsInfectious == 2 {
  2688. con = "有"
  2689. }
  2690. if errcode == nil {
  2691. var end_time int64
  2692. end_time = endDate.Unix() + plan.DisinfecTime*60
  2693. //新增消毒
  2694. information := models.DeviceInformation{
  2695. Date: dialysisOrder.DialysisDate,
  2696. Zone: dialysisOrder.ZoneId,
  2697. Class: dialysisOrder.SchedualType,
  2698. BedNumber: dialysisOrder.BedID,
  2699. PatientId: dialysisOrder.PatientId,
  2700. DialysisMode: scheduleByPatient.ModeId,
  2701. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2702. Disinfection: 1,
  2703. DialysisConcentration: 1,
  2704. DisinfectionStatus: 1,
  2705. Move: 1,
  2706. UserOrgId: dialysisOrder.UserOrgId,
  2707. DisinfectType: plan.Way,
  2708. DisinfectantType: plan.MachineDisinfectant,
  2709. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2710. Disinfectant: plan.Disinfectant,
  2711. Ctime: time.Now().Unix(),
  2712. Status: 1,
  2713. SignName: nurseID,
  2714. EquimentId: addmacher.ID,
  2715. DisinfectionResidue: 2,
  2716. Bed: addmacher.BedNumber,
  2717. StartTime: dialysisOrder.StartTime,
  2718. EndTime: dialysisOrder.EndTime,
  2719. Contagion: con,
  2720. WeightLoss: 0,
  2721. Hyperfiltratio: 0,
  2722. DialysisHour: "",
  2723. MachineRun: 1,
  2724. DisinfecStartime: endDate.Unix(),
  2725. DisinfecEndtime: end_time,
  2726. }
  2727. err := service.CreateInformationTwo(&information)
  2728. fmt.Println("报错", err)
  2729. }
  2730. }
  2731. }
  2732. }
  2733. dialysisOrder.Stage = 2
  2734. dialysisOrder.FinishNurse = nurseID
  2735. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2736. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2737. dialysisOrder.EndTime = endDate.Unix()
  2738. // 长沙南雅需求
  2739. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2740. //获取最后1条监测的数据
  2741. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2742. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2743. var accumulatedBloodVolume float64
  2744. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2745. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2746. fmt.Println(err)
  2747. // 查询未执行的医嘱
  2748. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2749. for _, item := range doctorAdvice {
  2750. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2751. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2752. redis := service.RedisClient()
  2753. //清空key 值
  2754. redis.Set(key, "", time.Second)
  2755. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2756. redis.Set(keyTwo, "", time.Second)
  2757. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2758. redis.Set(keyThree, "", time.Second)
  2759. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2760. theTime := toTime.Format("2006-01-02")
  2761. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2762. redis.Set(keyFour, "", time.Second)
  2763. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2764. redis.Set(keyFive, "", time.Second)
  2765. defer redis.Close()
  2766. }
  2767. }
  2768. go func() {
  2769. ssoDomain := beego.AppConfig.String("call_domain")
  2770. api := ssoDomain + "/index/downpatient"
  2771. values := make(url.Values)
  2772. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2773. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2774. values.Set("patient_id", strconv.FormatInt(id, 10))
  2775. http.PostForm(api, values)
  2776. }()
  2777. if err == nil {
  2778. c.ServeSuccessJSON(map[string]interface{}{
  2779. "dialysisOrder": dialysisOrder,
  2780. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2781. })
  2782. } else {
  2783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2784. }
  2785. }
  2786. }
  2787. func (c *DialysisAPIController) GetAllZone() {
  2788. adminUserInfo := c.GetMobileAdminUserInfo()
  2789. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2790. if err == nil {
  2791. c.ServeSuccessJSON(map[string]interface{}{
  2792. "zone": zone,
  2793. })
  2794. }
  2795. }
  2796. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2797. adminUserInfo := c.GetMobileAdminUserInfo()
  2798. page, _ := c.GetInt64("page", 1)
  2799. limit, _ := c.GetInt64("limit", 10)
  2800. schedulType, _ := c.GetInt64("schedul_type", 0)
  2801. startTime, _ := c.GetInt64("schedul_time", 0)
  2802. partitionType, _ := c.GetInt64("partition_type", 0)
  2803. keywords := c.GetString("keywords")
  2804. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2805. if err == nil {
  2806. c.ServeSuccessJSON(map[string]interface{}{
  2807. "schedule": dialysisSchedule,
  2808. })
  2809. }
  2810. return
  2811. }
  2812. // /m/api/dialysis/start [post]
  2813. // @param patient_id:int
  2814. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2815. // @param nurse:int 上机护士
  2816. // @param bed:int 床位号
  2817. func (this *DialysisAPIController) StartDialysis() {
  2818. patientID, _ := this.GetInt64("patient_id")
  2819. recordDateStr := this.GetString("record_date")
  2820. nurseID, _ := this.GetInt64("start_nurse")
  2821. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2822. blood_drawing, _ := this.GetInt64("blood_drawing")
  2823. schedual_type, _ := this.GetInt64("schedual_type")
  2824. bedID, _ := this.GetInt64("bed")
  2825. start_time := this.GetString("start_time")
  2826. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2827. change_nurse, _ := this.GetInt64("change_nurse")
  2828. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2829. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2830. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2831. puncture_needle := this.GetString("puncture_needle")
  2832. puncture_way := this.GetString("puncture_way")
  2833. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2834. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2835. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2836. zone_id, _ := this.GetInt64("zone_id")
  2837. elecsign := this.GetString("url")
  2838. nuclein_date_str := this.GetString("nuclein_date_str")
  2839. schedule_remark := this.GetString("schedule_remark")
  2840. order_remark := this.GetString("order_remark")
  2841. catheter_operation := this.GetString("catheter_operation")
  2842. blood_flow_volume := this.GetString("blood_flow_volume")
  2843. dialysis_strainer := this.GetString("dialysis_strainer")
  2844. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2845. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2846. return
  2847. }
  2848. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2849. if parseStartDateErr != nil {
  2850. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2851. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2852. return
  2853. }
  2854. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2855. if parseErr != nil {
  2856. this.ErrorLog("时间解析失败:%v", parseErr)
  2857. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2858. return
  2859. }
  2860. adminUserInfo := this.GetMobileAdminUserInfo()
  2861. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2862. if getPatientErr != nil {
  2863. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2864. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2865. return
  2866. } else if patient == nil {
  2867. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2868. return
  2869. }
  2870. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2871. if getNurseErr != nil {
  2872. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2873. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2874. return
  2875. } else if nurse == nil {
  2876. this.ErrorLog("护士不存在")
  2877. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2878. return
  2879. }
  2880. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2881. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2882. if getDeviceNumberErr != nil {
  2883. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2885. return
  2886. } else if deviceNumber == nil {
  2887. this.ErrorLog("床位号不存在")
  2888. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2889. return
  2890. }
  2891. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2892. if getRecordErr != nil {
  2893. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2894. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2895. return
  2896. } else if dialysisRecord != nil {
  2897. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2898. return
  2899. }
  2900. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2901. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2902. timeLayout := "2006-01-02 15:04:05"
  2903. loc, _ := time.LoadLocation("Local")
  2904. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2905. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2906. schedulestartTime := theStartTime.Unix()
  2907. scheduleendTime := theEndTime.Unix()
  2908. var theNucleinDate int64
  2909. timeLayoutOne := "2006-01-02"
  2910. if len(nuclein_date_str) > 0 {
  2911. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2912. if err != nil {
  2913. utils.ErrorLog(err.Error())
  2914. }
  2915. theNucleinDate = theTime.Unix()
  2916. }
  2917. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2918. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2919. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2920. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2921. //查询该床位是否有人用了
  2922. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2923. if err == gorm.ErrRecordNotFound { //空床位
  2924. // 修改了床位逻辑
  2925. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2926. if daySchedule.ID > 0 {
  2927. daySchedule.PartitionId = deviceNumber.ZoneID
  2928. daySchedule.BedId = bedID
  2929. daySchedule.ScheduleType = schedual_type
  2930. daySchedule.UpdatedTime = time.Now().Unix()
  2931. xtSchedule := models.Schedule{
  2932. PartitionId: deviceNumber.ZoneID,
  2933. BedId: bedID,
  2934. ScheduleType: schedual_type,
  2935. UpdatedTime: time.Now().Unix(),
  2936. }
  2937. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2938. if err != nil {
  2939. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2940. return
  2941. }
  2942. }
  2943. } else if err == nil {
  2944. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2945. if order.ID > 0 { //该机位被其他人占用了
  2946. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2947. return
  2948. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2949. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2950. if daySchedule.ID > 0 {
  2951. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2952. if err != nil {
  2953. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2954. return
  2955. }
  2956. }
  2957. }
  2958. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2960. return
  2961. }
  2962. //else if order.ID == 0 { //该床位没被占用
  2963. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2964. // if daySchedule.ID > 0 {
  2965. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2966. // //daySchedule.BedId = bedID
  2967. // //daySchedule.ScheduleType = schedual_type
  2968. // //daySchedule.UpdatedTime = time.Now().Unix()
  2969. // //err := service.UpdateSchedule(&daySchedule)
  2970. // xtSchedule := models.Schedule{
  2971. // PartitionId: deviceNumber.ZoneID,
  2972. // BedId: bedID,
  2973. // ScheduleType: schedual_type,
  2974. // UpdatedTime: time.Now().Unix(),
  2975. // }
  2976. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2977. // if err != nil {
  2978. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2979. // return
  2980. // }
  2981. // }
  2982. //}
  2983. //}
  2984. } else if err != nil {
  2985. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2986. return
  2987. }
  2988. // 查询信息规挡的设置天数
  2989. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2990. if infor.ID > 0 && infor.WeekDay > 0 {
  2991. var cha_time int64
  2992. timeNowStr := time.Now().Format("2006-01-02")
  2993. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2994. //今日的日期减去设置的日期
  2995. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2996. if cha_time >= recordDate.Unix() {
  2997. //查询审核是否允许
  2998. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  2999. //申请状态不允许的情况 拒绝修改
  3000. if infor.ApplicationStatus != 1 {
  3001. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3002. return
  3003. }
  3004. }
  3005. }
  3006. dialysisRecord = &models.DialysisOrder{
  3007. DialysisDate: recordDate.Unix(),
  3008. UserOrgId: adminUserInfo.Org.Id,
  3009. PatientId: patientID,
  3010. Stage: 1,
  3011. BedID: bedID,
  3012. StartNurse: nurseID,
  3013. Status: 1,
  3014. StartTime: startDate.Unix(),
  3015. CreatedTime: time.Now().Unix(),
  3016. UpdatedTime: time.Now().Unix(),
  3017. PunctureNurse: puncture_nurse,
  3018. Creator: adminUserInfo.AdminUser.Id,
  3019. Modifier: adminUserInfo.AdminUser.Id,
  3020. SchedualType: schedual_type,
  3021. WashpipeNurse: washpipe_nurse,
  3022. ChangeNurse: change_nurse,
  3023. DifficultPunctureNurse: difficult_puncture_nurse,
  3024. NewFistulaNurse: new_fistula_nurse,
  3025. ZoneId: zone_id,
  3026. QualityNurseId: quality_nurse_id,
  3027. PunctureNeedle: puncture_needle,
  3028. PunctureWay: puncture_way,
  3029. DialysisIrrigation: dialysis_irrigation,
  3030. DialysisDialyszers: dialysis_dialyszers,
  3031. BloodAccessId: blood_access_id,
  3032. Url: elecsign,
  3033. NucleinDate: theNucleinDate,
  3034. ScheduleRemark: schedule_remark,
  3035. OrderRemark: order_remark,
  3036. CatheterOperation: catheter_operation,
  3037. BloodFlowVolume: blood_flow_volume,
  3038. BloodDrawing: blood_drawing,
  3039. DialysisStrainer: dialysis_strainer,
  3040. }
  3041. //查询该床位是否有人用了
  3042. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3043. if errorscode == gorm.ErrRecordNotFound {
  3044. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3045. finish := models.XtDialysisFinish{
  3046. IsFinish: 1,
  3047. UserOrgId: adminUserInfo.Org.Id,
  3048. Status: 1,
  3049. Ctime: time.Now().Unix(),
  3050. Mtime: 0,
  3051. Module: 6,
  3052. RecordDate: schedulestartTime,
  3053. Sourse: 1,
  3054. PatientId: patientID,
  3055. }
  3056. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3057. if dialysisFinish.ID == 0 {
  3058. service.CreateDialysisFinish(finish)
  3059. }
  3060. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3061. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3062. //统计该患者总次数
  3063. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3064. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3065. }
  3066. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3067. //统计该患者总次数
  3068. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3069. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3070. }
  3071. redis := service.RedisClient()
  3072. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3073. redis.Set(key, "", time.Second)
  3074. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3075. //清空key 值
  3076. redis.Set(keyOne, "", time.Second)
  3077. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3078. //清空key 值
  3079. redis.Set(keyTwo, "", time.Second)
  3080. if createErr != nil {
  3081. this.ErrorLog("上机失败:%v", createErr)
  3082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3083. return
  3084. }
  3085. }
  3086. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3087. var tempdispose string
  3088. // 只针对中能建
  3089. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3090. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3091. }
  3092. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3093. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3094. }
  3095. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3096. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3097. //}
  3098. var ultrafiltration_rate float64
  3099. var ultrafiltration_rate_one string
  3100. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3101. //后期预增脱水量
  3102. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3103. if prescription.ID > 0 {
  3104. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3105. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3106. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375 || adminUserInfo.Org.Id == 10599) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  3107. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3108. }
  3109. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3110. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3111. }
  3112. //针对医师汇
  3113. if adminUserInfo.Org.Id == 10121 {
  3114. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3115. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3116. }
  3117. //针对通道
  3118. if adminUserInfo.Org.Id == 10234 {
  3119. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3120. }
  3121. //针对监利大垸医院
  3122. if template.TemplateId == 41 {
  3123. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3124. }
  3125. //针对肇庆三鹤血液透析中心
  3126. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3127. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3128. }
  3129. if adminUserInfo.Org.Id == 10469 {
  3130. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3131. }
  3132. if adminUserInfo.Org.Id == 10667 {
  3133. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3134. }
  3135. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3136. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3137. }
  3138. // 只针对方济医院
  3139. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3140. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3141. ultrafiltration_rate = value
  3142. }
  3143. //针对
  3144. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3145. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3146. ultrafiltration_rate = ultrafiltration_rate / 1000
  3147. }
  3148. if adminUserInfo.Org.Id == 10551 {
  3149. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3150. ultrafiltration_rate = ultrafiltration_rate / 1000
  3151. }
  3152. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3153. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3154. ultrafiltration_rate = ultrafiltration_rate / 1000
  3155. }
  3156. if adminUserInfo.Org.Id == 10580 {
  3157. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3158. ultrafiltration_rate = ultrafiltration_rate / 1000
  3159. }
  3160. if adminUserInfo.Org.Id == 10629 {
  3161. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3162. ultrafiltration_rate = ultrafiltration_rate / 1000
  3163. }
  3164. if adminUserInfo.Org.Id == 10644 {
  3165. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3166. ultrafiltration_rate = ultrafiltration_rate / 1000
  3167. }
  3168. if adminUserInfo.Org.Id == 10667 {
  3169. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3170. ultrafiltration_rate = ultrafiltration_rate / 1000
  3171. }
  3172. if adminUserInfo.Org.Id == 10693 {
  3173. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3174. ultrafiltration_rate = ultrafiltration_rate
  3175. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3176. }
  3177. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3178. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3179. ultrafiltration_rate = ultrafiltration_rate
  3180. }
  3181. if adminUserInfo.Org.Id == 10702 {
  3182. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3183. ultrafiltration_rate = ultrafiltration_rate / 1000
  3184. }
  3185. if adminUserInfo.Org.Id == 10723 {
  3186. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3187. ultrafiltration_rate = ultrafiltration_rate / 1000
  3188. }
  3189. if adminUserInfo.Org.Id == 10721 {
  3190. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3191. ultrafiltration_rate = ultrafiltration_rate / 1000
  3192. }
  3193. }
  3194. }
  3195. record := models.MonitoringRecord{
  3196. UserOrgId: adminUserInfo.Org.Id,
  3197. PatientId: patientID,
  3198. DialysisOrderId: dialysisRecord.ID,
  3199. MonitoringDate: schedulestartTime,
  3200. OperateTime: startDate.Unix(),
  3201. // MonitoringTime: recordTime,
  3202. MonitoringNurse: nurseID,
  3203. Dispose: tempdispose,
  3204. UltrafiltrationRate: ultrafiltration_rate,
  3205. UltrafiltrationVolume: 0,
  3206. Status: 1,
  3207. CreatedTime: time.Now().Unix(),
  3208. UpdatedTime: time.Now().Unix(),
  3209. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3210. }
  3211. //只针对广慈医院
  3212. 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 {
  3213. // 查询病人是否有透前评估数据
  3214. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3215. //如果有数据就插入
  3216. if errcode == nil {
  3217. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3218. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3219. record.BreathingRate = befor.BreathingRate
  3220. record.PulseFrequency = befor.PulseFrequency
  3221. record.Temperature = befor.Temperature
  3222. }
  3223. }
  3224. //孝昌
  3225. if adminUserInfo.Org.Id == 10693 {
  3226. // 查询病人是否有透前评估数据
  3227. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3228. //如果有数据就插入
  3229. if errcode == nil {
  3230. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3231. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3232. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3233. record.BreathingRate = befor.BreathingRate
  3234. }
  3235. }
  3236. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3237. if newdialysisRecord.ID > 0 {
  3238. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3239. record.Temperature = 36.5
  3240. record.ArterialPressure = -100
  3241. record.DialysateTemperature = 36.5
  3242. record.Conductivity = 14
  3243. record.BreathingRate = "20"
  3244. record.VenousPressure = 80
  3245. record.TransmembranePressure = 60
  3246. record.Dispose = catheter_operation
  3247. }
  3248. //针对新化博翔
  3249. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3250. record.BloodOxygenSaturation = "99"
  3251. record.Conductivity = 14
  3252. record.DialysateTemperature = 36.5
  3253. record.BreathingRate = "20"
  3254. }
  3255. //针对兰溪人民医院的需求
  3256. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3257. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3258. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3259. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3260. record.Temperature = befor.Temperature
  3261. record.PulseFrequency = befor.PulseFrequency
  3262. record.BreathingRate = befor.BreathingRate
  3263. }
  3264. //针对乐山友谊医院的需求
  3265. if adminUserInfo.Org.Id == 10677 {
  3266. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3267. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3268. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3269. record.Temperature = befor.Temperature
  3270. record.PulseFrequency = befor.PulseFrequency
  3271. record.BreathingRate = befor.BreathingRate
  3272. }
  3273. //新化博翔
  3274. if adminUserInfo.Org.Id == 10447 {
  3275. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3276. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3277. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3278. record.BreathingRate = befor.BreathingRate
  3279. }
  3280. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3281. record.PulseFrequency = 80
  3282. record.Temperature = 36.5
  3283. }
  3284. //诊断灵山圣康
  3285. if adminUserInfo.Org.Id == 10375 {
  3286. record.Conductivity = 13.8
  3287. record.DialysateTemperature = 37
  3288. record.DialysateFlow = 500
  3289. record.BloodFlowVolume = 200
  3290. record.BreathingRate = "18"
  3291. record.SodiumConcentration = 140
  3292. }
  3293. //江成肾病医院
  3294. if adminUserInfo.Org.Id == 10517 {
  3295. record.SodiumConcentration = 138
  3296. record.DialysateTemperature = 36.5
  3297. }
  3298. //濉溪杏康血液透析中心
  3299. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3300. record.BloodFlowVolume = prescription.BloodFlowVolume
  3301. }
  3302. if adminUserInfo.Org.Id != 10683 {
  3303. err = service.CreateMonitor(&record)
  3304. }
  3305. //记录日志
  3306. byterequest, _ := json.Marshal(record)
  3307. monitorRecordLog := models.XtMonitorRecordLog{
  3308. RecordDate: record.MonitoringDate,
  3309. PatientId: record.PatientId,
  3310. Module: 1,
  3311. AdminUserId: adminUserInfo.AdminUser.Id,
  3312. Ctime: time.Now().Unix(),
  3313. Mtime: 0,
  3314. Status: 1,
  3315. UserOrgId: record.UserOrgId,
  3316. ErrLog: string(byterequest),
  3317. Source: "执行上机时新增监测",
  3318. }
  3319. service.CreateMonitorRecordLog(monitorRecordLog)
  3320. finish := models.XtDialysisFinish{
  3321. IsFinish: 1,
  3322. UserOrgId: adminUserInfo.Org.Id,
  3323. Status: 1,
  3324. Ctime: time.Now().Unix(),
  3325. Mtime: 0,
  3326. Module: 7,
  3327. RecordDate: schedulestartTime,
  3328. Sourse: 1,
  3329. PatientId: patientID,
  3330. }
  3331. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3332. if dialysisFinish.ID == 0 {
  3333. service.CreateDialysisFinish(finish)
  3334. }
  3335. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3336. redis := service.RedisClient()
  3337. //清空key 值
  3338. redis.Set(key, "", time.Second)
  3339. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3340. redis.Set(keyOne, "", time.Second)
  3341. defer redis.Close()
  3342. if err != nil {
  3343. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3344. return
  3345. }
  3346. }
  3347. go func() {
  3348. ssoDomain := beego.AppConfig.String("call_domain")
  3349. api := ssoDomain + "/index/uppatient"
  3350. values := make(url.Values)
  3351. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3352. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3353. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3354. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3355. http.PostForm(api, values)
  3356. }()
  3357. this.ServeSuccessJSON(map[string]interface{}{
  3358. "dialysis_order": newdialysisRecord,
  3359. "monitor": record,
  3360. })
  3361. return
  3362. }
  3363. func (c *DialysisAPIController) PostSolution() {
  3364. id, _ := c.GetInt64("patient", 0)
  3365. recordDateStr := c.GetString("record_date")
  3366. if id <= 0 {
  3367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3368. return
  3369. }
  3370. adminUserInfo := c.GetMobileAdminUserInfo()
  3371. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3372. if patient.ID == 0 {
  3373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3374. return
  3375. }
  3376. if len(recordDateStr) == 0 {
  3377. recordDateStr = time.Now().Format("2006-01-02")
  3378. }
  3379. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3380. if parseDateErr != nil {
  3381. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3383. return
  3384. }
  3385. mode_id, _ := c.GetInt64("mode_id", 0)
  3386. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3387. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3388. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3389. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3390. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3391. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3392. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3393. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3394. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3395. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3396. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3397. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3398. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3399. kalium, _ := c.GetFloat("kalium", 0)
  3400. sodium, _ := c.GetFloat("sodium", 0)
  3401. calcium, _ := c.GetFloat("calcium", 0)
  3402. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3403. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3404. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3405. glucose, _ := c.GetFloat("glucose", 0)
  3406. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3407. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3408. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3409. conductivity, _ := c.GetFloat("conductivity", 0)
  3410. remark := c.GetString("remark")
  3411. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3412. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3413. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3414. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3415. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3416. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3417. special_medicine_other := c.GetString("special_medicine_other")
  3418. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3419. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3420. blood_access, _ := c.GetInt64("blood_access", 0)
  3421. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3422. body_fluid_other := c.GetString("body_fluid_other")
  3423. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3424. niprocart, _ := c.GetInt64("niprocart", 0)
  3425. jms, _ := c.GetInt64("jms", 0)
  3426. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3427. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3428. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3429. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3430. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3431. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3432. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3433. injector, _ := c.GetInt64("injector", 0)
  3434. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3435. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3436. safe_package, _ := c.GetInt64("package", 0)
  3437. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3438. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3439. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3440. blood := c.GetString("blood")
  3441. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3442. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3443. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3444. displace_speed := c.GetString("displace_speed")
  3445. illness, _ := c.GetInt64("illness")
  3446. amylaceum := c.GetString("amylaceum")
  3447. single_time := c.GetString("single_time")
  3448. single_water := c.GetString("single_water")
  3449. replacement_flow := c.GetString("replacement_flow")
  3450. plasma_separator := c.GetString("plasma_separator")
  3451. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3452. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3453. oxygen_flow := c.GetString("oxygen_flow")
  3454. oxygen_time := c.GetString("oxygen_time")
  3455. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3456. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3457. puncture_needle := c.GetString("puncture_needle")
  3458. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3459. epo := c.GetString("epo")
  3460. epo_count, _ := c.GetFloat("epo_count", 0)
  3461. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3462. pre_impulse := c.GetString("pre_impulse")
  3463. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3464. admin_user_id, _ := c.GetInt64("admin_user_id")
  3465. is_water := c.GetString("is_water")
  3466. add_amount, _ := c.GetFloat("add_amount")
  3467. reduce_amount, _ := c.GetFloat("reduce_amount")
  3468. prescribing_number, _ := c.GetFloat("prescribing_number")
  3469. treatment_remark := c.GetString("treatment_remark")
  3470. prescription_sodium := c.GetString("prescription_sodium")
  3471. start_sodium := c.GetString("start_sodium")
  3472. sodium_curve := c.GetString("sodium_curve")
  3473. var is_war int64
  3474. if is_water == "是" {
  3475. is_war = 1
  3476. }
  3477. if is_water == "否" {
  3478. is_war = 2
  3479. }
  3480. if is_water == "请选择" {
  3481. is_war = 0
  3482. }
  3483. drhy_water := c.GetString("drhy_water")
  3484. dry_water_hour := c.GetString("dry_water_hour")
  3485. water_machine := c.GetString("water_machine")
  3486. dialysis_remark := c.GetString("dialysis_remark")
  3487. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3488. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3489. prescription_water, _ := c.GetFloat("prescription_water")
  3490. dialysis_strainer := c.GetString("dialysis_strainer")
  3491. chaptalization := c.GetString("chaptalization")
  3492. washing_time := c.GetString("washing_time")
  3493. warsh_count := c.GetString("warsh_count")
  3494. blood_access_part_id := c.GetString("blood_access_part_id")
  3495. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3496. dialyzate := c.GetString("dialyzate")
  3497. if mode_id > 0 {
  3498. var str string
  3499. //查找该机构用的是什么透析器
  3500. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3501. if filedConfig.ID > 0 {
  3502. str = dialyzerPerfusionApparatus
  3503. } else {
  3504. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3505. }
  3506. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3507. }
  3508. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3509. //
  3510. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3511. // if appRole.UserType == 3 {
  3512. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3513. // if getPermissionErr != nil {
  3514. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3515. // return
  3516. // } else if headNursePermission == nil {
  3517. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3518. // return
  3519. // }
  3520. // }
  3521. //}
  3522. // 查询信息规挡的设置天数
  3523. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3524. if infor.ID > 0 && infor.WeekDay > 0 {
  3525. var cha_time int64
  3526. timeNowStr := time.Now().Format("2006-01-02")
  3527. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3528. //今日的日期减去设置的日期
  3529. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3530. if cha_time >= recordDate.Unix() {
  3531. //查询审核是否允许
  3532. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3533. //申请状态不允许的情况 拒绝修改
  3534. if infor.ApplicationStatus != 1 {
  3535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3536. return
  3537. }
  3538. }
  3539. }
  3540. prescription := models.DialysisPrescription{
  3541. UserOrgId: adminUserInfo.Org.Id,
  3542. PatientId: id,
  3543. RecordDate: recordDate.Unix(),
  3544. ModeId: mode_id,
  3545. DialysisDuration: dialysis_duration,
  3546. Dialyzer: dialyzer,
  3547. PerfusionApparatus: perfusion_apparatus,
  3548. BloodFlowVolume: blood_flow_volume,
  3549. DewaterAmount: dewater_amount,
  3550. DisplaceLiqui: displace_liqui,
  3551. ReplacementWay: replacement_way,
  3552. Anticoagulant: anticoagulant,
  3553. AnticoagulantShouji: anticoagulant_shouji,
  3554. AnticoagulantWeichi: anticoagulant_weichi,
  3555. AnticoagulantZongliang: anticoagulant_zongliang,
  3556. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3557. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3558. Kalium: kalium,
  3559. Sodium: sodium,
  3560. Calcium: calcium,
  3561. Bicarbonate: bicarbonate,
  3562. Glucose: glucose,
  3563. // DryWeight: dry_weight,
  3564. DialysateFlow: dialysate_flow,
  3565. DialysateTemperature: dialysate_temperature,
  3566. Conductivity: conductivity,
  3567. Remark: remark,
  3568. Status: 1,
  3569. CreatedTime: time.Now().Unix(),
  3570. UpdatedTime: time.Now().Unix(),
  3571. DialysisDurationMinute: dialysisDurationMinute,
  3572. DialysisDurationHour: dialysisDurationHour,
  3573. TargetUltrafiltration: targetUltrafiltration,
  3574. DialysateFormulation: dialysateFormulation,
  3575. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3576. BodyFluid: body_fluid,
  3577. SpecialMedicine: special_medicine,
  3578. SpecialMedicineOther: special_medicine_other,
  3579. DisplaceLiquiPart: displace_liqui_part,
  3580. DisplaceLiquiValue: displace_liqui_value,
  3581. BloodAccess: blood_access,
  3582. Ultrafiltration: ultrafiltration,
  3583. BodyFluidOther: body_fluid_other,
  3584. ReplacementTotal: replacement_total,
  3585. Niprocart: niprocart,
  3586. Jms: jms,
  3587. FistulaNeedleSet: fistula_needle_set,
  3588. FistulaNeedleSet16: fistula_needle_set_16,
  3589. Hemoperfusion: hemoperfusion,
  3590. DialyserSterilised: dialyser_sterilised,
  3591. Filtryzer: filtryzer,
  3592. TargetKtv: target_ktv,
  3593. Dialyzers: dialyzers,
  3594. Injector: injector,
  3595. Bloodlines: bloodlines,
  3596. TubingHemodialysis: tubing_hemodialysis,
  3597. Package: safe_package,
  3598. ALiquid: a_liquid,
  3599. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3600. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3601. Blood: blood,
  3602. DialysisDialyszers: dialysis_dialyszers,
  3603. DialysisIrrigation: dialysis_irrigation,
  3604. AntioxidantCommodityName: antioxidant_commodity_name,
  3605. DisplaceSpeed: displace_speed,
  3606. Illness: illness,
  3607. Amylaceum: amylaceum,
  3608. SingleWater: single_water,
  3609. SingleTime: single_time,
  3610. ReplacementFlow: replacement_flow,
  3611. PlasmaSeparator: plasma_separator,
  3612. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3613. OxygenUptake: oxygen_uptake,
  3614. OxygenTime: oxygen_time,
  3615. OxygenFlow: oxygen_flow,
  3616. HemodialysisPipelines: hemodialysis_pipelines,
  3617. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3618. PunctureNeedle: puncture_needle,
  3619. PunctureNeedleCount: puncture_needle_count,
  3620. Epo: epo,
  3621. EpoCount: epo_count,
  3622. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3623. PreImpulse: impulse,
  3624. AdminUserId: admin_user_id,
  3625. IsWater: is_war,
  3626. DrhyWater: drhy_water,
  3627. DryWaterHour: dry_water_hour,
  3628. WaterMachine: water_machine,
  3629. AddAmount: add_amount,
  3630. ReduceAmount: reduce_amount,
  3631. DialysisRemark: dialysis_remark,
  3632. PrescribingNumber: prescribing_number,
  3633. PrescriptionSodium: prescription_sodium,
  3634. StartSodium: start_sodium,
  3635. SodiumCurve: sodium_curve,
  3636. TreatmentRemark: treatment_remark,
  3637. DialysisFluidFlow: dialysis_fluid_flow,
  3638. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3639. PrescriptionWater: prescription_water,
  3640. DialysisStrainer: dialysis_strainer,
  3641. Chaptalization: chaptalization,
  3642. WashingTime: washing_time,
  3643. WarshCount: warsh_count,
  3644. BloodAccessPartId: blood_access_part_id,
  3645. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3646. Dialyzate: dialyzate,
  3647. }
  3648. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3649. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3650. //
  3651. if appRole.UserType == 2 || appRole.UserType == 1 {
  3652. prescription_doctor = adminUserInfo.AdminUser.Id
  3653. prescription.PrescriptionDoctor = prescription_doctor
  3654. }
  3655. if dialysisPrescription.ID == 0 { //新增
  3656. prescription.Creater = adminUserInfo.AdminUser.Id
  3657. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3658. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3659. }
  3660. } else { //修改
  3661. if dialysisPrescription.Creater == 0 {
  3662. prescription.Creater = adminUserInfo.AdminUser.Id
  3663. } else {
  3664. prescription.Creater = dialysisPrescription.Creater
  3665. if adminUserInfo.Org.Id == 9882 {
  3666. if appRole.UserType == 2 || appRole.UserType == 1 {
  3667. prescription.Creater = adminUserInfo.AdminUser.Id
  3668. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3669. }
  3670. }
  3671. }
  3672. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3673. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3674. }
  3675. //if/**/
  3676. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3677. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3678. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3679. // if getPermissionErr != nil {
  3680. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3681. // return
  3682. // } else if headNursePermission == nil {
  3683. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3684. // return
  3685. // }
  3686. //}
  3687. //prescription.Creater = dialysisPrescription.Creater
  3688. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3689. prescription.Modifier = adminUserInfo.AdminUser.Id
  3690. prescription.ID = dialysisPrescription.ID
  3691. }
  3692. solution := models.DialysisSolution{
  3693. RegistrarsId: adminUserInfo.AdminUser.Id,
  3694. UserOrgId: adminUserInfo.Org.Id,
  3695. Doctor: prescription_doctor,
  3696. PatientId: id,
  3697. ModeId: mode_id,
  3698. DialysisDuration: dialysis_duration,
  3699. PerfusionApparatus: perfusion_apparatus,
  3700. BloodFlowVolume: blood_flow_volume,
  3701. Dewater: dewater_amount,
  3702. DisplaceLiqui: displace_liqui,
  3703. ReplacementWay: replacement_way,
  3704. Anticoagulant: anticoagulant,
  3705. AnticoagulantShouji: anticoagulant_shouji,
  3706. AnticoagulantWeichi: anticoagulant_weichi,
  3707. AnticoagulantZongliang: anticoagulant_zongliang,
  3708. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3709. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3710. Kalium: kalium,
  3711. Sodium: sodium,
  3712. Calcium: calcium,
  3713. Bicarbonate: bicarbonate,
  3714. Glucose: glucose,
  3715. // DryWeight: dry_weight,
  3716. DialysateFlow: dialysate_flow,
  3717. DialysateTemperature: dialysate_temperature,
  3718. Conductivity: conductivity,
  3719. Remark: remark,
  3720. Status: 1,
  3721. CreatedTime: time.Now().Unix(),
  3722. UpdatedTime: time.Now().Unix(),
  3723. DialysisDurationMinute: dialysisDurationMinute,
  3724. DialysisDurationHour: dialysisDurationHour,
  3725. TargetUltrafiltration: targetUltrafiltration,
  3726. DialysateFormulation: dialysateFormulation,
  3727. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3728. BodyFluid: body_fluid,
  3729. SpecialMedicine: special_medicine,
  3730. SpecialMedicineOther: special_medicine_other,
  3731. DisplaceLiquiPart: displace_liqui_part,
  3732. DisplaceLiquiValue: displace_liqui_value,
  3733. BloodAccess: blood_access,
  3734. Ultrafiltration: ultrafiltration,
  3735. BodyFluidOther: body_fluid_other,
  3736. ReplacementTotal: replacement_total,
  3737. TargetKtv: target_ktv,
  3738. DialysisDialyszers: dialysis_dialyszers,
  3739. DialysisIrrigation: dialysis_irrigation,
  3740. HemodialysisPipelines: hemodialysis_pipelines,
  3741. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3742. PunctureNeedle: puncture_needle,
  3743. PunctureNeedleCount: puncture_needle_count,
  3744. Epo: epo,
  3745. EpoCount: epo_count,
  3746. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3747. PreImpulse: impulse,
  3748. SolutionStatus: 1,
  3749. DialysisRemark: dialysis_remark,
  3750. PrescribingNumber: prescribing_number,
  3751. PrescriptionSodium: prescription_sodium,
  3752. StartSodium: start_sodium,
  3753. SodiumCurve: sodium_curve,
  3754. TreatmentRemark: treatment_remark,
  3755. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3756. DialysisFluidFlow: dialysis_fluid_flow,
  3757. PrescriptionWater: prescription_water,
  3758. DialysisStrainer: dialysis_strainer,
  3759. Chaptalization: chaptalization,
  3760. WashingTime: washing_time,
  3761. WarshCount: warsh_count,
  3762. BloodAccessPartId: blood_access_part_id,
  3763. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3764. Dialyzate: dialyzate,
  3765. }
  3766. //针对河间咸的
  3767. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3768. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3769. solution.DisplaceLiquiPart = 0
  3770. solution.DisplaceLiquiValue = 0
  3771. }
  3772. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3773. prescription.DisplaceLiquiPart = 0
  3774. prescription.DisplaceLiquiValue = 0
  3775. }
  3776. }
  3777. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3778. if solution.PrescribingNumber == 0 {
  3779. solution.PrescribingNumber = 1
  3780. }
  3781. if prescription.PrescribingNumber == 0 {
  3782. prescription.PrescribingNumber = 1
  3783. }
  3784. if solution.PrescribingNumber == 0 && id == 14682 {
  3785. solution.PrescribingNumber = 2
  3786. }
  3787. if solution.PrescribingNumber == 0 && id == 18560 {
  3788. solution.PrescribingNumber = 2
  3789. }
  3790. if prescription.PrescribingNumber == 0 && id == 14682 {
  3791. prescription.PrescribingNumber = 2
  3792. }
  3793. if prescription.PrescribingNumber == 0 && id == 18560 {
  3794. prescription.PrescribingNumber = 2
  3795. }
  3796. }
  3797. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3798. //记录日志
  3799. byterequest, _ := json.Marshal(prescription)
  3800. prescriptionLog := models.XtDialysisPrescriptionLog{
  3801. UserOrgId: prescription.UserOrgId,
  3802. Ctime: time.Now().Unix(),
  3803. Mtime: 0,
  3804. ErrLog: string(byterequest),
  3805. AdminUserId: adminUserInfo.AdminUser.Id,
  3806. RecordDate: prescription.RecordDate,
  3807. PatientId: prescription.PatientId,
  3808. Source: "手机端新增长期处方",
  3809. Status: 1,
  3810. }
  3811. service.CreatePrescriptionLog(prescriptionLog)
  3812. finish := models.XtDialysisFinish{
  3813. IsFinish: 1,
  3814. UserOrgId: adminUserInfo.Org.Id,
  3815. Status: 1,
  3816. Ctime: time.Now().Unix(),
  3817. Mtime: 0,
  3818. Module: 1,
  3819. RecordDate: recordDate.Unix(),
  3820. Sourse: 1,
  3821. PatientId: id,
  3822. }
  3823. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3824. if dialysisFinish.ID == 0 {
  3825. service.CreateDialysisFinish(finish)
  3826. }
  3827. //获取最新1条
  3828. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3829. //更新状态
  3830. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3831. //长沙南雅医院,自动生成抗凝剂的临时处方
  3832. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3833. if prescribing_number == 0 {
  3834. prescribing_number = 1
  3835. }
  3836. advice := models.DoctorAdvice{
  3837. UserOrgId: adminUserInfo.Org.Id,
  3838. PatientId: id,
  3839. GroupNo: 0,
  3840. AdviceType: 2,
  3841. RecordDate: recordDate.Unix(),
  3842. AdviceDate: recordDate.Unix(),
  3843. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3844. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3845. AdviceDesc: "",
  3846. ReminderDate: 0,
  3847. SingleDose: prescription.AnticoagulantZongliang,
  3848. SingleDoseUnit: "iu",
  3849. DrugSpec: 0,
  3850. DrugSpecUnit: "",
  3851. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3852. PrescribingNumberUnit: "支",
  3853. DeliveryWay: "静脉注射",
  3854. ExecutionFrequency: "上机前",
  3855. AdviceDoctor: 0,
  3856. Status: 1,
  3857. CreatedTime: time.Now().Unix(),
  3858. UpdatedTime: time.Now().Unix(),
  3859. IsPrescription: 1,
  3860. ExecutionState: 2,
  3861. StopState: 2,
  3862. IsSettle: 2,
  3863. }
  3864. // 查询排班信息
  3865. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3866. if schedulePatient.ID > 0 {
  3867. if schedulePatient.ScheduleType == 1 {
  3868. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3869. }
  3870. if schedulePatient.ScheduleType == 2 {
  3871. advice.StartTime = recordDate.Unix() + 9*60*60
  3872. }
  3873. }
  3874. // 抗凝剂名称
  3875. switch anticoagulant {
  3876. case 1:
  3877. advice.AdviceName = "无肝素"
  3878. break
  3879. case 2:
  3880. advice.AdviceName = "普通肝素"
  3881. break
  3882. case 3:
  3883. advice.AdviceName = "低分子肝素"
  3884. break
  3885. case 4:
  3886. advice.AdviceName = "阿加曲班"
  3887. break
  3888. case 5:
  3889. advice.AdviceName = "枸橼酸钠"
  3890. break
  3891. case 6:
  3892. advice.AdviceName = "低分子肝素钙"
  3893. break
  3894. case 7:
  3895. advice.AdviceName = "低分子肝素钠"
  3896. break
  3897. case 8:
  3898. advice.AdviceName = "依诺肝素"
  3899. break
  3900. case 9:
  3901. advice.AdviceName = "达肝素"
  3902. break
  3903. case 10:
  3904. advice.AdviceName = "体外抗凝"
  3905. break
  3906. case 11:
  3907. advice.AdviceName = "那曲肝素"
  3908. break
  3909. case 12:
  3910. advice.AdviceName = "无抗凝剂"
  3911. break
  3912. }
  3913. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3914. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3915. advice.AdviceDoctor = appRole.AdminUserId
  3916. }
  3917. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3918. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3919. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3920. advice.AdviceName = "低分子肝素钠注射液"
  3921. // 修改患者临时医嘱里的抗凝剂医嘱
  3922. advice.ID = advicePrescription.ID
  3923. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3924. } else {
  3925. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3926. advice.AdviceName = "低分子肝素钠注射液"
  3927. service.CreateDoctorAdvice(&advice)
  3928. }
  3929. }
  3930. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3931. redis := service.RedisClient()
  3932. defer redis.Close()
  3933. //清空key 值
  3934. redis.Set(key, "", time.Second)
  3935. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3936. redis.Set(keyOne, "", time.Second)
  3937. }
  3938. //获取key,清空redis
  3939. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3940. redis := service.RedisClient()
  3941. defer redis.Close()
  3942. //清空key 值
  3943. redis.Set(key, "", time.Second)
  3944. //清空长期医嘱的key
  3945. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3946. redis.Set(soulution_key, "", time.Second)
  3947. //查询最近透析准备表里是否存在 透析器 灌流器
  3948. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3949. redis.Set(keyOne, "", time.Second)
  3950. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3951. redis.Set(keyTwo, "", time.Second)
  3952. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3953. redis.Set(keyThree, "", time.Second)
  3954. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3955. redis.Set(keyFour, "", time.Second)
  3956. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3957. //
  3958. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3959. //
  3960. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3961. //if len(mation)>0{
  3962. // for _, item := range splitStr {
  3963. // for _,it := range mation{
  3964. // if(item == it.SpecificationName){
  3965. //
  3966. // //查询最近一次的透析器
  3967. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3968. //
  3969. // if errcode == gorm.ErrRecordNotFound{
  3970. // //插入数据
  3971. // prepare := models.DialysisBeforePrepare{
  3972. // UserOrgId: adminUserInfo.Org.Id,
  3973. // PatientId: id,
  3974. // RecordDate: recordDate.Unix(),
  3975. // GoodTypeId: it.GoodTypeId,
  3976. // GoodId: it.ID,
  3977. // Count: 1,
  3978. // Ctime: time.Now().Unix(),
  3979. // Creater: adminUserInfo.AdminUser.Id,
  3980. // Status:1,
  3981. //
  3982. // }
  3983. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3984. // fmt.Println("",errcode)
  3985. // }
  3986. // }
  3987. // }
  3988. //
  3989. // }
  3990. //
  3991. // for _, item := range splitIrrigation {
  3992. // for _,it := range mation{
  3993. // if(item == it.SpecificationName){
  3994. // //查询最近一次的透析器
  3995. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3996. // if errcode == gorm.ErrRecordNotFound{
  3997. // //插入数据
  3998. // prepare := models.DialysisBeforePrepare{
  3999. // UserOrgId: adminUserInfo.Org.Id,
  4000. // PatientId: id,
  4001. // RecordDate: recordDate.Unix(),
  4002. // GoodTypeId: it.GoodTypeId,
  4003. // GoodId: it.ID,
  4004. // Count: 1,
  4005. // Ctime: time.Now().Unix(),
  4006. // Creater: adminUserInfo.AdminUser.Id,
  4007. // Status:1,
  4008. //
  4009. // }
  4010. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4011. // fmt.Println(errcode)
  4012. // }
  4013. // }
  4014. // }
  4015. // }
  4016. //}
  4017. c.ServeSuccessJSON(map[string]interface{}{
  4018. "solution": &solution,
  4019. "prescription": &prescription,
  4020. })
  4021. }
  4022. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4023. patient, _ := c.GetInt64("patient", 0)
  4024. adminUserInfo := c.GetMobileAdminUserInfo()
  4025. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4026. c.ServeSuccessJSON(map[string]interface{}{
  4027. "receiveTreatmentAsses": receiveTreatmentAsses,
  4028. })
  4029. }
  4030. func (this *DialysisAPIController) PostSignInfo() {
  4031. patientID, _ := this.GetInt64("patient_id")
  4032. recordDateStr := this.GetString("date")
  4033. if patientID <= 0 {
  4034. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4035. return
  4036. }
  4037. if len(recordDateStr) == 0 {
  4038. recordDateStr = time.Now().Format("2006-01-02")
  4039. }
  4040. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4041. if parseDateErr != nil {
  4042. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4043. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4044. return
  4045. }
  4046. adminInfo := this.GetMobileAdminUserInfo()
  4047. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4048. if err != nil {
  4049. this.ErrorLog("签名失败:%v", err)
  4050. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4051. return
  4052. }
  4053. this.ServeSuccessJSON(map[string]interface{}{
  4054. "doctor_id": adminInfo.AdminUser.Id,
  4055. })
  4056. }
  4057. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4058. patientID, _ := this.GetInt64("patient_id")
  4059. adminInfo := this.GetMobileAdminUserInfo()
  4060. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4061. this.ServeSuccessJSON(map[string]interface{}{
  4062. "monitor": record,
  4063. })
  4064. }
  4065. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4066. thisTime := time.Now()
  4067. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4068. timeLayout := "2006-01-02 15:04:05"
  4069. loc, _ := time.LoadLocation("Local")
  4070. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4071. theAssessmentDateTime := theStartTime.Unix()
  4072. patientID, _ := this.GetInt64("patient_id")
  4073. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4074. adminInfo := this.GetMobileAdminUserInfo()
  4075. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4076. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4077. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4078. var ultrafiltration_rate float64
  4079. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4080. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4081. fmt.Println(evaluation)
  4082. fmt.Println("prescription.ID", prescription.ID)
  4083. if prescription.ID > 0 {
  4084. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4085. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4086. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4087. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4088. record.UltrafiltrationRate = ultrafiltration_rate
  4089. }
  4090. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4091. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4092. record.UltrafiltrationRate = ultrafiltration_rate
  4093. }
  4094. if adminInfo.Org.Id == 10510 {
  4095. record.UltrafiltrationRate = 0
  4096. }
  4097. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4098. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4099. record.UltrafiltrationRate = ultrafiltration_rate
  4100. }
  4101. if template.TemplateId == 20 || template.TemplateId == 22 {
  4102. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4103. record.UltrafiltrationRate = ultrafiltration_rate
  4104. }
  4105. // 只针对方济医院
  4106. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4107. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4108. ultrafiltration_rate = value
  4109. record.UltrafiltrationRate = ultrafiltration_rate
  4110. }
  4111. if template.TemplateId == 41 || template.TemplateId == 47 {
  4112. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4113. record.UltrafiltrationRate = ultrafiltration_rate
  4114. }
  4115. if template.TemplateId == 43 {
  4116. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4117. record.UltrafiltrationRate = ultrafiltration_rate
  4118. }
  4119. if template.TemplateId == 46 || template.TemplateId == 54 {
  4120. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4121. record.UltrafiltrationRate = ultrafiltration_rate
  4122. }
  4123. 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 {
  4124. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4125. record.UltrafiltrationRate = ultrafiltration_rate
  4126. }
  4127. if adminInfo.Org.Id == 10469 {
  4128. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4129. record.UltrafiltrationRate = ultrafiltration_rate
  4130. }
  4131. if adminInfo.Org.Id == 10667 {
  4132. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4133. record.UltrafiltrationRate = ultrafiltration_rate
  4134. }
  4135. if adminInfo.Org.Id == 10471 {
  4136. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4137. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4138. }
  4139. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4140. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4141. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4142. }
  4143. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4144. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4145. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4146. }
  4147. if adminInfo.Org.Id == 10721 {
  4148. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4149. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4150. }
  4151. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4152. record.UltrafiltrationRate = 0
  4153. }
  4154. //if template.TemplateId == 47 {
  4155. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4156. // record.UltrafiltrationRate = ultrafiltration_rate
  4157. //}
  4158. }
  4159. }
  4160. // record.UltrafiltrationRate = ultrafiltration_rate
  4161. record.UltrafiltrationVolume = 0
  4162. 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
  4163. if ultrafiltration_rate > 0 {
  4164. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4165. record.UltrafiltrationVolume = value
  4166. }
  4167. }
  4168. 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
  4169. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4170. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4171. record.UltrafiltrationVolume = ultrafiltration_volume
  4172. }
  4173. }
  4174. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4175. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4176. record.UltrafiltrationVolume = ultrafiltration_volume
  4177. }
  4178. //长沙南雅
  4179. 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 {
  4180. if ultrafiltration_rate > 0 {
  4181. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4182. record.UltrafiltrationVolume = ultrafiltration_volume
  4183. }
  4184. }
  4185. if adminInfo.Org.Id == 10471 {
  4186. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4187. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4188. }
  4189. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4190. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4191. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4192. }
  4193. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4194. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4195. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4196. }
  4197. //长沙南雅累计血容量自动计算
  4198. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4199. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4200. //}
  4201. if template.TemplateId == 47 || template.TemplateId == 54 {
  4202. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4203. }
  4204. if adminInfo.Org.Id == 10510 {
  4205. record.UltrafiltrationVolume = 0
  4206. }
  4207. if adminInfo.Org.Id == 10721 {
  4208. if ultrafiltration_rate > 0 {
  4209. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4210. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4211. }
  4212. }
  4213. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4214. this.ServeSuccessJSON(map[string]interface{}{
  4215. "monitor": record,
  4216. "lastMonitorRecordList": lastMonitorRecordList,
  4217. })
  4218. }
  4219. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4220. record_id, _ := this.GetInt64("id")
  4221. nurseID, _ := this.GetInt64("start_nurse")
  4222. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4223. bedID, _ := this.GetInt64("bed")
  4224. start_time := this.GetString("start_time")
  4225. schedual_type, _ := this.GetInt64("schedual_type")
  4226. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4227. change_nurse, _ := this.GetInt64("change_nurse")
  4228. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4229. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4230. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4231. patient_id, _ := this.GetInt64("patient_id")
  4232. record_date, _ := this.GetInt64("record_date")
  4233. puncture_needle := this.GetString("puncture_needle")
  4234. puncture_way := this.GetString("puncture_way")
  4235. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4236. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4237. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4238. nuclein_date_str := this.GetString("nuclein_date_str")
  4239. order_remark := this.GetString("order_remark")
  4240. schedule_remark := this.GetString("schedule_remark")
  4241. catheter_operation := this.GetString("catheter_operation")
  4242. blood_flow_volume := this.GetString("blood_flow_volume")
  4243. blood_drawing, _ := this.GetInt64("blood_drawing")
  4244. dialysis_strainer := this.GetString("dialysis_strainer")
  4245. if record_id == 0 {
  4246. this.ErrorLog("id:%v", record_id)
  4247. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4248. return
  4249. }
  4250. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4251. if parseStartDateErr != nil {
  4252. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4253. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4254. return
  4255. }
  4256. adminUserInfo := this.GetMobileAdminUserInfo()
  4257. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4258. if getNurseErr != nil {
  4259. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4260. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4261. return
  4262. } else if nurse == nil {
  4263. this.ErrorLog("护士不存在")
  4264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4265. return
  4266. }
  4267. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4268. //if getNurseErr != nil {
  4269. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4270. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4271. // return
  4272. //} else if nurse == nil {
  4273. // this.ErrorLog("护士不存在")
  4274. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4275. // return
  4276. //}
  4277. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4278. if getDeviceNumberErr != nil {
  4279. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4280. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4281. return
  4282. } else if deviceNumber == nil {
  4283. this.ErrorLog("床位号不存在")
  4284. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4285. return
  4286. }
  4287. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4288. //
  4289. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4290. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4291. // if getPermissionErr != nil {
  4292. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4293. // return
  4294. // } else if headNursePermission == nil {
  4295. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4296. // return
  4297. // }
  4298. //}
  4299. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4300. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4301. timeLayout := "2006-01-02 15:04:05"
  4302. loc, _ := time.LoadLocation("Local")
  4303. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4304. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4305. schedulestartTime := theStartTime.Unix()
  4306. scheduleendTime := theEndTime.Unix()
  4307. var theNucleinDate int64
  4308. timeLayoutOne := "2006-01-02"
  4309. if len(nuclein_date_str) > 0 {
  4310. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4311. if err != nil {
  4312. utils.ErrorLog(err.Error())
  4313. }
  4314. theNucleinDate = theTime.Unix()
  4315. }
  4316. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4317. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4318. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4319. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4320. if err == gorm.ErrRecordNotFound { //空床位
  4321. // 修改了床位逻辑
  4322. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4323. if daySchedule.ID > 0 {
  4324. //daySchedule.BedId = bedID
  4325. //daySchedule.PartitionId = deviceNumber.ZoneID
  4326. //daySchedule.ScheduleType = schedual_type
  4327. //daySchedule.UpdatedTime = time.Now().Unix()
  4328. //err := service.UpdateSchedule(&daySchedule)
  4329. xtSchedule := models.Schedule{
  4330. PartitionId: deviceNumber.ZoneID,
  4331. BedId: bedID,
  4332. ScheduleType: schedual_type,
  4333. UpdatedTime: time.Now().Unix(),
  4334. }
  4335. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4336. if err != nil {
  4337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4338. return
  4339. }
  4340. }
  4341. } else if err == nil {
  4342. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4343. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4344. if daySchedule.ID > 0 {
  4345. //daySchedule.BedId = bedID
  4346. //daySchedule.PartitionId = deviceNumber.ZoneID
  4347. //
  4348. //daySchedule.ScheduleType = schedual_type
  4349. //daySchedule.UpdatedTime = time.Now().Unix()
  4350. //err := service.UpdateSchedule(&daySchedule)
  4351. xtSchedule := models.Schedule{
  4352. PartitionId: deviceNumber.ZoneID,
  4353. BedId: bedID,
  4354. ScheduleType: schedual_type,
  4355. UpdatedTime: time.Now().Unix(),
  4356. }
  4357. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4358. if err != nil {
  4359. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4360. return
  4361. }
  4362. }
  4363. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4364. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4365. return
  4366. }
  4367. } else if err != nil {
  4368. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4369. return
  4370. }
  4371. }
  4372. dialysisRecord := &models.DialysisOrder{
  4373. ID: record_id,
  4374. UserOrgId: adminUserInfo.Org.Id,
  4375. BedID: bedID,
  4376. StartNurse: nurseID,
  4377. StartTime: startDate.Unix(),
  4378. PunctureNurse: puncture_nurse,
  4379. Creator: adminUserInfo.AdminUser.Id,
  4380. Modifier: adminUserInfo.AdminUser.Id,
  4381. WashpipeNurse: washpipe_nurse,
  4382. SchedualType: schedual_type,
  4383. ChangeNurse: change_nurse,
  4384. DifficultPunctureNurse: difficult_puncture_nurse,
  4385. NewFistulaNurse: new_fistula_nurse,
  4386. QualityNurseId: quality_nurse_id,
  4387. PunctureNeedle: puncture_needle,
  4388. PunctureWay: puncture_way,
  4389. DialysisDialyszers: dialysis_dialyszers,
  4390. DialysisIrrigation: dialysis_irrigation,
  4391. BloodAccessId: blood_access_id,
  4392. NucleinDate: theNucleinDate,
  4393. OrderRemark: order_remark,
  4394. ScheduleRemark: schedule_remark,
  4395. CatheterOperation: catheter_operation,
  4396. BloodFlowVolume: blood_flow_volume,
  4397. BloodDrawing: blood_drawing,
  4398. DialysisStrainer: dialysis_strainer,
  4399. }
  4400. //修改床位号需要重新消毒
  4401. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4402. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4403. //查询第一条监测
  4404. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4405. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4406. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4407. redis := service.RedisClient()
  4408. //清空key 值
  4409. redis.Set(key, "", time.Second)
  4410. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4411. redis.Set(keyOne, "", time.Second)
  4412. defer redis.Close()
  4413. }
  4414. // 查询信息规挡的设置天数
  4415. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4416. if infor.ID > 0 && infor.WeekDay > 0 {
  4417. var cha_time int64
  4418. timeNowStr := time.Now().Format("2006-01-02")
  4419. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4420. //今日的日期减去设置的日期
  4421. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4422. if cha_time >= record_date {
  4423. //查询审核是否允许
  4424. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4425. //申请状态不允许的情况 拒绝修改
  4426. if infor.ApplicationStatus != 1 {
  4427. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4428. return
  4429. }
  4430. }
  4431. }
  4432. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4433. //修改床位后重新生成消毒计划
  4434. if adminUserInfo.Org.Id == 10340 {
  4435. //根据床位号获取设备型号
  4436. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4437. //查询使用消毒最后一条消毒记录
  4438. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4439. fmt.Println("err", err)
  4440. if err == gorm.ErrRecordNotFound {
  4441. //查找排班
  4442. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4443. //查询改设备是否有消毒计划
  4444. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4445. //根据床位号获取设备id
  4446. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4447. //查询病人信息
  4448. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4449. var con = ""
  4450. if patients.IsInfectious == 0 {
  4451. con = ""
  4452. }
  4453. if patients.IsInfectious == 1 {
  4454. con = "无"
  4455. }
  4456. if patients.IsInfectious == 2 {
  4457. con = "有"
  4458. }
  4459. if errcode == nil {
  4460. var end_time int64
  4461. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4462. //新增消毒
  4463. information := models.DeviceInformation{
  4464. Date: dialysisRecord.DialysisDate,
  4465. Zone: dialysisRecord.ZoneId,
  4466. Class: dialysisRecord.SchedualType,
  4467. BedNumber: dialysisRecord.BedID,
  4468. PatientId: dialysisRecord.PatientId,
  4469. DialysisMode: scheduleByPatient.ModeId,
  4470. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4471. Disinfection: 1,
  4472. DialysisConcentration: 1,
  4473. DisinfectionStatus: 1,
  4474. Move: 1,
  4475. UserOrgId: dialysisRecord.UserOrgId,
  4476. DisinfectType: plan.Way,
  4477. DisinfectantType: plan.MachineDisinfectant,
  4478. FluidPath: plan.DisinfectanWay, //液路消毒方式
  4479. Disinfectant: plan.Disinfectant,
  4480. Ctime: time.Now().Unix(),
  4481. Status: 1,
  4482. SignName: nurseID,
  4483. EquimentId: addmacher.ID,
  4484. DisinfectionResidue: 2,
  4485. Bed: addmacher.BedNumber,
  4486. StartTime: dialysisRecord.StartTime,
  4487. EndTime: dialysisRecord.EndTime,
  4488. Contagion: con,
  4489. WeightLoss: 0,
  4490. Hyperfiltratio: 0,
  4491. DialysisHour: "",
  4492. MachineRun: 1,
  4493. DisinfecStartime: dialysisRecord.EndTime,
  4494. DisinfecEndtime: end_time,
  4495. }
  4496. err := service.CreateInformationTwo(&information)
  4497. fmt.Println("报错", err)
  4498. }
  4499. }
  4500. }
  4501. order, _ := service.GetLastPatientOrder(record_id)
  4502. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4503. redis := service.RedisClient()
  4504. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4505. redis.Set(key, "", time.Second)
  4506. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4507. //清空key 值
  4508. redis.Set(keyOne, "", time.Second)
  4509. scheduleDateStartOne := startDate.Format("2006-01-02")
  4510. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4511. redis.Set(keyTwo, "", time.Second)
  4512. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4513. redis.Set(keyThree, "", time.Second)
  4514. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4515. redis.Set(keyFour, "", time.Second)
  4516. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4517. redis.Set(keyFive, "", time.Second)
  4518. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4519. redis.Set(keySix, "", time.Second)
  4520. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4521. redis.Set(keySeven, "", time.Second)
  4522. if updateErr != nil {
  4523. this.ErrorLog("修改上机失败:%v", updateErr)
  4524. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4525. return
  4526. }
  4527. if updateErr == nil {
  4528. if tempDialysisRecord.Stage == 2 {
  4529. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4530. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4531. fmt.Println(value)
  4532. a, b := math.Modf(value)
  4533. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4534. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4535. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4536. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4537. redis := service.RedisClient()
  4538. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4539. redis.Set(key, "", time.Second)
  4540. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4541. redis.Set(keyOne, "", time.Second)
  4542. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4543. //清空key 值
  4544. redis.Set(keySix, "", time.Second)
  4545. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4546. redis.Set(keySeven, "", time.Second)
  4547. redis.Close()
  4548. if updateAssessmentErr != nil {
  4549. utils.ErrorLog("%v", updateAssessmentErr)
  4550. }
  4551. }
  4552. }
  4553. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4554. this.ServeSuccessJSON(map[string]interface{}{
  4555. "dialysis_order": dialysisRecords,
  4556. })
  4557. }
  4558. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4559. record_id, _ := c.GetInt64("id")
  4560. nurseID, _ := c.GetInt64("nurse")
  4561. end_time := c.GetString("end_time")
  4562. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4563. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4564. catheter := c.GetString("catheter")
  4565. cruor := c.GetString("cruor")
  4566. mission := c.GetString("mission")
  4567. condenser := c.GetString("condenser")
  4568. if record_id <= 0 || nurseID <= 0 {
  4569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4570. return
  4571. }
  4572. adminUserInfo := c.GetMobileAdminUserInfo()
  4573. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4574. if getNurseErr != nil {
  4575. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4577. return
  4578. } else if nurse == nil {
  4579. c.ErrorLog("护士不存在")
  4580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4581. return
  4582. }
  4583. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4584. if parseEndDateErr != nil {
  4585. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4587. return
  4588. }
  4589. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4590. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4591. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4592. // if getPermissionErr != nil {
  4593. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4594. // return
  4595. // } else if headNursePermission == nil {
  4596. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4597. // return
  4598. // }
  4599. //}
  4600. // 查询信息规挡的设置天数
  4601. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4602. if infor.ID > 0 {
  4603. var cha_time int64
  4604. timeNowStr := time.Now().Format("2006-01-02")
  4605. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4606. //今日的日期减去设置的日期
  4607. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4608. if cha_time >= tempDialysisRecords.DialysisDate {
  4609. //查询审核是否允许
  4610. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4611. //申请状态不允许的情况 拒绝修改
  4612. if infor.ApplicationStatus != 1 {
  4613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4614. return
  4615. }
  4616. }
  4617. }
  4618. dialysisRecord := &models.DialysisOrder{
  4619. ID: record_id,
  4620. UserOrgId: adminUserInfo.Org.Id,
  4621. EndTime: endDate.Unix(),
  4622. FinishNurse: nurseID,
  4623. FinishModifier: adminUserInfo.AdminUser.Id,
  4624. PuncturePointHaematoma: puncture_point_haematoma,
  4625. BloodAccessInternalFistula: blood_access_internal_fistula,
  4626. Catheter: catheter,
  4627. Cruor: cruor,
  4628. Mission: mission,
  4629. Condenser: condenser,
  4630. }
  4631. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4632. redis := service.RedisClient()
  4633. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4634. //清空key 值
  4635. redis.Set(key, "", time.Second)
  4636. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4637. //清空key 值
  4638. redis.Set(keyOne, "", time.Second)
  4639. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4640. redis.Set(keySeven, "", time.Second)
  4641. redis.Close()
  4642. if updateErr != nil {
  4643. c.ErrorLog("修改下机失败:%v", updateErr)
  4644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4645. return
  4646. }
  4647. if updateErr == nil {
  4648. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4649. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4650. a, b := math.Modf(value)
  4651. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4652. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4653. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4654. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4655. redis := service.RedisClient()
  4656. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4657. redis.Set(keyTen, "", time.Second)
  4658. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4659. redis.Set(keyTwo, "", time.Second)
  4660. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4661. redis.Set(key, "", time.Second)
  4662. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4663. redis.Set(keyThree, "", time.Second)
  4664. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4665. redis.Set(keySeven, "", time.Second)
  4666. defer redis.Close()
  4667. if updateAssessmentErr != nil {
  4668. utils.ErrorLog("%v", updateAssessmentErr)
  4669. }
  4670. }
  4671. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4672. c.ServeSuccessJSON(map[string]interface{}{
  4673. "dialysis_order": dialysisRecords,
  4674. })
  4675. }
  4676. func (c *DialysisAPIController) GetLongAdvice() {
  4677. patient_id, _ := c.GetInt64("id")
  4678. adminUserInfo := c.GetMobileAdminUserInfo()
  4679. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4680. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4681. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4682. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4683. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4684. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4685. c.ServeSuccessJSON(map[string]interface{}{
  4686. "status": "1",
  4687. })
  4688. return
  4689. } else { //开启推送提醒
  4690. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4691. var advice_three []*models.DoctorAdvice
  4692. recordDateStr := time.Now().Format("2006-01-02")
  4693. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4694. nowtime := recordDate.Unix()
  4695. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4696. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4697. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4698. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4699. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4700. for _, advice := range advices {
  4701. if advice.FrequencyType == 3 {
  4702. t := time.Now()
  4703. week := int(t.Weekday())
  4704. fmt.Println(t.Weekday())
  4705. fmt.Println(week)
  4706. switch week {
  4707. case 1:
  4708. if strings.Index(advice.WeekDay, "周一") == -1 {
  4709. advice_three = append(advice_three, advice)
  4710. }
  4711. break
  4712. case 2:
  4713. if strings.Index(advice.WeekDay, "周二") == -1 {
  4714. advice_three = append(advice_three, advice)
  4715. }
  4716. break
  4717. case 3:
  4718. if strings.Index(advice.WeekDay, "周三") == -1 {
  4719. advice_three = append(advice_three, advice)
  4720. }
  4721. break
  4722. case 4:
  4723. if strings.Index(advice.WeekDay, "周四") == -1 {
  4724. advice_three = append(advice_three, advice)
  4725. }
  4726. break
  4727. case 5:
  4728. if strings.Index(advice.WeekDay, "周五") == -1 {
  4729. advice_three = append(advice_three, advice)
  4730. }
  4731. break
  4732. case 6:
  4733. if strings.Index(advice.WeekDay, "周六") == -1 {
  4734. advice_three = append(advice_three, advice)
  4735. }
  4736. break
  4737. case 0:
  4738. if strings.Index(advice.WeekDay, "周日") == -1 {
  4739. advice_three = append(advice_three, advice)
  4740. }
  4741. break
  4742. }
  4743. }
  4744. }
  4745. for _, advice := range advices_two {
  4746. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4747. now := p.Unix()
  4748. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4749. dayStr2 := "-" + dayStr
  4750. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4751. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4752. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4753. for _, ad := range advices {
  4754. advice_three = append(advice_three, ad)
  4755. }
  4756. }
  4757. if err == nil {
  4758. c.ServeSuccessJSON(map[string]interface{}{
  4759. "status": "2",
  4760. "advices": advices,
  4761. "advices_two": RemoveRepeatedElement(advice_three),
  4762. "is_open_remind": config.IsOpenRemind,
  4763. "his_config_open": hisConfig.IsOpen,
  4764. "is_advice_open": is_advice_open.IsAdviceOpen,
  4765. "prescription_open": prescription_open.IsOpen,
  4766. })
  4767. }
  4768. }
  4769. }
  4770. func (c *DialysisAPIController) GetLongAdviceOne() {
  4771. patient_id, _ := c.GetInt64("id")
  4772. startTime := c.GetString("schedule_date")
  4773. timeLayout := "2006-01-02"
  4774. loc, _ := time.LoadLocation("Local")
  4775. var theStartTime int64
  4776. if len(startTime) > 0 {
  4777. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4778. if err != nil {
  4779. utils.ErrorLog(err.Error())
  4780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4781. return
  4782. }
  4783. theStartTime = theTime.Unix()
  4784. }
  4785. adminUserInfo := c.GetMobileAdminUserInfo()
  4786. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4787. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4788. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4789. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4790. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4791. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4792. c.ServeSuccessJSON(map[string]interface{}{
  4793. "status": "1",
  4794. })
  4795. return
  4796. } else { //开启推送提醒
  4797. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4798. var advice_three []*models.DoctorAdvice
  4799. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4800. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4801. for _, advice := range advices {
  4802. if advice.FrequencyType == 3 {
  4803. t := time.Now()
  4804. week := int(t.Weekday())
  4805. fmt.Println(t.Weekday())
  4806. fmt.Println(week)
  4807. switch week {
  4808. case 1:
  4809. if strings.Index(advice.WeekDay, "周一") == -1 {
  4810. advice_three = append(advice_three, advice)
  4811. }
  4812. break
  4813. case 2:
  4814. if strings.Index(advice.WeekDay, "周二") == -1 {
  4815. advice_three = append(advice_three, advice)
  4816. }
  4817. break
  4818. case 3:
  4819. if strings.Index(advice.WeekDay, "周三") == -1 {
  4820. advice_three = append(advice_three, advice)
  4821. }
  4822. break
  4823. case 4:
  4824. if strings.Index(advice.WeekDay, "周四") == -1 {
  4825. advice_three = append(advice_three, advice)
  4826. }
  4827. break
  4828. case 5:
  4829. if strings.Index(advice.WeekDay, "周五") == -1 {
  4830. advice_three = append(advice_three, advice)
  4831. }
  4832. break
  4833. case 6:
  4834. if strings.Index(advice.WeekDay, "周六") == -1 {
  4835. advice_three = append(advice_three, advice)
  4836. }
  4837. break
  4838. case 0:
  4839. if strings.Index(advice.WeekDay, "周日") == -1 {
  4840. advice_three = append(advice_three, advice)
  4841. }
  4842. break
  4843. }
  4844. }
  4845. }
  4846. for _, advice := range advices_two {
  4847. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4848. now := p.Unix()
  4849. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4850. dayStr2 := "-" + dayStr
  4851. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4852. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4853. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4854. for _, ad := range advices {
  4855. advice_three = append(advice_three, ad)
  4856. }
  4857. }
  4858. if err == nil {
  4859. c.ServeSuccessJSON(map[string]interface{}{
  4860. "status": "2",
  4861. "advices": advices,
  4862. "advices_two": RemoveRepeatedElement(advice_three),
  4863. "is_open_remind": config.IsOpenRemind,
  4864. "his_config_open": hisConfig.IsOpen,
  4865. "is_advice_open": is_advice_open.IsAdviceOpen,
  4866. "prescription_open": prescription_open.IsOpen,
  4867. })
  4868. }
  4869. }
  4870. }
  4871. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4872. newArr = make([]*models.DoctorAdvice, 0)
  4873. for i := 0; i < len(arr); i++ {
  4874. repeat := false
  4875. for j := i + 1; j < len(arr); j++ {
  4876. if arr[i].ID == arr[j].ID {
  4877. repeat = true
  4878. break
  4879. }
  4880. }
  4881. if !repeat {
  4882. newArr = append(newArr, arr[i])
  4883. }
  4884. }
  4885. return
  4886. }
  4887. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4888. patient, _ := c.GetInt64("id", 0)
  4889. groupNo, _ := c.GetInt64("groupno", 0)
  4890. if patient <= 0 {
  4891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4892. return
  4893. }
  4894. adminUserInfo := c.GetMobileAdminUserInfo()
  4895. dataBody := make(map[string]interface{}, 0)
  4896. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4897. if err != nil {
  4898. utils.ErrorLog(err.Error())
  4899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4900. return
  4901. }
  4902. utils.ErrorLog("%v", dataBody)
  4903. timeLayout := "2006-01-02 15:04"
  4904. loc, _ := time.LoadLocation("Local")
  4905. timeLayout2 := "2006-01-02"
  4906. loc2, _ := time.LoadLocation("Local")
  4907. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4908. utils.ErrorLog("advice_type")
  4909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4910. return
  4911. }
  4912. adviceType := int64(2)
  4913. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4914. utils.ErrorLog("advice_date")
  4915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4916. return
  4917. }
  4918. adviceDate, _ := dataBody["advice_date"].(string)
  4919. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4920. AdviceDate := theTime.Unix()
  4921. RecordDate := theTime.Unix()
  4922. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4923. utils.ErrorLog("start_time")
  4924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4925. return
  4926. }
  4927. startTime, _ := dataBody["start_time"].(string)
  4928. if len(startTime) == 0 {
  4929. utils.ErrorLog("len(start_time) == 0")
  4930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4931. return
  4932. }
  4933. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4934. if err != nil {
  4935. utils.ErrorLog(err.Error())
  4936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4937. return
  4938. }
  4939. StartTime := theTime.Unix()
  4940. Remark := ""
  4941. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4942. remark, _ := dataBody["remark"].(string)
  4943. Remark = remark
  4944. }
  4945. var advices []*models.GroupAdvice
  4946. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4947. utils.ErrorLog("advices")
  4948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4949. return
  4950. }
  4951. adviceNames := dataBody["advices"].([]interface{})
  4952. for _, adviceNameMap := range adviceNames {
  4953. adviceNameM := adviceNameMap.(map[string]interface{})
  4954. var advice models.GroupAdvice
  4955. advice.Remark = Remark
  4956. advice.AdviceType = adviceType
  4957. advice.StartTime = StartTime
  4958. advice.AdviceDate = AdviceDate
  4959. advice.RecordDate = RecordDate
  4960. advice.Status = 1
  4961. advice.CreatedTime = time.Now().Unix()
  4962. advice.UpdatedTime = time.Now().Unix()
  4963. advice.StopState = 2
  4964. advice.ExecutionState = 2
  4965. advice.UserOrgId = adminUserInfo.Org.Id
  4966. advice.PatientId = patient
  4967. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4968. advice.IsSettle = 2
  4969. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4970. utils.ErrorLog("advice_name")
  4971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4972. return
  4973. }
  4974. adviceName, _ := adviceNameM["advice_name"].(string)
  4975. if len(adviceName) == 0 {
  4976. utils.ErrorLog("len(advice_name) == 0")
  4977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4978. return
  4979. }
  4980. advice.AdviceName = adviceName
  4981. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4982. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4983. advice.DrugSpec = drugSpec
  4984. }
  4985. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4986. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4987. advice.AdviceDesc = adviceDesc
  4988. }
  4989. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4990. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4991. advice.DrugSpecUnit = drugSpecUnit
  4992. }
  4993. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4994. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4995. // advice.SingleDose = singleDose
  4996. //}
  4997. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4998. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4999. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5000. }
  5001. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5002. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5003. advice.SingleDoseUnit = singleDoseUnit
  5004. }
  5005. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5006. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5007. // advice.PrescribingNumber = prescribingNumber
  5008. //}
  5009. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5010. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5011. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5012. }
  5013. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5014. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5015. advice.PrescribingNumberUnit = prescribingNumberUnit
  5016. }
  5017. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5018. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5019. advice.DeliveryWay = deliveryWay
  5020. }
  5021. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5022. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5023. advice.ExecutionFrequency = executionFrequency
  5024. }
  5025. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5026. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5027. advice.FrequencyType = frequency_type
  5028. }
  5029. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5030. day_count := int64(adviceNameM["day_count"].(float64))
  5031. advice.DayCount = day_count
  5032. }
  5033. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5034. week_day, _ := adviceNameM["week_day"].(string)
  5035. advice.WeekDay = week_day
  5036. }
  5037. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5038. way := int64(adviceNameM["way"].(float64))
  5039. advice.Way = way
  5040. }
  5041. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5042. drug_id := int64(adviceNameM["drug_id"].(float64))
  5043. advice.DrugId = drug_id
  5044. }
  5045. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5046. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5047. advice.DrugNameId = drug_name_id
  5048. }
  5049. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5050. remark, _ := adviceNameM["remark"].(string)
  5051. advice.Remark = remark
  5052. }
  5053. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5054. groupno := int64(adviceNameM["groupno"].(float64))
  5055. advice.GroupNo = groupno
  5056. }
  5057. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5058. template_id, _ := adviceNameM["template_id"].(string)
  5059. advice.TemplateId = template_id
  5060. }
  5061. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5062. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5063. advice.ExecutionFrequency = executionFrequency
  5064. }
  5065. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5066. children := adviceNameM["child"].([]interface{})
  5067. if len(children) > 0 {
  5068. for _, childrenMap := range children {
  5069. childMap := childrenMap.(map[string]interface{})
  5070. var child models.GroupAdvice
  5071. child.Remark = Remark
  5072. child.AdviceType = adviceType
  5073. child.StartTime = StartTime
  5074. child.AdviceDate = AdviceDate
  5075. child.RecordDate = RecordDate
  5076. child.Status = 1
  5077. child.CreatedTime = time.Now().Unix()
  5078. child.UpdatedTime = time.Now().Unix()
  5079. child.StopState = 2
  5080. child.ExecutionState = 2
  5081. child.UserOrgId = adminUserInfo.Org.Id
  5082. child.PatientId = patient
  5083. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5084. child.IsSettle = 1
  5085. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5086. utils.ErrorLog("child advice_name")
  5087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5088. return
  5089. }
  5090. childAdviceName, _ := childMap["advice_name"].(string)
  5091. if len(childAdviceName) == 0 {
  5092. utils.ErrorLog("len(child advice_name) == 0")
  5093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5094. return
  5095. }
  5096. child.AdviceName = childAdviceName
  5097. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5098. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5099. child.AdviceDesc = childAdviceDesc
  5100. }
  5101. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5102. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5103. child.DrugSpec = childDrugSpec
  5104. }
  5105. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5106. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5107. child.DrugSpecUnit = childDrugSpecUnit
  5108. }
  5109. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5110. child.SingleDose = childMap["single_dose"].(float64)
  5111. }
  5112. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5113. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5114. child.SingleDoseUnit = childSingleDoseUnit
  5115. }
  5116. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5117. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5118. }
  5119. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5120. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5121. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5122. }
  5123. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5124. groupno := int64(childMap["groupno"].(float64))
  5125. advice.GroupNo = groupno
  5126. }
  5127. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5128. remark, _ := childMap["remark"].(string)
  5129. child.Remark = remark
  5130. }
  5131. child.DeliveryWay = advice.DeliveryWay
  5132. child.ExecutionFrequency = advice.ExecutionFrequency
  5133. advice.Children = append(advice.Children, &child)
  5134. }
  5135. }
  5136. }
  5137. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5138. if temp_advice.ID == 0 {
  5139. advices = append(advices, &advice)
  5140. }
  5141. }
  5142. if len(advices) > 0 {
  5143. finish := models.XtDialysisFinish{
  5144. IsFinish: 1,
  5145. UserOrgId: adminUserInfo.Org.Id,
  5146. Status: 1,
  5147. Ctime: time.Now().Unix(),
  5148. Mtime: 0,
  5149. Module: 4,
  5150. RecordDate: AdviceDate,
  5151. Sourse: 1,
  5152. PatientId: patient,
  5153. }
  5154. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5155. if dialysisFinish.ID == 0 {
  5156. service.CreateDialysisFinish(finish)
  5157. }
  5158. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5159. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5160. for _, item := range advices {
  5161. byterequest, _ := json.Marshal(item)
  5162. adviceLog := models.XtDoctorAdviceLog{
  5163. UserOrgId: adminUserInfo.Org.Id,
  5164. PatientId: patient,
  5165. AdminUserId: adminUserInfo.AdminUser.Id,
  5166. Module: 1,
  5167. ErrLog: string(byterequest),
  5168. Status: 1,
  5169. Ctime: time.Now().Unix(),
  5170. Mtime: 0,
  5171. Source: "手机端医嘱推送",
  5172. RecordDate: item.AdviceDate,
  5173. }
  5174. service.CreateDoctorAdviceLog(adviceLog)
  5175. }
  5176. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5177. redis := service.RedisClient()
  5178. //清空key 值
  5179. redis.Set(key, "", time.Second)
  5180. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5181. redis.Set(keyOne, "", time.Second)
  5182. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5183. defer redis.Close()
  5184. redis.Set(keyThree, "", time.Second)
  5185. if err != nil {
  5186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5187. return
  5188. }
  5189. c.ServeSuccessJSON(map[string]interface{}{
  5190. "msg": "ok",
  5191. "advices": list,
  5192. })
  5193. } else {
  5194. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5195. for _, item := range advices {
  5196. byterequest, _ := json.Marshal(item)
  5197. adviceLog := models.XtDoctorAdviceLog{
  5198. UserOrgId: adminUserInfo.Org.Id,
  5199. PatientId: patient,
  5200. AdminUserId: adminUserInfo.AdminUser.Id,
  5201. Module: 1,
  5202. ErrLog: string(byterequest),
  5203. Status: 1,
  5204. Ctime: time.Now().Unix(),
  5205. Mtime: 0,
  5206. Source: "手机端医嘱推送",
  5207. RecordDate: item.AdviceDate,
  5208. }
  5209. service.CreateDoctorAdviceLog(adviceLog)
  5210. }
  5211. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5212. redis := service.RedisClient()
  5213. //清空key 值
  5214. redis.Set(key, "", time.Second)
  5215. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5216. redis.Set(keyOne, "", time.Second)
  5217. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5218. defer redis.Close()
  5219. redis.Set(keyThree, "", time.Second)
  5220. if err != nil {
  5221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5222. return
  5223. }
  5224. c.ServeSuccessJSON(map[string]interface{}{
  5225. "msg": "ok",
  5226. "advices": list,
  5227. })
  5228. }
  5229. } else {
  5230. c.ServeSuccessJSON(map[string]interface{}{
  5231. "msg": "ok",
  5232. })
  5233. }
  5234. return
  5235. }
  5236. func (c *DialysisAPIController) UploadDryWeight() {
  5237. patient_id, _ := c.GetInt64("id")
  5238. dry_weight, _ := c.GetFloat("dry_weight")
  5239. doctor_id, _ := c.GetInt64("doctor_id")
  5240. remark := c.GetString("remark")
  5241. adminUserInfo := c.GetMobileAdminUserInfo()
  5242. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5243. if err == gorm.ErrRecordNotFound {
  5244. dryWeight := &models.SgjPatientDryweight{
  5245. PatientId: patient_id,
  5246. DryWeight: dry_weight,
  5247. Remakes: remark,
  5248. Ctime: time.Now().Unix(),
  5249. Mtime: time.Now().Unix(),
  5250. Creator: doctor_id,
  5251. Status: 1,
  5252. UserOrgId: adminUserInfo.Org.Id,
  5253. AdjustedValue: "/",
  5254. UserId: adminUserInfo.AdminUser.Id,
  5255. }
  5256. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5257. redis := service.RedisClient()
  5258. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5259. redis.Set(keyOne, "", time.Second)
  5260. loc, _ := time.LoadLocation("Local")
  5261. nowTime := time.Now()
  5262. nowDay := nowTime.Format("2006-01-02")
  5263. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5264. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5265. redis.Set(key, "", time.Second)
  5266. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5267. redis.Set(keyTwo, "", time.Second)
  5268. redis.Close()
  5269. if createErr == nil {
  5270. c.ServeSuccessJSON(map[string]interface{}{
  5271. "msg": "提交成功",
  5272. "weight": dryWeight,
  5273. })
  5274. }
  5275. } else {
  5276. dryWeight := &models.SgjPatientDryweight{
  5277. PatientId: patient_id,
  5278. DryWeight: dry_weight,
  5279. Remakes: remark,
  5280. Ctime: time.Now().Unix(),
  5281. Mtime: time.Now().Unix(),
  5282. Creator: doctor_id,
  5283. Status: 1,
  5284. UserOrgId: adminUserInfo.Org.Id,
  5285. AdjustedValue: "/",
  5286. UserId: adminUserInfo.AdminUser.Id,
  5287. }
  5288. var value float64
  5289. value = dry_weight - weightAdjust.DryWeight
  5290. if value < 0 {
  5291. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5292. } else if value == 0 {
  5293. dryWeight.AdjustedValue = "/"
  5294. } else if value > 0 {
  5295. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5296. }
  5297. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5298. //康桥
  5299. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 {
  5300. timeNowStr := time.Now().Format("2006-01-02")
  5301. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5302. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5303. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5304. if beforAssesment.ID > 0 {
  5305. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5306. var dewater_amount float64
  5307. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5308. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5309. //获取key,清空redis
  5310. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5311. redis := service.RedisClient()
  5312. //清空key 值
  5313. redis.Set(key, "", time.Second)
  5314. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5315. //清空key 值
  5316. redis.Set(keyOne, "", time.Second)
  5317. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5318. //清空key 值
  5319. redis.Set(keyTwo, "", time.Second)
  5320. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5321. redis.Set(keySix, "", time.Second)
  5322. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5323. redis.Set(keySeven, "", time.Second)
  5324. }
  5325. }
  5326. redis := service.RedisClient()
  5327. loc, _ := time.LoadLocation("Local")
  5328. nowTime := time.Now()
  5329. nowDay := nowTime.Format("2006-01-02")
  5330. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5331. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5332. redis.Set(keyOne, "", time.Second)
  5333. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5334. redis.Set(key, "", time.Second)
  5335. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5336. redis.Set(keyTwo, "", time.Second)
  5337. redis.Close()
  5338. if createErr == nil {
  5339. c.ServeSuccessJSON(map[string]interface{}{
  5340. "msg": "提交成功",
  5341. "weight": dryWeight,
  5342. })
  5343. }
  5344. }
  5345. }
  5346. func (c *DialysisAPIController) GetSolution() {
  5347. patient_id, _ := c.GetInt64("patient_id")
  5348. mode_id, _ := c.GetInt64("mode_id")
  5349. adminUserInfo := c.GetMobileAdminUserInfo()
  5350. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5351. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5352. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5353. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5354. if err != nil {
  5355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5356. return
  5357. }
  5358. c.ServeSuccessJSON(map[string]interface{}{
  5359. "solution": solution,
  5360. "prescription": prescription,
  5361. "system_prescription": system_prescription,
  5362. "dialysisPrescription": dialysisPrescription,
  5363. })
  5364. }
  5365. func (c *DialysisAPIController) GetSchedule() {
  5366. schedual_type, _ := c.GetInt64("schedual_type")
  5367. adminUserInfo := c.GetMobileAdminUserInfo()
  5368. scheduleTime, _ := c.GetInt64("record_date")
  5369. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5370. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5371. c.ServeSuccessJSON(map[string]interface{}{
  5372. "number": deviceNumber,
  5373. "list": list,
  5374. })
  5375. }
  5376. func (c *DialysisAPIController) GetPatientId() {
  5377. id, _ := c.GetInt64("id")
  5378. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5379. patientId, _ := service.GetPatientId(id)
  5380. //获取该患者的所有传染病
  5381. list, _ := service.GetPatientInfectious(id)
  5382. c.ServeSuccessJSON(map[string]interface{}{
  5383. "patient": patientId,
  5384. "infectioulist": list,
  5385. })
  5386. }
  5387. func (this *DialysisAPIController) GetDialysisSchedule() {
  5388. schedualDate := this.GetString("date")
  5389. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5390. if parseDateErr != nil {
  5391. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5392. return
  5393. }
  5394. adminInfo := this.GetMobileAdminUserInfo()
  5395. orgID := adminInfo.Org.Id
  5396. redis := service.RedisClient()
  5397. defer redis.Close()
  5398. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5399. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5400. if len(scheduals) > 0 {
  5401. //缓存数据
  5402. scheduals_json, err := json.Marshal(scheduals)
  5403. if err == nil {
  5404. redis.Set(key, scheduals_json, time.Second*30)
  5405. }
  5406. }
  5407. this.ServeSuccessJSON(map[string]interface{}{
  5408. "scheduals": scheduals,
  5409. })
  5410. }
  5411. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5412. change_type, _ := this.GetInt64("type", 0)
  5413. record_date := this.GetString("record_time")
  5414. patient_id, _ := this.GetInt64("patient_id", 0)
  5415. timeLayout := "2006-01-02"
  5416. loc, _ := time.LoadLocation("Local")
  5417. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5418. record_time := theAdviceRecordTime.Unix()
  5419. adminUserInfo := this.GetMobileAdminUserInfo()
  5420. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5421. if err == nil {
  5422. if len(advices) == 0 {
  5423. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5424. return
  5425. } else {
  5426. this.ServeSuccessJSON(map[string]interface{}{
  5427. "advices": advices,
  5428. "schedule": sch,
  5429. })
  5430. return
  5431. }
  5432. } else {
  5433. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5434. return
  5435. }
  5436. }
  5437. func (c *DialysisAPIController) CreateConsumables() {
  5438. record_date := c.GetString("record_time")
  5439. patient_id, _ := c.GetInt64("patient_id", 0)
  5440. active, _ := c.GetInt64("active")
  5441. adminUser := c.GetMobileAdminUserInfo()
  5442. timeLayout := "2006-01-02"
  5443. loc, _ := time.LoadLocation("Local")
  5444. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5445. record_time := theRecordTime.Unix()
  5446. // 查询信息规挡的设置天数
  5447. orgid := c.GetMobileAdminUserInfo().Org.Id
  5448. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5449. if infor.ID > 0 {
  5450. var cha_time int64
  5451. timeNowStr := time.Now().Format("2006-01-02")
  5452. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5453. //今日的日期减去设置的日期
  5454. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5455. if cha_time >= record_time {
  5456. //查询审核是否允许
  5457. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5458. //申请状态不允许的情况 拒绝修改
  5459. if infor.ApplicationStatus != 1 {
  5460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5461. return
  5462. }
  5463. }
  5464. }
  5465. dataBody := make(map[string]interface{}, 0)
  5466. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5467. if err != nil {
  5468. utils.ErrorLog(err.Error())
  5469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5470. return
  5471. }
  5472. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5473. var beforePrepares []*models.DialysisBeforePrepareGoods
  5474. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5475. var dialysisBefor []*models.DialysisBeforePrepare
  5476. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5477. goods, _ := dataBody["goods"].([]interface{})
  5478. if len(goods) > 0 {
  5479. for _, item := range goods {
  5480. items := item.(map[string]interface{})
  5481. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5482. utils.ErrorLog("good_id")
  5483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5484. return
  5485. }
  5486. good_id := int64(items["good_id"].(float64))
  5487. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5488. utils.ErrorLog("good_type_id")
  5489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5490. return
  5491. }
  5492. good_type_id := int64(items["good_type_id"].(float64))
  5493. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5494. utils.ErrorLog("count")
  5495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5496. return
  5497. }
  5498. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5499. commdity_code := items["commdity_code"].(string)
  5500. fmt.Println("commdity", commdity_code)
  5501. prepareGoods := &models.DialysisBeforePrepareGoods{
  5502. GoodTypeId: good_type_id,
  5503. GoodId: good_id,
  5504. Count: count,
  5505. StorehouseId: houseConfig.StorehouseOutInfo,
  5506. }
  5507. beforePrepares = append(beforePrepares, prepareGoods)
  5508. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5509. GoodTypeId: good_type_id,
  5510. GoodId: good_id,
  5511. Count: count,
  5512. StorehouseId: houseConfig.StorehouseOutInfo,
  5513. }
  5514. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5515. prepare := &models.DialysisBeforePrepare{
  5516. GoodTypeId: good_type_id,
  5517. GoodId: good_id,
  5518. Count: count,
  5519. PatientId: patient_id,
  5520. RecordDate: record_time,
  5521. UserOrgId: adminUser.Org.Id,
  5522. Status: 1,
  5523. Ctime: time.Now().Unix(),
  5524. Creater: adminUser.AdminUser.Id,
  5525. CommdityCode: commdity_code,
  5526. StorehouseId: houseConfig.StorehouseOutInfo,
  5527. }
  5528. dialysisBefor = append(dialysisBefor, prepare)
  5529. }
  5530. }
  5531. //查询是否有库存
  5532. for _, item := range dialysisBefor {
  5533. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5534. if err == gorm.ErrRecordNotFound {
  5535. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5536. c.ServeSuccessJSON(map[string]interface{}{
  5537. "message": "1",
  5538. "good_name": goodObj.GoodName,
  5539. "specification_name": goodObj.SpecificationName,
  5540. })
  5541. return
  5542. }
  5543. if err != nil {
  5544. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5545. c.ServeSuccessJSON(map[string]interface{}{
  5546. "message": "1",
  5547. "good_name": goodObj.GoodName,
  5548. "specification_name": goodObj.SpecificationName,
  5549. })
  5550. return
  5551. }
  5552. }
  5553. //新增
  5554. if active == 1 && len(goods) > 0 {
  5555. for _, item := range dialysisBefor {
  5556. dialyPrepareOne := models.DialysisBeforePrepare{
  5557. GoodTypeId: item.GoodTypeId,
  5558. GoodId: item.GoodId,
  5559. PatientId: item.PatientId,
  5560. RecordDate: item.RecordDate,
  5561. UserOrgId: item.UserOrgId,
  5562. Count: item.Count,
  5563. Ctime: time.Now().Unix(),
  5564. Creater: item.Creater,
  5565. CommdityCode: item.CommdityCode,
  5566. Status: 1,
  5567. StorehouseId: houseConfig.StorehouseOutInfo,
  5568. }
  5569. //先清除再插入
  5570. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5571. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5572. //查询默认仓库
  5573. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5574. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5575. var total_count int64
  5576. for _, it := range stockList {
  5577. total_count += it.StockCount
  5578. }
  5579. //基础库插入数据
  5580. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5581. //更新库存
  5582. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5583. var flush_count int64
  5584. for _, it := range goodList {
  5585. flush_count += it.StockCount
  5586. }
  5587. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5588. }
  5589. if err == nil {
  5590. c.ServeSuccessJSON(map[string]interface{}{
  5591. "msg": "保存成功",
  5592. "message": "2",
  5593. })
  5594. return
  5595. } else {
  5596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5597. return
  5598. }
  5599. }
  5600. if len(beforePrepares) > 0 && active == 2 {
  5601. for _, item := range beforePrepares {
  5602. //1.查看该患者该耗材型号最后一次出库数量
  5603. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5604. //判断当前出库数量和最后一次出库数量的大小
  5605. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5606. if item.Count <= goodInfo.Count {
  5607. //退库
  5608. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5609. //查询今日出库数据
  5610. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5611. for _, it := range list {
  5612. prepare := models.DialysisBeforePrepare{
  5613. UserOrgId: it.OrgId,
  5614. PatientId: patient_id,
  5615. RecordDate: it.RecordTime,
  5616. GoodId: it.GoodId,
  5617. GoodTypeId: it.GoodTypeId,
  5618. Count: it.Count,
  5619. Ctime: time.Now().Unix(),
  5620. Creater: adminUser.AdminUser.Id,
  5621. Status: 1,
  5622. StorehouseId: houseConfig.StorehouseOutInfo,
  5623. }
  5624. //删除准备表数据
  5625. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5626. service.CreateDialysisBeforePrepareOne(&prepare)
  5627. }
  5628. }
  5629. var last_total int64
  5630. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5631. if item.Count >= goodInfo.Count {
  5632. //查询当前批次当前耗材最后一条出库数据
  5633. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5634. //计算当前出库和最后一次出库数据相差数据
  5635. last_total = item.Count - lastOutInfo.Count
  5636. //查询该批次剩余库存
  5637. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5638. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5639. if lastInfo.StockCount >= last_total {
  5640. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5641. //查询今日出库数据
  5642. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5643. for _, it := range list {
  5644. prepare := models.DialysisBeforePrepare{
  5645. UserOrgId: it.OrgId,
  5646. PatientId: patient_id,
  5647. RecordDate: it.RecordTime,
  5648. GoodId: it.GoodId,
  5649. GoodTypeId: it.GoodTypeId,
  5650. Count: it.Count,
  5651. Ctime: time.Now().Unix(),
  5652. Creater: adminUser.AdminUser.Id,
  5653. Status: 1,
  5654. StorehouseId: houseConfig.StorehouseOutInfo,
  5655. }
  5656. //删除准备表数据
  5657. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5658. service.CreateDialysisBeforePrepareOne(&prepare)
  5659. //查询默认仓库
  5660. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5661. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5662. var total_count int64
  5663. for _, it := range stockList {
  5664. total_count += it.StockCount
  5665. }
  5666. //基础库插入数据
  5667. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5668. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5669. var flush_count int64
  5670. for _, it := range goodList {
  5671. flush_count += it.StockCount
  5672. }
  5673. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5674. }
  5675. }
  5676. //如果库存不够,则出库到下一个批次
  5677. if lastInfo.StockCount < last_total {
  5678. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5679. //查询今日出库数据
  5680. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5681. for _, it := range list {
  5682. prepare := models.DialysisBeforePrepare{
  5683. UserOrgId: it.OrgId,
  5684. PatientId: patient_id,
  5685. RecordDate: it.RecordTime,
  5686. GoodId: it.GoodId,
  5687. GoodTypeId: it.GoodTypeId,
  5688. Count: it.Count,
  5689. Ctime: time.Now().Unix(),
  5690. Creater: adminUser.AdminUser.Id,
  5691. Status: 1,
  5692. StorehouseId: houseConfig.StorehouseOutInfo,
  5693. }
  5694. //删除准备表数据
  5695. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5696. service.CreateDialysisBeforePrepareOne(&prepare)
  5697. //查询默认仓库
  5698. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5699. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5700. var total_count int64
  5701. for _, it := range stockList {
  5702. total_count += it.StockCount
  5703. }
  5704. //基础库插入数据
  5705. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5706. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5707. var flush_count int64
  5708. for _, it := range goodList {
  5709. flush_count += it.StockCount
  5710. }
  5711. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5712. }
  5713. if err != nil {
  5714. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5715. c.ServeSuccessJSON(map[string]interface{}{
  5716. "message": "1",
  5717. "good_name": goodObj.GoodName,
  5718. "specification_name": goodObj.SpecificationName,
  5719. })
  5720. return
  5721. }
  5722. }
  5723. }
  5724. if err != nil {
  5725. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5726. c.ServeSuccessJSON(map[string]interface{}{
  5727. "message": "1",
  5728. "good_name": goodObj.GoodName,
  5729. "specification_name": goodObj.SpecificationName,
  5730. })
  5731. return
  5732. }
  5733. }
  5734. }
  5735. }
  5736. var errs error
  5737. if errs == nil {
  5738. c.ServeSuccessJSON(map[string]interface{}{
  5739. "msg": "提交成功",
  5740. "message": "2",
  5741. "good_name": "",
  5742. "specification_name": "",
  5743. })
  5744. return
  5745. } else {
  5746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5747. return
  5748. }
  5749. }
  5750. func (c *DialysisAPIController) CreateStockOutInfo() {
  5751. patient_id, _ := c.GetInt64("patient_id", 0)
  5752. record_date := c.GetString("record_time")
  5753. if patient_id <= 0 {
  5754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5755. return
  5756. }
  5757. adminInfo := c.GetMobileAdminUserInfo()
  5758. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5759. timeLayout := "2006-01-02"
  5760. loc, _ := time.LoadLocation("Local")
  5761. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5762. record_time := theRecordTime.Unix()
  5763. // 查询信息规挡的设置天数
  5764. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5765. if infor.ID > 0 && infor.WeekDay > 0 {
  5766. var cha_time int64
  5767. timeNowStr := time.Now().Format("2006-01-02")
  5768. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5769. //今日的日期减去设置的日期
  5770. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5771. if cha_time >= record_time {
  5772. //查询审核是否允许
  5773. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5774. //申请状态不允许的情况 拒绝修改
  5775. if infor.ApplicationStatus != 1 {
  5776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5777. return
  5778. }
  5779. }
  5780. }
  5781. //创建步骤表
  5782. finish := models.XtDialysisFinish{
  5783. IsFinish: 1,
  5784. UserOrgId: adminInfo.Org.Id,
  5785. Status: 1,
  5786. Ctime: time.Now().Unix(),
  5787. Mtime: 0,
  5788. Module: 11,
  5789. RecordDate: record_time,
  5790. Sourse: 1,
  5791. PatientId: patient_id,
  5792. }
  5793. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5794. if dialysisFinish.ID == 0 {
  5795. service.CreateDialysisFinish(finish)
  5796. }
  5797. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5798. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5799. //去重
  5800. consumables = RemoveRepeatedGood(consumables)
  5801. if adminInfo.Org.Id == 9919 {
  5802. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5803. //查询是否有库存
  5804. for _, item := range consumables {
  5805. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5806. if item.Count > warehouse.Count {
  5807. goodErrcode := models.XtGoodErrcode{
  5808. UserOrgId: item.UserOrgId,
  5809. Errcode: "自动出库库存不足",
  5810. GoodId: item.GoodId,
  5811. Status: 1,
  5812. Ctime: time.Now().Unix(),
  5813. Mtime: 0,
  5814. Count: 0,
  5815. StockCount: 0,
  5816. Creater: creator,
  5817. BatchNumberId: warehouse.ID,
  5818. WarehouseOutId: 0,
  5819. }
  5820. service.CreateGoodErrcode(goodErrcode)
  5821. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5822. c.ServeSuccessJSON(map[string]interface{}{
  5823. "message": "1",
  5824. "good_name": goodObj.GoodName,
  5825. "specification_name": goodObj.SpecificationName,
  5826. })
  5827. return
  5828. }
  5829. }
  5830. //查询是否有出库单
  5831. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5832. if err == gorm.ErrRecordNotFound {
  5833. //没有记录,则创建出库单
  5834. timeStr := time.Now().Format("2006-01-02")
  5835. timeArr := strings.Split(timeStr, "-")
  5836. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5837. total = total + 1
  5838. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5839. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5840. number = number + total
  5841. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5842. creater := adminInfo.AdminUser.Id
  5843. warehouseOut := models.WarehouseOut{
  5844. WarehouseOutOrderNumber: warehousing_out_order,
  5845. OperationTime: time.Now().Unix(),
  5846. OrgId: adminInfo.Org.Id,
  5847. Creater: creater,
  5848. Ctime: time.Now().Unix(),
  5849. Status: 1,
  5850. WarehouseOutTime: record_time,
  5851. Dealer: 0,
  5852. Manufacturer: 0,
  5853. Type: 1,
  5854. IsSys: 1,
  5855. StorehouseId: houseConfig.StorehouseOutInfo,
  5856. IsCheck: 1,
  5857. }
  5858. err := service.AddSigleWarehouseOut(&warehouseOut)
  5859. if err != nil {
  5860. goodErrcode := models.XtGoodErrcode{
  5861. UserOrgId: adminInfo.Org.Id,
  5862. Errcode: "创建出库单失败",
  5863. GoodId: 0,
  5864. Status: 1,
  5865. Ctime: time.Now().Unix(),
  5866. Mtime: 0,
  5867. Count: 0,
  5868. StockCount: 0,
  5869. Creater: creator,
  5870. BatchNumberId: 0,
  5871. WarehouseOutId: 0,
  5872. }
  5873. service.CreateGoodErrcode(goodErrcode)
  5874. utils.TraceLog("创建出库单失败 err = %v", err)
  5875. } else {
  5876. for _, item := range consumables {
  5877. //出库
  5878. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5879. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5880. if err == nil {
  5881. goodErrcode := models.XtGoodErrcode{
  5882. UserOrgId: adminInfo.Org.Id,
  5883. Errcode: "自动出库接口报错",
  5884. GoodId: 0,
  5885. Status: 1,
  5886. Ctime: time.Now().Unix(),
  5887. Mtime: 0,
  5888. Count: 0,
  5889. StockCount: 0,
  5890. Creater: creator,
  5891. BatchNumberId: 0,
  5892. WarehouseOutId: 0,
  5893. }
  5894. service.CreateGoodErrcode(goodErrcode)
  5895. utils.TraceLog("创建出库单失败 err = %v", err)
  5896. }
  5897. //查询
  5898. //出库数量相加
  5899. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5900. if errs != nil {
  5901. goodErrcode := models.XtGoodErrcode{
  5902. UserOrgId: item.UserOrgId,
  5903. Errcode: "创建剩余库存字段报错",
  5904. GoodId: item.GoodId,
  5905. Status: 1,
  5906. Ctime: time.Now().Unix(),
  5907. Mtime: 0,
  5908. Count: 0,
  5909. StockCount: 0,
  5910. Creater: creater,
  5911. BatchNumberId: 0,
  5912. WarehouseOutId: 0,
  5913. }
  5914. service.CreateGoodErrcode(goodErrcode)
  5915. }
  5916. }
  5917. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5918. if len(list) == 0 {
  5919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5920. return
  5921. }
  5922. for _, item := range list {
  5923. prepare := models.DialysisBeforePrepare{
  5924. UserOrgId: adminInfo.Org.Id,
  5925. PatientId: patient_id,
  5926. RecordDate: record_time,
  5927. GoodId: item.GoodId,
  5928. GoodTypeId: item.GoodTypeId,
  5929. Count: item.Count,
  5930. Creater: adminInfo.AdminUser.Id,
  5931. Status: 1,
  5932. Ctime: time.Now().Unix(),
  5933. StorehouseId: houseConfig.StorehouseOutInfo,
  5934. }
  5935. //清空准备表数据
  5936. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5937. if err != nil {
  5938. goodErrcode := models.XtGoodErrcode{
  5939. UserOrgId: item.OrgId,
  5940. Errcode: "自动出库清空准备表数据报错",
  5941. GoodId: item.GoodId,
  5942. Status: 1,
  5943. Ctime: time.Now().Unix(),
  5944. Mtime: 0,
  5945. Count: 0,
  5946. StockCount: 0,
  5947. Creater: creater,
  5948. BatchNumberId: 0,
  5949. WarehouseOutId: 0,
  5950. }
  5951. service.CreateGoodErrcode(goodErrcode)
  5952. }
  5953. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5954. if errs != nil {
  5955. goodErrcode := models.XtGoodErrcode{
  5956. UserOrgId: item.OrgId,
  5957. Errcode: "自动出库创建准备表数据报错",
  5958. GoodId: item.GoodId,
  5959. Status: 1,
  5960. Ctime: time.Now().Unix(),
  5961. Mtime: 0,
  5962. Count: 0,
  5963. StockCount: 0,
  5964. Creater: creater,
  5965. BatchNumberId: 0,
  5966. WarehouseOutId: 0,
  5967. }
  5968. service.CreateGoodErrcode(goodErrcode)
  5969. }
  5970. //查询默认仓库
  5971. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5972. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5973. var total_count int64
  5974. for _, it := range stockList {
  5975. total_count += it.StockCount
  5976. }
  5977. //基础库插入数据
  5978. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5979. if errcodes != nil {
  5980. goodErrcode := models.XtGoodErrcode{
  5981. UserOrgId: item.OrgId,
  5982. Errcode: "自动出库基础库插入数据",
  5983. GoodId: item.GoodId,
  5984. Status: 1,
  5985. Ctime: time.Now().Unix(),
  5986. Mtime: 0,
  5987. Count: 0,
  5988. StockCount: 0,
  5989. Creater: creater,
  5990. BatchNumberId: 0,
  5991. WarehouseOutId: 0,
  5992. }
  5993. service.CreateGoodErrcode(goodErrcode)
  5994. }
  5995. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5996. var flush_count int64
  5997. for _, it := range goodList {
  5998. flush_count += it.StockCount
  5999. }
  6000. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6001. if errsss != nil {
  6002. goodErrcode := models.XtGoodErrcode{
  6003. UserOrgId: item.OrgId,
  6004. Errcode: "自动出库剩余库存更新数据",
  6005. GoodId: item.GoodId,
  6006. Status: 1,
  6007. Ctime: time.Now().Unix(),
  6008. Mtime: 0,
  6009. Count: 0,
  6010. StockCount: 0,
  6011. Creater: creater,
  6012. BatchNumberId: 0,
  6013. WarehouseOutId: 0,
  6014. }
  6015. service.CreateGoodErrcode(goodErrcode)
  6016. }
  6017. }
  6018. }
  6019. //
  6020. } else if err == nil {
  6021. for _, item := range consumables {
  6022. //出库
  6023. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6024. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6025. if err != nil {
  6026. goodErrcode := models.XtGoodErrcode{
  6027. UserOrgId: adminInfo.Org.Id,
  6028. Errcode: "自动出库接口报错",
  6029. GoodId: 0,
  6030. Status: 1,
  6031. Ctime: time.Now().Unix(),
  6032. Mtime: 0,
  6033. Count: 0,
  6034. StockCount: 0,
  6035. Creater: creator,
  6036. BatchNumberId: 0,
  6037. WarehouseOutId: 0,
  6038. }
  6039. service.CreateGoodErrcode(goodErrcode)
  6040. }
  6041. //出库数量相加
  6042. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6043. if errss != nil {
  6044. goodErrcode := models.XtGoodErrcode{
  6045. UserOrgId: item.UserOrgId,
  6046. Errcode: "创建剩余库存字段报错",
  6047. GoodId: item.GoodId,
  6048. Status: 1,
  6049. Ctime: time.Now().Unix(),
  6050. Mtime: time.Now().Unix(),
  6051. Count: 0,
  6052. StockCount: 0,
  6053. Creater: item.Creater,
  6054. BatchNumberId: 0,
  6055. WarehouseOutId: 0,
  6056. }
  6057. service.CreateGoodErrcode(goodErrcode)
  6058. }
  6059. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6060. if len(list) == 0 {
  6061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6062. return
  6063. }
  6064. for _, item := range list {
  6065. prepare := models.DialysisBeforePrepare{
  6066. UserOrgId: adminInfo.Org.Id,
  6067. PatientId: patient_id,
  6068. RecordDate: record_time,
  6069. GoodId: item.GoodId,
  6070. GoodTypeId: item.GoodTypeId,
  6071. Count: item.Count,
  6072. Creater: adminInfo.AdminUser.Id,
  6073. Status: 1,
  6074. Ctime: time.Now().Unix(),
  6075. StorehouseId: houseConfig.StorehouseOutInfo,
  6076. }
  6077. //清空准备表数据
  6078. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6079. if errs != nil {
  6080. goodErrcode := models.XtGoodErrcode{
  6081. UserOrgId: adminInfo.Org.Id,
  6082. Errcode: "自动出库清空准备表数据报错",
  6083. GoodId: 0,
  6084. Status: 1,
  6085. Ctime: time.Now().Unix(),
  6086. Mtime: 0,
  6087. Count: 0,
  6088. StockCount: 0,
  6089. Creater: creator,
  6090. BatchNumberId: 0,
  6091. WarehouseOutId: 0,
  6092. }
  6093. service.CreateGoodErrcode(goodErrcode)
  6094. }
  6095. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6096. if errcodes != nil {
  6097. goodErrcode := models.XtGoodErrcode{
  6098. UserOrgId: adminInfo.Org.Id,
  6099. Errcode: "自动出库创建准备表数据报错",
  6100. GoodId: 0,
  6101. Status: 1,
  6102. Ctime: time.Now().Unix(),
  6103. Mtime: 0,
  6104. Count: 0,
  6105. StockCount: 0,
  6106. Creater: creator,
  6107. BatchNumberId: 0,
  6108. WarehouseOutId: 0,
  6109. }
  6110. service.CreateGoodErrcode(goodErrcode)
  6111. }
  6112. //查询默认仓库
  6113. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6114. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6115. var total_count int64
  6116. for _, it := range stockList {
  6117. total_count += it.StockCount
  6118. }
  6119. //基础库插入数据
  6120. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6121. if errcodes != nil {
  6122. goodErrcode := models.XtGoodErrcode{
  6123. UserOrgId: adminInfo.Org.Id,
  6124. Errcode: "自动出库基础库插入数据报错",
  6125. GoodId: 0,
  6126. Status: 1,
  6127. Ctime: time.Now().Unix(),
  6128. Mtime: 0,
  6129. Count: 0,
  6130. StockCount: 0,
  6131. Creater: creator,
  6132. BatchNumberId: 0,
  6133. WarehouseOutId: 0,
  6134. }
  6135. service.CreateGoodErrcode(goodErrcode)
  6136. }
  6137. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6138. var flush_count int64
  6139. for _, it := range goodList {
  6140. flush_count += it.StockCount
  6141. }
  6142. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6143. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6144. if errss != nil {
  6145. goodErrcode := models.XtGoodErrcode{
  6146. UserOrgId: item.OrgId,
  6147. Errcode: "自动出库剩余库存更新数据",
  6148. GoodId: item.GoodId,
  6149. Status: 1,
  6150. Ctime: time.Now().Unix(),
  6151. Mtime: 0,
  6152. Count: 0,
  6153. StockCount: 0,
  6154. Creater: creater,
  6155. BatchNumberId: 0,
  6156. WarehouseOutId: 0,
  6157. }
  6158. service.CreateGoodErrcode(goodErrcode)
  6159. }
  6160. }
  6161. }
  6162. }
  6163. c.ServeSuccessJSON(map[string]interface{}{
  6164. "msg": "提交成功",
  6165. "message": "2",
  6166. "good_name": "",
  6167. "specification_name": "",
  6168. })
  6169. return
  6170. }
  6171. if record.IsOpen == 1 {
  6172. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6173. //查询是否有库存
  6174. for _, item := range consumables {
  6175. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6176. if item.Count > warehouse.Count {
  6177. goodErrcode := models.XtGoodErrcode{
  6178. UserOrgId: item.UserOrgId,
  6179. Errcode: "自动出库库存不足",
  6180. GoodId: item.GoodId,
  6181. Status: 1,
  6182. Ctime: time.Now().Unix(),
  6183. Mtime: 0,
  6184. Count: 0,
  6185. StockCount: 0,
  6186. Creater: creator,
  6187. BatchNumberId: warehouse.ID,
  6188. WarehouseOutId: 0,
  6189. }
  6190. service.CreateGoodErrcode(goodErrcode)
  6191. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6192. c.ServeSuccessJSON(map[string]interface{}{
  6193. "message": "1",
  6194. "good_name": goodObj.GoodName,
  6195. "specification_name": goodObj.SpecificationName,
  6196. })
  6197. return
  6198. }
  6199. }
  6200. //查询是否有出库单
  6201. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6202. if err == gorm.ErrRecordNotFound {
  6203. //没有记录,则创建出库单
  6204. timeStr := time.Now().Format("2006-01-02")
  6205. timeArr := strings.Split(timeStr, "-")
  6206. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6207. total = total + 1
  6208. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6209. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6210. number = number + total
  6211. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6212. creater := adminInfo.AdminUser.Id
  6213. warehouseOut := models.WarehouseOut{
  6214. WarehouseOutOrderNumber: warehousing_out_order,
  6215. OperationTime: time.Now().Unix(),
  6216. OrgId: adminInfo.Org.Id,
  6217. Creater: creater,
  6218. Ctime: time.Now().Unix(),
  6219. Status: 1,
  6220. WarehouseOutTime: record_time,
  6221. Dealer: 0,
  6222. Manufacturer: 0,
  6223. Type: 1,
  6224. IsSys: 1,
  6225. StorehouseId: houseConfig.StorehouseOutInfo,
  6226. IsCheck: 1,
  6227. }
  6228. err := service.AddSigleWarehouseOut(&warehouseOut)
  6229. if err != nil {
  6230. goodErrcode := models.XtGoodErrcode{
  6231. UserOrgId: adminInfo.Org.Id,
  6232. Errcode: "创建出库单失败",
  6233. GoodId: 0,
  6234. Status: 1,
  6235. Ctime: time.Now().Unix(),
  6236. Mtime: 0,
  6237. Count: 0,
  6238. StockCount: 0,
  6239. Creater: creator,
  6240. BatchNumberId: 0,
  6241. WarehouseOutId: 0,
  6242. }
  6243. service.CreateGoodErrcode(goodErrcode)
  6244. utils.TraceLog("创建出库单失败 err = %v", err)
  6245. } else {
  6246. for _, item := range consumables {
  6247. //出库
  6248. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6249. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6250. if err == nil {
  6251. goodErrcode := models.XtGoodErrcode{
  6252. UserOrgId: adminInfo.Org.Id,
  6253. Errcode: "自动出库接口报错",
  6254. GoodId: 0,
  6255. Status: 1,
  6256. Ctime: time.Now().Unix(),
  6257. Mtime: 0,
  6258. Count: 0,
  6259. StockCount: 0,
  6260. Creater: creator,
  6261. BatchNumberId: 0,
  6262. WarehouseOutId: 0,
  6263. }
  6264. service.CreateGoodErrcode(goodErrcode)
  6265. utils.TraceLog("创建出库单失败 err = %v", err)
  6266. }
  6267. //查询
  6268. //出库数量相加
  6269. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6270. if errs != nil {
  6271. goodErrcode := models.XtGoodErrcode{
  6272. UserOrgId: item.UserOrgId,
  6273. Errcode: "创建剩余库存字段报错",
  6274. GoodId: item.GoodId,
  6275. Status: 1,
  6276. Ctime: time.Now().Unix(),
  6277. Mtime: 0,
  6278. Count: 0,
  6279. StockCount: 0,
  6280. Creater: creater,
  6281. BatchNumberId: 0,
  6282. WarehouseOutId: 0,
  6283. }
  6284. service.CreateGoodErrcode(goodErrcode)
  6285. }
  6286. }
  6287. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6288. if len(list) == 0 {
  6289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6290. return
  6291. }
  6292. for _, item := range list {
  6293. prepare := models.DialysisBeforePrepare{
  6294. UserOrgId: adminInfo.Org.Id,
  6295. PatientId: patient_id,
  6296. RecordDate: record_time,
  6297. GoodId: item.GoodId,
  6298. GoodTypeId: item.GoodTypeId,
  6299. Count: item.Count,
  6300. Creater: adminInfo.AdminUser.Id,
  6301. Status: 1,
  6302. Ctime: time.Now().Unix(),
  6303. StorehouseId: houseConfig.StorehouseOutInfo,
  6304. }
  6305. //清空准备表数据
  6306. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6307. if err != nil {
  6308. goodErrcode := models.XtGoodErrcode{
  6309. UserOrgId: item.OrgId,
  6310. Errcode: "自动出库清空准备表数据报错",
  6311. GoodId: item.GoodId,
  6312. Status: 1,
  6313. Ctime: time.Now().Unix(),
  6314. Mtime: 0,
  6315. Count: 0,
  6316. StockCount: 0,
  6317. Creater: creater,
  6318. BatchNumberId: 0,
  6319. WarehouseOutId: 0,
  6320. }
  6321. service.CreateGoodErrcode(goodErrcode)
  6322. }
  6323. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6324. if errs != nil {
  6325. goodErrcode := models.XtGoodErrcode{
  6326. UserOrgId: item.OrgId,
  6327. Errcode: "自动出库创建准备表数据报错",
  6328. GoodId: item.GoodId,
  6329. Status: 1,
  6330. Ctime: time.Now().Unix(),
  6331. Mtime: 0,
  6332. Count: 0,
  6333. StockCount: 0,
  6334. Creater: creater,
  6335. BatchNumberId: 0,
  6336. WarehouseOutId: 0,
  6337. }
  6338. service.CreateGoodErrcode(goodErrcode)
  6339. }
  6340. //查询默认仓库
  6341. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6342. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6343. var total_count int64
  6344. for _, it := range stockList {
  6345. total_count += it.StockCount
  6346. }
  6347. //基础库插入数据
  6348. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6349. if errcodes != nil {
  6350. goodErrcode := models.XtGoodErrcode{
  6351. UserOrgId: item.OrgId,
  6352. Errcode: "自动出库基础库插入数据",
  6353. GoodId: item.GoodId,
  6354. Status: 1,
  6355. Ctime: time.Now().Unix(),
  6356. Mtime: 0,
  6357. Count: 0,
  6358. StockCount: 0,
  6359. Creater: creater,
  6360. BatchNumberId: 0,
  6361. WarehouseOutId: 0,
  6362. }
  6363. service.CreateGoodErrcode(goodErrcode)
  6364. }
  6365. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6366. var flush_count int64
  6367. for _, it := range goodList {
  6368. flush_count += it.StockCount
  6369. }
  6370. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6371. if errsss != nil {
  6372. goodErrcode := models.XtGoodErrcode{
  6373. UserOrgId: item.OrgId,
  6374. Errcode: "自动出库剩余库存更新数据",
  6375. GoodId: item.GoodId,
  6376. Status: 1,
  6377. Ctime: time.Now().Unix(),
  6378. Mtime: 0,
  6379. Count: 0,
  6380. StockCount: 0,
  6381. Creater: creater,
  6382. BatchNumberId: 0,
  6383. WarehouseOutId: 0,
  6384. }
  6385. service.CreateGoodErrcode(goodErrcode)
  6386. }
  6387. }
  6388. }
  6389. //
  6390. } else if err == nil {
  6391. for _, item := range consumables {
  6392. //出库
  6393. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6394. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6395. if err != nil {
  6396. goodErrcode := models.XtGoodErrcode{
  6397. UserOrgId: adminInfo.Org.Id,
  6398. Errcode: "自动出库接口报错",
  6399. GoodId: 0,
  6400. Status: 1,
  6401. Ctime: time.Now().Unix(),
  6402. Mtime: 0,
  6403. Count: 0,
  6404. StockCount: 0,
  6405. Creater: creator,
  6406. BatchNumberId: 0,
  6407. WarehouseOutId: 0,
  6408. }
  6409. service.CreateGoodErrcode(goodErrcode)
  6410. }
  6411. //出库数量相加
  6412. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6413. if errss != nil {
  6414. goodErrcode := models.XtGoodErrcode{
  6415. UserOrgId: item.UserOrgId,
  6416. Errcode: "创建剩余库存字段报错",
  6417. GoodId: item.GoodId,
  6418. Status: 1,
  6419. Ctime: time.Now().Unix(),
  6420. Mtime: time.Now().Unix(),
  6421. Count: 0,
  6422. StockCount: 0,
  6423. Creater: item.Creater,
  6424. BatchNumberId: 0,
  6425. WarehouseOutId: 0,
  6426. }
  6427. service.CreateGoodErrcode(goodErrcode)
  6428. }
  6429. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6430. if len(list) == 0 {
  6431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6432. return
  6433. }
  6434. for _, item := range list {
  6435. prepare := models.DialysisBeforePrepare{
  6436. UserOrgId: adminInfo.Org.Id,
  6437. PatientId: patient_id,
  6438. RecordDate: record_time,
  6439. GoodId: item.GoodId,
  6440. GoodTypeId: item.GoodTypeId,
  6441. Count: item.Count,
  6442. Creater: adminInfo.AdminUser.Id,
  6443. Status: 1,
  6444. Ctime: time.Now().Unix(),
  6445. StorehouseId: houseConfig.StorehouseOutInfo,
  6446. }
  6447. //清空准备表数据
  6448. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6449. if errs != nil {
  6450. goodErrcode := models.XtGoodErrcode{
  6451. UserOrgId: adminInfo.Org.Id,
  6452. Errcode: "自动出库清空准备表数据报错",
  6453. GoodId: 0,
  6454. Status: 1,
  6455. Ctime: time.Now().Unix(),
  6456. Mtime: 0,
  6457. Count: 0,
  6458. StockCount: 0,
  6459. Creater: creator,
  6460. BatchNumberId: 0,
  6461. WarehouseOutId: 0,
  6462. }
  6463. service.CreateGoodErrcode(goodErrcode)
  6464. }
  6465. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6466. if errcodes != nil {
  6467. goodErrcode := models.XtGoodErrcode{
  6468. UserOrgId: adminInfo.Org.Id,
  6469. Errcode: "自动出库创建准备表数据报错",
  6470. GoodId: 0,
  6471. Status: 1,
  6472. Ctime: time.Now().Unix(),
  6473. Mtime: 0,
  6474. Count: 0,
  6475. StockCount: 0,
  6476. Creater: creator,
  6477. BatchNumberId: 0,
  6478. WarehouseOutId: 0,
  6479. }
  6480. service.CreateGoodErrcode(goodErrcode)
  6481. }
  6482. //查询默认仓库
  6483. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6484. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6485. var total_count int64
  6486. for _, it := range stockList {
  6487. total_count += it.StockCount
  6488. }
  6489. //基础库插入数据
  6490. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6491. if errcodes != nil {
  6492. goodErrcode := models.XtGoodErrcode{
  6493. UserOrgId: adminInfo.Org.Id,
  6494. Errcode: "自动出库基础库插入数据报错",
  6495. GoodId: 0,
  6496. Status: 1,
  6497. Ctime: time.Now().Unix(),
  6498. Mtime: 0,
  6499. Count: 0,
  6500. StockCount: 0,
  6501. Creater: creator,
  6502. BatchNumberId: 0,
  6503. WarehouseOutId: 0,
  6504. }
  6505. service.CreateGoodErrcode(goodErrcode)
  6506. }
  6507. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6508. var flush_count int64
  6509. for _, it := range goodList {
  6510. flush_count += it.StockCount
  6511. }
  6512. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6513. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6514. if errss != nil {
  6515. goodErrcode := models.XtGoodErrcode{
  6516. UserOrgId: item.OrgId,
  6517. Errcode: "自动出库剩余库存更新数据",
  6518. GoodId: item.GoodId,
  6519. Status: 1,
  6520. Ctime: time.Now().Unix(),
  6521. Mtime: 0,
  6522. Count: 0,
  6523. StockCount: 0,
  6524. Creater: creater,
  6525. BatchNumberId: 0,
  6526. WarehouseOutId: 0,
  6527. }
  6528. service.CreateGoodErrcode(goodErrcode)
  6529. }
  6530. }
  6531. }
  6532. }
  6533. c.ServeSuccessJSON(map[string]interface{}{
  6534. "msg": "提交成功",
  6535. "message": "2",
  6536. "good_name": "",
  6537. "specification_name": "",
  6538. })
  6539. return
  6540. } else {
  6541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6542. return
  6543. }
  6544. }
  6545. func (c *DialysisAPIController) EditConsumables() {
  6546. patient_id, _ := c.GetInt64("patient_id", 0)
  6547. record_date := c.GetString("record_time")
  6548. if patient_id <= 0 {
  6549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6550. return
  6551. }
  6552. adminInfo := c.GetMobileAdminUserInfo()
  6553. timeLayout := "2006-01-02"
  6554. loc, _ := time.LoadLocation("Local")
  6555. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6556. record_time := theRecordTime.Unix()
  6557. // 查询信息规挡的设置天数
  6558. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6559. if infor.ID > 0 && infor.WeekDay > 0 {
  6560. var cha_time int64
  6561. timeNowStr := time.Now().Format("2006-01-02")
  6562. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6563. //今日的日期减去设置的日期
  6564. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6565. if cha_time >= record_time {
  6566. //查询审核是否允许
  6567. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6568. //申请状态不允许的情况 拒绝修改
  6569. if infor.ApplicationStatus != 1 {
  6570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6571. return
  6572. }
  6573. }
  6574. }
  6575. dataBody := make(map[string]interface{}, 0)
  6576. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6577. if err != nil {
  6578. utils.ErrorLog(err.Error())
  6579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6580. return
  6581. }
  6582. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6583. var beforePrepares []*models.DialysisBeforePrepareGoods
  6584. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6585. var cancelbefor []*models.DialysisBeforePrepareGoods
  6586. var outbefor []*models.DialysisBeforePrepareGoods
  6587. //判断是否开启自动出库
  6588. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6589. if record.IsOpen == 1 {
  6590. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6591. goods, _ := dataBody["goods"].([]interface{})
  6592. if len(goods) > 0 {
  6593. for _, item := range goods {
  6594. items := item.(map[string]interface{})
  6595. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6596. utils.ErrorLog("good_id")
  6597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6598. return
  6599. }
  6600. good_id := int64(items["good_id"].(float64))
  6601. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6602. utils.ErrorLog("good_type_id")
  6603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6604. return
  6605. }
  6606. good_type_id := int64(items["good_type_id"].(float64))
  6607. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6608. utils.ErrorLog("count")
  6609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6610. return
  6611. }
  6612. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6613. commdity_code := items["commdity_code"].(string)
  6614. fmt.Println(commdity_code)
  6615. prepareGoods := &models.DialysisBeforePrepareGoods{
  6616. GoodTypeId: good_type_id,
  6617. GoodId: good_id,
  6618. Count: count,
  6619. StorehouseId: houseConfig.StorehouseOutInfo,
  6620. }
  6621. beforePrepares = append(beforePrepares, prepareGoods)
  6622. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6623. GoodTypeId: good_type_id,
  6624. GoodId: good_id,
  6625. Count: count,
  6626. StorehouseId: houseConfig.StorehouseOutInfo,
  6627. }
  6628. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6629. }
  6630. for _, item := range beforePrepares {
  6631. //1.查看该患者该耗材型号最后一次出库数量
  6632. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6633. //判断当前出库数量和最后一次出库数量的大小
  6634. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6635. if item.Count < goodInfo.Count {
  6636. cancelbefor = append(cancelbefor, item)
  6637. }
  6638. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6639. if item.Count > goodInfo.Count {
  6640. outbefor = append(outbefor, item)
  6641. }
  6642. //处理编辑耗材新增不了的问题
  6643. if goodInfo.Count == item.Count {
  6644. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6645. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6646. }
  6647. }
  6648. if len(cancelbefor) > 0 {
  6649. //退库
  6650. for _, item := range cancelbefor {
  6651. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6652. creater := adminInfo.AdminUser.Id
  6653. //查询该患者当天已经出库的耗材信息
  6654. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6655. var delete_count int64 = 0
  6656. delete_count = warehouseOutInfos.Count - item.Count
  6657. //增加库存数量
  6658. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6659. //减少实际出库库存数量
  6660. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6661. // 删除出库完成后,要增加对应批次的库存数量
  6662. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6663. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6664. //更新剩余库存
  6665. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6666. var flush_count int64
  6667. for _, it := range goodListOne {
  6668. flush_count += it.StockCount
  6669. }
  6670. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6671. //查询剩余库存
  6672. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6673. var sum_count int64
  6674. for _, item := range goodList {
  6675. sum_count += item.StockCount
  6676. }
  6677. // 在出库记录表里记录退库详情
  6678. warehouseOutInfo := &models.WarehouseOutInfo{
  6679. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6680. WarehouseOutId: warehouseOut.ID,
  6681. Status: 1,
  6682. Ctime: time.Now().Unix(),
  6683. OrgId: adminInfo.Org.Id,
  6684. Type: 1,
  6685. IsSys: 1,
  6686. SysRecordTime: record_time,
  6687. GoodTypeId: item.GoodTypeId,
  6688. GoodId: item.GoodId,
  6689. PatientId: patient_id,
  6690. ConsumableType: 2,
  6691. StorehouseId: houseConfig.StorehouseOutInfo,
  6692. IsCheck: 1,
  6693. OverCount: sum_count,
  6694. }
  6695. warehouseOutInfo.Count = item.Count
  6696. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6697. warehouseOutInfo.Price = stockInInfo.Price
  6698. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6699. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6700. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6701. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6702. warehouseOutInfo.Number = warehouseOutInfos.Number
  6703. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6704. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6705. //查找当天是否存在出库记录
  6706. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6707. if errcod == gorm.ErrRecordNotFound {
  6708. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6709. //插入详情明细表
  6710. stockFlow := models.VmStockFlow{
  6711. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6712. WarehouseOutId: warehouseOut.ID,
  6713. GoodId: item.GoodId,
  6714. Number: warehouseOutInfos.Number,
  6715. ProductDate: stockInInfo.ProductDate,
  6716. ExpireDate: stockInInfo.ExpiryDate,
  6717. Count: item.Count,
  6718. Price: stockInInfo.Price,
  6719. Status: 1,
  6720. Ctime: record_time,
  6721. UserOrgId: adminInfo.Org.Id,
  6722. Manufacturer: stockInInfo.Manufacturer,
  6723. Dealer: stockInInfo.Dealer,
  6724. LicenseNumber: stockInInfo.LicenseNumber,
  6725. IsEdit: 2,
  6726. Creator: creater,
  6727. SystemTime: record_time,
  6728. ConsumableType: 3,
  6729. WarehousingDetailId: 0,
  6730. IsSys: 1,
  6731. UpdateCreator: creater,
  6732. PatientId: patient_id,
  6733. StorehouseId: houseConfig.StorehouseOutInfo,
  6734. }
  6735. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6736. if errflow == gorm.ErrRecordNotFound {
  6737. //创建流水表
  6738. err := service.CreateStockFlowOne(stockFlow)
  6739. fmt.Println("err", err)
  6740. } else if errflow == nil {
  6741. //插入详情明细表
  6742. stockFlow := models.VmStockFlow{
  6743. ID: exsit.ID,
  6744. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6745. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6746. WarehouseOutId: warehouseOut.ID,
  6747. GoodId: item.GoodId,
  6748. Number: warehouseOutInfos.Number,
  6749. ProductDate: stockInInfo.ProductDate,
  6750. ExpireDate: stockInInfo.ExpiryDate,
  6751. Count: exsit.Count - delete_count,
  6752. Price: stockInInfo.Price,
  6753. Status: 1,
  6754. Ctime: record_time,
  6755. UserOrgId: adminInfo.Org.Id,
  6756. Manufacturer: stockInInfo.Manufacturer,
  6757. Dealer: stockInInfo.Dealer,
  6758. LicenseNumber: stockInInfo.LicenseNumber,
  6759. IsEdit: 2,
  6760. Creator: creater,
  6761. SystemTime: record_time,
  6762. ConsumableType: 3,
  6763. WarehousingDetailId: 0,
  6764. IsSys: 1,
  6765. UpdateCreator: creater,
  6766. PatientId: patient_id,
  6767. StorehouseId: houseConfig.StorehouseOutInfo,
  6768. }
  6769. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6770. }
  6771. } else if errcod == nil {
  6772. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6773. //查询剩余库存
  6774. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6775. var sum_count int64
  6776. for _, item := range goodList {
  6777. sum_count += item.StockCount
  6778. }
  6779. //创建退库单,生成退库数据
  6780. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6781. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6782. operation_time := time.Now().Unix()
  6783. creater := adminInfo.AdminUser.Id
  6784. //创建退库单
  6785. timeStr := time.Now().Format("2006-01-02")
  6786. timeArr := strings.Split(timeStr, "-")
  6787. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6788. total = total + 1
  6789. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6790. cancelStock := models.CancelStock{
  6791. OrderNumber: orderNumber,
  6792. OperaTime: operation_time,
  6793. OrgId: adminInfo.Org.Id,
  6794. Creater: creater,
  6795. Ctime: time.Now().Unix(),
  6796. Status: 1,
  6797. ReturnTime: record_time,
  6798. Type: 1,
  6799. StorehouseId: houseConfig.StorehouseOutInfo,
  6800. IsCheck: 1,
  6801. }
  6802. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6803. if msgerrkonde == gorm.ErrRecordNotFound {
  6804. service.AddSigleCancelStock(&cancelStock)
  6805. }
  6806. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6807. //查询是否有出库
  6808. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6809. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6810. deaerler, _ := service.GetDealerById(info.Dealer)
  6811. if info.ID > 0 {
  6812. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6813. cancelStockInfo := models.CancelStockInfo{
  6814. GoodId: item.GoodId,
  6815. CancelStockId: cancel.ID,
  6816. GoodTypeId: good.GoodTypeId,
  6817. Count: delete_count,
  6818. Price: info.Price,
  6819. Total: 0,
  6820. ProductDate: info.ProductDate,
  6821. ExpiryDate: info.ExpiryDate,
  6822. Ctime: time.Now().Unix(),
  6823. Status: 1,
  6824. OrgId: adminInfo.Org.Id,
  6825. OrderNumber: cancel.OrderNumber,
  6826. Type: 0,
  6827. Dealer: deaerler.DealerName,
  6828. Manufacturer: manufacturer.ManufacturerName,
  6829. Number: info.Number,
  6830. RegisterAccount: "",
  6831. Remark: "",
  6832. WarehouseInfoId: info.WarehouseInfotId,
  6833. PatientId: info.PatientId,
  6834. RecordDate: info.SysRecordTime,
  6835. StorehouseId: houseConfig.StorehouseOutInfo,
  6836. IsCheck: 1,
  6837. }
  6838. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6839. //退库数量增加
  6840. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6841. //查询剩余库存
  6842. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6843. var over_count int64
  6844. for _, it := range goodList {
  6845. over_count += it.StockCount
  6846. }
  6847. flow := models.VmStockFlow{
  6848. WarehousingId: info.WarehouseInfotId,
  6849. GoodId: item.GoodId,
  6850. Number: info.Number,
  6851. LicenseNumber: info.LicenseNumber,
  6852. Count: delete_count,
  6853. UserOrgId: adminInfo.Org.Id,
  6854. PatientId: patient_id,
  6855. SystemTime: info.SysRecordTime,
  6856. ConsumableType: 7,
  6857. IsSys: 0,
  6858. WarehousingOrder: "",
  6859. WarehouseOutId: info.WarehouseOutId,
  6860. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6861. IsEdit: 0,
  6862. CancelStockId: cancel.ID,
  6863. CancelOrderNumber: cancel.OrderNumber,
  6864. Manufacturer: manufacturer.ID,
  6865. Dealer: 0,
  6866. Creator: adminInfo.AdminUser.Id,
  6867. UpdateCreator: 0,
  6868. Status: 1,
  6869. Ctime: record_time,
  6870. Mtime: 0,
  6871. Price: info.Price,
  6872. WarehousingDetailId: info.WarehouseInfotId,
  6873. WarehouseOutDetailId: info.ID,
  6874. CancelOutDetailId: cancelInfo.ID,
  6875. ProductDate: info.ProductDate,
  6876. ExpireDate: info.ExpiryDate,
  6877. StorehouseId: houseConfig.StorehouseOutInfo,
  6878. OverCount: over_count,
  6879. }
  6880. service.CreateStockFlowOne(flow)
  6881. }
  6882. }
  6883. //更改自动出库的表格
  6884. details := models.BloodAutomaticReduceDetail{
  6885. WarehouseOutId: warehouseOutInfo.ID,
  6886. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6887. PatientId: patient_id,
  6888. Ctime: time.Now().Unix(),
  6889. Mtime: time.Now().Unix(),
  6890. Status: 1,
  6891. RecordTime: record_time,
  6892. OrgId: adminInfo.Org.Id,
  6893. GoodId: item.GoodId,
  6894. GoodTypeId: item.GoodTypeId,
  6895. Count: item.Count,
  6896. StorehouseId: houseConfig.StorehouseOutInfo,
  6897. }
  6898. //查询当天耗材是否已经存在数据
  6899. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6900. if errcode == gorm.ErrRecordNotFound {
  6901. service.CreateAutoReduceRecord(&details)
  6902. } else if errcode == nil {
  6903. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6904. service.CreateAutoReduceRecord(&details)
  6905. }
  6906. //查询默认仓库
  6907. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6908. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6909. var total_count int64
  6910. for _, it := range stockList {
  6911. total_count += it.StockCount
  6912. }
  6913. //基础库插入数据
  6914. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6915. }
  6916. }
  6917. if len(outbefor) > 0 {
  6918. //出库
  6919. for _, item := range outbefor {
  6920. var last_total int64
  6921. //1.查看该患者该耗材型号最后一次出库数量
  6922. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6923. //计算当前出库和最后一次出库数据相差数据
  6924. last_total = item.Count - goodInfoOne.Count
  6925. //查询该耗材的总库存
  6926. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6927. // 如果库存差大于剩余库存则提示库存不足
  6928. if last_total > wareinfo.StockCount {
  6929. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6930. c.ServeSuccessJSON(map[string]interface{}{
  6931. "message": "1",
  6932. "good_name": goodObj.GoodName,
  6933. "specification_name": goodObj.SpecificationName,
  6934. })
  6935. return
  6936. } else {
  6937. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6938. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6939. if err == gorm.ErrRecordNotFound {
  6940. //没有记录,则创建出库单
  6941. timeStr := time.Now().Format("2006-01-02")
  6942. timeArr := strings.Split(timeStr, "-")
  6943. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6944. total = total + 1
  6945. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6946. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6947. number = number + total
  6948. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6949. warehouseOut := models.WarehouseOut{
  6950. WarehouseOutOrderNumber: warehousing_out_order,
  6951. OperationTime: time.Now().Unix(),
  6952. OrgId: adminInfo.Org.Id,
  6953. Creater: adminInfo.AdminUser.Id,
  6954. Ctime: time.Now().Unix(),
  6955. Status: 1,
  6956. WarehouseOutTime: record_time,
  6957. Dealer: 0,
  6958. Manufacturer: 0,
  6959. Type: 1,
  6960. IsSys: 1,
  6961. StorehouseId: houseConfig.StorehouseOutInfo,
  6962. IsCheck: 1,
  6963. }
  6964. service.AddSigleWarehouseOut(&warehouseOut)
  6965. }
  6966. //出库
  6967. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6968. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6969. //1.查看该患者该耗材型号最后一次出库数量
  6970. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6971. prepare := models.DialysisBeforePrepare{
  6972. UserOrgId: adminInfo.Org.Id,
  6973. PatientId: patient_id,
  6974. RecordDate: record_time,
  6975. GoodId: item.GoodId,
  6976. GoodTypeId: item.GoodTypeId,
  6977. Count: item.Count - goodInfoTwo.Count,
  6978. Ctime: time.Now().Unix(),
  6979. Mtime: 0,
  6980. Creater: adminInfo.AdminUser.Id,
  6981. Modifier: adminInfo.AdminUser.Id,
  6982. Status: 1,
  6983. CommdityCode: "",
  6984. NewCount: 0,
  6985. ProjectId: 0,
  6986. StorehouseId: houseConfig.StorehouseOutInfo,
  6987. }
  6988. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  6989. //增加出库数量
  6990. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  6991. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6992. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6993. var total_count int64
  6994. for _, it := range stockList {
  6995. total_count += it.StockCount
  6996. }
  6997. //基础库插入数据
  6998. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6999. //剩余库存
  7000. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7001. var flush_count int64
  7002. for _, it := range goodList {
  7003. flush_count += it.StockCount
  7004. }
  7005. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7006. }
  7007. }
  7008. }
  7009. //查询今日出库数据
  7010. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7011. for _, it := range list {
  7012. prepare := models.DialysisBeforePrepare{
  7013. UserOrgId: it.OrgId,
  7014. PatientId: patient_id,
  7015. RecordDate: it.RecordTime,
  7016. GoodId: it.GoodId,
  7017. GoodTypeId: it.GoodTypeId,
  7018. Count: it.Count,
  7019. Ctime: time.Now().Unix(),
  7020. Creater: adminInfo.AdminUser.Id,
  7021. Status: 1,
  7022. StorehouseId: houseConfig.StorehouseOutInfo,
  7023. ProjectId: it.ProjectId,
  7024. }
  7025. //删除准备表数据
  7026. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7027. service.CreateDialysisBeforePrepareOne(&prepare)
  7028. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7029. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7030. var total_count int64
  7031. for _, it := range stockList {
  7032. total_count += it.StockCount
  7033. }
  7034. //基础库插入数据
  7035. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7036. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7037. var flush_count int64
  7038. for _, it := range goodList {
  7039. flush_count += it.StockCount
  7040. }
  7041. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7042. }
  7043. }
  7044. }
  7045. //更新自动出库的地方
  7046. var errs error
  7047. if errs == nil {
  7048. c.ServeSuccessJSON(map[string]interface{}{
  7049. "msg": "修改成功",
  7050. "message": "2",
  7051. "good_name": "",
  7052. "specification_name": "",
  7053. })
  7054. return
  7055. } else {
  7056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7057. return
  7058. }
  7059. }
  7060. }
  7061. func (c *DialysisAPIController) GetDialysisGoods() {
  7062. schedualDate := c.GetString("schedule_date")
  7063. schedule_type, _ := c.GetInt64("schedule_type")
  7064. partition_id, _ := c.GetInt64("partition_id")
  7065. page, _ := c.GetInt("page")
  7066. patient_id, _ := c.GetInt64("patient_id")
  7067. schedualEndDate := int64(0)
  7068. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7069. if parseDateErr != nil && len(schedualDate) != 0 {
  7070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7071. return
  7072. }
  7073. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7074. if parseDateErr != nil && len(schedualDate) != 0 {
  7075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7076. return
  7077. }
  7078. schedualEndDate = endDate.Unix()
  7079. adminUser := c.GetMobileAdminUserInfo()
  7080. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7081. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7082. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7083. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7084. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7085. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7086. //获取当天该病人的透析处方
  7087. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7088. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7089. if err == gorm.ErrRecordNotFound {
  7090. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7091. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7092. if patient_id != 0 {
  7093. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7094. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7095. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7096. //获取患者总的出库数据
  7097. item.LastAutomaticReduceDetail = goodUser
  7098. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7099. item.Project = project
  7100. for _, it := range item.AutomaticReduceDetail {
  7101. var total int64
  7102. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7103. for _, its := range auto {
  7104. total += its.Count
  7105. }
  7106. it.Count = total
  7107. }
  7108. }
  7109. }
  7110. c.ServeSuccessJSON(map[string]interface{}{
  7111. "dialysis_goods": dialysisGoods,
  7112. "good_type": goodTypes,
  7113. "total": total,
  7114. "prescribe": prescribe,
  7115. "good_info": good_info,
  7116. "warehouseOutList": warehouseOutList,
  7117. "config": config,
  7118. "outConfig": outConfig,
  7119. "settleConfig": settleConfig,
  7120. })
  7121. return
  7122. } else if err == nil {
  7123. //获取当天排班的每个患者的库存使用情况
  7124. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7125. //获取患者总的出库数据
  7126. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7127. if patient_id != 0 {
  7128. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7129. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7130. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7131. item.Project = project
  7132. item.LastAutomaticReduceDetail = goodUser
  7133. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7134. for _, it := range item.AutomaticReduceDetail {
  7135. var total int64
  7136. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7137. for _, its := range auto {
  7138. total += its.Count
  7139. }
  7140. it.Count = total
  7141. }
  7142. }
  7143. }
  7144. if err == nil {
  7145. c.ServeSuccessJSON(map[string]interface{}{
  7146. "dialysis_goods": dialysisGoods,
  7147. "good_type": goodTypes,
  7148. "total": total,
  7149. "prescribe": prescribe,
  7150. "good_info": good_info,
  7151. "project": project,
  7152. "warehouseOutList": warehouseOutList,
  7153. "config": config,
  7154. "outConfig": outConfig,
  7155. "settleConfig": settleConfig,
  7156. })
  7157. return
  7158. } else {
  7159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7160. return
  7161. }
  7162. } else if err != nil {
  7163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7164. return
  7165. }
  7166. }
  7167. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7168. start_time := c.GetString("start_time")
  7169. end_time := c.GetString("end_time")
  7170. timeLayout := "2006-01-02"
  7171. loc, _ := time.LoadLocation("Local")
  7172. var theStartTime int64
  7173. if len(start_time) > 0 {
  7174. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7175. if err != nil {
  7176. utils.ErrorLog(err.Error())
  7177. }
  7178. theStartTime = theTime.Unix()
  7179. }
  7180. var theEndtTime int64
  7181. if len(end_time) > 0 {
  7182. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7183. if err != nil {
  7184. utils.ErrorLog(err.Error())
  7185. }
  7186. theEndtTime = theTime.Unix()
  7187. }
  7188. adminUser := c.GetMobileAdminUserInfo()
  7189. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7190. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7191. if err == nil {
  7192. c.ServeSuccessJSON(map[string]interface{}{
  7193. "stock_out": outInfo,
  7194. "stockCount": stockCount,
  7195. })
  7196. return
  7197. } else {
  7198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7199. return
  7200. }
  7201. }
  7202. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7203. patient_id, _ := c.GetInt64("patient_id", 0)
  7204. record_time := c.GetString("record_time")
  7205. adminUser := c.GetMobileAdminUserInfo()
  7206. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7207. if parseDateErr != nil && len(record_time) != 0 {
  7208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7209. return
  7210. }
  7211. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7212. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7213. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7214. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7215. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7216. //获取今日患者的透析处方参数
  7217. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7218. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7219. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7220. c.ServeSuccessJSON(map[string]interface{}{
  7221. "good_type": goodTypes,
  7222. "good_user": goodUser,
  7223. "good_info": good_info,
  7224. "last_good_user": lastGoodUserDetial,
  7225. "project": project,
  7226. "prescription": prescribe,
  7227. "outInfo": outInfo,
  7228. "configs": configs,
  7229. })
  7230. return
  7231. }
  7232. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7233. patient_id, _ := c.GetInt64("patient_id", 0)
  7234. record_date := c.GetString("record_time")
  7235. timeLayout := "2006-01-02"
  7236. loc, _ := time.LoadLocation("Local")
  7237. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7238. record_time := theRecordTime.Unix()
  7239. adminInfo := c.GetMobileAdminUserInfo()
  7240. dataBody := make(map[string]interface{}, 0)
  7241. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7242. if err != nil {
  7243. utils.ErrorLog(err.Error())
  7244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7245. return
  7246. }
  7247. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7248. var beforePrepares []*models.DialysisBeforePrepareGoods
  7249. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7250. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7251. goods, _ := dataBody["goods"].([]interface{})
  7252. if len(goods) > 0 {
  7253. for _, item := range goods {
  7254. items := item.(map[string]interface{})
  7255. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7256. utils.ErrorLog("good_id")
  7257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7258. return
  7259. }
  7260. good_id := int64(items["good_id"].(float64))
  7261. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7262. utils.ErrorLog("good_type_id")
  7263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7264. return
  7265. }
  7266. good_type_id := int64(items["good_type_id"].(float64))
  7267. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7268. utils.ErrorLog("count")
  7269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7270. return
  7271. }
  7272. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7273. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7274. utils.ErrorLog("project_id")
  7275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7276. return
  7277. }
  7278. project_id := int64(items["project_id"].(float64))
  7279. new_count := int64(items["new_count"].(float64))
  7280. old_count := int64(items["old_count"].(float64))
  7281. prepare := &models.DialysisBeforePrepareGoods{
  7282. GoodId: good_id,
  7283. GoodTypeId: good_type_id,
  7284. Count: count,
  7285. ProjectId: project_id,
  7286. StorehouseId: houseConfig.StorehouseOutInfo,
  7287. NewCount: new_count,
  7288. OldCount: old_count,
  7289. }
  7290. beforePrepares = append(beforePrepares, prepare)
  7291. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7292. GoodId: good_id,
  7293. GoodTypeId: good_type_id,
  7294. Count: count,
  7295. ProjectId: project_id,
  7296. StorehouseId: houseConfig.StorehouseOutInfo,
  7297. NewCount: new_count,
  7298. OldCount: old_count,
  7299. }
  7300. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7301. }
  7302. }
  7303. }
  7304. //查询是否有库存
  7305. for _, item := range beforePrepares {
  7306. if item.NewCount > 0 {
  7307. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7308. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7309. if item.Count > warehouse.Count {
  7310. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7311. c.ServeSuccessJSON(map[string]interface{}{
  7312. "message": "1",
  7313. "good_name": goodObj.GoodName,
  7314. "specification_name": goodObj.SpecificationName,
  7315. })
  7316. return
  7317. }
  7318. }
  7319. }
  7320. // 查询信息规挡的设置天数
  7321. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7322. if infor.ID > 0 && infor.WeekDay > 0 {
  7323. var cha_time int64
  7324. timeNowStr := time.Now().Format("2006-01-02")
  7325. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7326. //今日的日期减去设置的日期
  7327. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7328. if cha_time >= record_time {
  7329. //查询审核是否允许
  7330. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7331. //申请状态不允许的情况 拒绝修改
  7332. if infor.ApplicationStatus != 1 {
  7333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7334. return
  7335. }
  7336. }
  7337. }
  7338. //出库逻辑
  7339. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7340. if err != nil {
  7341. utils.ErrorLog(err.Error())
  7342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7343. return
  7344. }
  7345. finish := models.XtDialysisFinish{
  7346. IsFinish: 1,
  7347. UserOrgId: adminInfo.Org.Id,
  7348. Status: 1,
  7349. Ctime: time.Now().Unix(),
  7350. Mtime: 0,
  7351. Module: 11,
  7352. RecordDate: record_time,
  7353. Sourse: 1,
  7354. PatientId: patient_id,
  7355. }
  7356. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7357. if dialysisFinish.ID == 0 {
  7358. service.CreateDialysisFinish(finish)
  7359. }
  7360. //查询当天出库的数据
  7361. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7362. for _, item := range list {
  7363. prepare := models.DialysisBeforePrepare{
  7364. UserOrgId: item.OrgId,
  7365. PatientId: item.PatientId,
  7366. RecordDate: item.RecordTime,
  7367. GoodId: item.GoodId,
  7368. GoodTypeId: item.GoodTypeId,
  7369. Count: item.Count,
  7370. Creater: adminInfo.AdminUser.Id,
  7371. Status: 1,
  7372. Ctime: time.Now().Unix(),
  7373. ProjectId: item.ProjectId,
  7374. StorehouseId: houseConfig.StorehouseOutInfo,
  7375. }
  7376. //清空准备表的数据
  7377. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7378. //插入准备表数据
  7379. service.CreateDialysisBeforePrepareOne(&prepare)
  7380. //查询默认仓库
  7381. //查询默认仓库
  7382. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7383. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7384. var total_count int64
  7385. for _, it := range stockList {
  7386. total_count += it.StockCount
  7387. }
  7388. //基础库插入数据
  7389. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7390. ////更新剩余库存
  7391. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7392. var flush_count int64
  7393. for _, it := range goodList {
  7394. flush_count += it.StockCount
  7395. }
  7396. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7397. if errs != nil {
  7398. goodErrcode := models.XtGoodErrcode{
  7399. UserOrgId: item.OrgId,
  7400. Errcode: "手动出库更新剩余出库失败",
  7401. GoodId: item.GoodId,
  7402. Status: 1,
  7403. Ctime: time.Now().Unix(),
  7404. Mtime: 0,
  7405. Count: 0,
  7406. StockCount: 0,
  7407. Creater: adminInfo.AdminUser.Id,
  7408. BatchNumberId: 0,
  7409. WarehouseOutId: 0,
  7410. }
  7411. service.CreateGoodErrcode(goodErrcode)
  7412. }
  7413. }
  7414. //更新自动出库的地方
  7415. var errs error
  7416. if errs == nil {
  7417. c.ServeSuccessJSON(map[string]interface{}{
  7418. "msg": "修改成功",
  7419. "message": "2",
  7420. "good_name": "",
  7421. "specification_name": "",
  7422. })
  7423. return
  7424. } else {
  7425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7426. return
  7427. }
  7428. }
  7429. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7430. newArr = make([]*models.DialysisBeforePrepare, 0)
  7431. for i := 0; i < len(arr); i++ {
  7432. repeat := false
  7433. for j := i + 1; j < len(arr); j++ {
  7434. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7435. repeat = true
  7436. break
  7437. }
  7438. }
  7439. if !repeat {
  7440. newArr = append(newArr, arr[i])
  7441. }
  7442. }
  7443. return
  7444. }
  7445. func (c *DialysisAPIController) GetAllDrug() {
  7446. patient_id, _ := c.GetInt64("patient_id", 0)
  7447. adminInfo := c.GetMobileAdminUserInfo()
  7448. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7449. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7450. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7451. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7452. c.ServeSuccessJSON(map[string]interface{}{
  7453. "base_drug_config": drugStockConfig,
  7454. "private_drug_config": privateDrugConfig,
  7455. "base_drug_list": drugList,
  7456. "private_drug_list": privateDrugList,
  7457. })
  7458. }
  7459. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7460. newArr = make([]*models.DialysisBeforePrepare, 0)
  7461. for i := 0; i < len(arr); i++ {
  7462. repeat := false
  7463. for j := i + 1; j < len(arr); j++ {
  7464. if arr[i].GoodId == arr[j].GoodId {
  7465. repeat = true
  7466. break
  7467. }
  7468. }
  7469. if !repeat {
  7470. newArr = append(newArr, arr[i])
  7471. }
  7472. }
  7473. return
  7474. }
  7475. func (c *DialysisAPIController) GetDepartment() {
  7476. adminInfo := c.GetMobileAdminUserInfo()
  7477. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7478. if err == nil {
  7479. c.ServeSuccessJSON(map[string]interface{}{
  7480. "departments": departments,
  7481. })
  7482. } else {
  7483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7484. return
  7485. }
  7486. }
  7487. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7488. types, _ := c.GetInt("type", 0)
  7489. start_time := c.GetString("start_time")
  7490. end_time := c.GetString("end_time")
  7491. orgId := c.GetMobileAdminUserInfo().Org.Id
  7492. timeLayout := "2006-01-02"
  7493. loc, _ := time.LoadLocation("Local")
  7494. var startTime int64
  7495. if len(start_time) > 0 {
  7496. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7497. if err != nil {
  7498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7499. return
  7500. }
  7501. startTime = theTime.Unix()
  7502. }
  7503. var endTime int64
  7504. if len(end_time) > 0 {
  7505. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7506. if err != nil {
  7507. utils.ErrorLog(err.Error())
  7508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7509. return
  7510. }
  7511. endTime = theTime.Unix()
  7512. }
  7513. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7514. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7515. if err != nil {
  7516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7517. } else {
  7518. c.ServeSuccessJSON(map[string]interface{}{
  7519. "list": list,
  7520. "type": types,
  7521. "stockTotal": stockTotal,
  7522. })
  7523. }
  7524. }
  7525. func (c *DialysisAPIController) GetPrescriptionList() {
  7526. start_time := c.GetString("start_time")
  7527. end_time := c.GetString("end_time")
  7528. schedule_type, _ := c.GetInt64("schedule_type")
  7529. partion_id, _ := c.GetInt64("partion_id")
  7530. orgId := c.GetMobileAdminUserInfo().Org.Id
  7531. timeLayout := "2006-01-02"
  7532. loc, _ := time.LoadLocation("Local")
  7533. var startTime int64
  7534. if len(start_time) > 0 {
  7535. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7536. if err != nil {
  7537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7538. return
  7539. }
  7540. startTime = theTime.Unix()
  7541. }
  7542. var endTime int64
  7543. if len(end_time) > 0 {
  7544. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7545. if err != nil {
  7546. utils.ErrorLog(err.Error())
  7547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7548. return
  7549. }
  7550. endTime = theTime.Unix()
  7551. }
  7552. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7553. fmt.Println("schedulelist22222222", schedulelist)
  7554. c.ServeSuccessJSON(map[string]interface{}{
  7555. "list": schedulelist,
  7556. })
  7557. return
  7558. }
  7559. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7560. ids := c.GetString("ids")
  7561. //patient_id, _ := c.GetInt64("patient_id")
  7562. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7563. idArray := strings.Split(ids, ",")
  7564. err := service.BatchDeleteMonitor(idArray)
  7565. fmt.Print("err", err)
  7566. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7567. //redis := service.RedisClient()
  7568. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7569. //redis.Set(key, "", time.Second)
  7570. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7571. //redis.Set(keyOne, "", time.Second)
  7572. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7573. //redis.Close()
  7574. c.ServeSuccessJSON(map[string]interface{}{
  7575. "msg": "批量删除成功",
  7576. })
  7577. return
  7578. }
  7579. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7580. id, _ := c.GetInt64("id")
  7581. timeLayout := "2006-01-02"
  7582. loc, _ := time.LoadLocation("Local")
  7583. //start_time := time.Now().Format("2006-01-02")
  7584. start_time := c.GetString("start_time")
  7585. end_time := c.GetString("end_time")
  7586. var startdateunix int64
  7587. if len(start_time) > 0 {
  7588. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7589. if err != nil {
  7590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7591. return
  7592. }
  7593. startdateunix = theTime.Unix()
  7594. }
  7595. var enddateunix int64
  7596. if len(end_time) > 0 {
  7597. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7598. if err != nil {
  7599. utils.ErrorLog(err.Error())
  7600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7601. return
  7602. }
  7603. enddateunix = theTime.Unix()
  7604. }
  7605. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7606. //nowTime := time.Now()
  7607. //endTime := nowTime.AddDate(-30, 0, 0)
  7608. //endTimes := endTime.Format("2006-01-02")
  7609. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7610. org_id := c.GetMobileAdminUserInfo().Org.Id
  7611. //if org_id == 10579 {
  7612. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7613. // c.ServeSuccessJSON(map[string]interface{}{
  7614. // "list": list,
  7615. // })
  7616. // return
  7617. //} else {
  7618. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7619. // c.ServeSuccessJSON(map[string]interface{}{
  7620. // "list": list,
  7621. // })
  7622. // return
  7623. //}
  7624. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  7625. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7626. c.ServeSuccessJSON(map[string]interface{}{
  7627. "list": list,
  7628. })
  7629. return
  7630. } else {
  7631. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7632. c.ServeSuccessJSON(map[string]interface{}{
  7633. "list": list,
  7634. })
  7635. }
  7636. return
  7637. }
  7638. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7639. dataBody := make(map[string]interface{}, 0)
  7640. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7641. ids := c.GetString("ids")
  7642. idArray := strings.Split(ids, ",")
  7643. origin, _ := c.GetInt64("origin")
  7644. if origin == 1 {
  7645. err = service.BatchDeleteAdvice(idArray)
  7646. fmt.Print("err", err)
  7647. c.ServeSuccessJSON(map[string]interface{}{
  7648. "msg": "批量删除成功",
  7649. })
  7650. return
  7651. }
  7652. if origin == 2 {
  7653. service.BatchDeleteHisAdvice(idArray)
  7654. }
  7655. }
  7656. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7657. good_id, _ := c.GetInt64("good_id")
  7658. count, _ := c.GetInt64("count")
  7659. record_time, _ := c.GetInt64("record_time")
  7660. patient_id, _ := c.GetInt64("patient_id")
  7661. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7662. c.ServeSuccessJSON(map[string]interface{}{
  7663. "detail": detail,
  7664. })
  7665. return
  7666. }
  7667. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7668. good_id, _ := c.GetInt64("good_id")
  7669. record_time, _ := c.GetInt64("record_time")
  7670. patient_id, _ := c.GetInt64("patient_id")
  7671. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7672. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7673. fmt.Print("err", err)
  7674. c.ServeSuccessJSON(map[string]interface{}{
  7675. "msg": "批量删除成功",
  7676. })
  7677. return
  7678. }
  7679. func (c *DialysisAPIController) BatchAdviceCheck() {
  7680. ids := c.GetString("ids")
  7681. idArray := strings.Split(ids, ",")
  7682. creator, _ := c.GetInt64("creator")
  7683. origin, _ := c.GetInt64("origin")
  7684. if origin == 1 {
  7685. err := service.BatchAdviceCheck(idArray, creator)
  7686. fmt.Println(err)
  7687. list, _ := service.GetAdviceExecutionById(idArray)
  7688. c.ServeSuccessJSON(map[string]interface{}{
  7689. "list": list,
  7690. })
  7691. return
  7692. }
  7693. if origin == 2 {
  7694. service.BatchHisAdviceCheck(idArray, creator)
  7695. list, _ := service.GetHisAdviceExecutionById(idArray)
  7696. c.ServeSuccessJSON(map[string]interface{}{
  7697. "list": list,
  7698. })
  7699. return
  7700. }
  7701. }
  7702. func (c *DialysisAPIController) BatchAdviceExecution() {
  7703. ids := c.GetString("ids")
  7704. idArray := strings.Split(ids, ",")
  7705. executionTime := c.GetString("execution_time")
  7706. creator, _ := c.GetInt64("creator")
  7707. timeLayout := "2006-01-02 15:04:05"
  7708. loc, _ := time.LoadLocation("Local")
  7709. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7710. orgin, _ := c.GetInt64("origin")
  7711. if orgin == 1 {
  7712. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7713. list, _ := service.GetAdviceExecutionById(idArray)
  7714. fmt.Println(err)
  7715. c.ServeSuccessJSON(map[string]interface{}{
  7716. "list": list,
  7717. })
  7718. return
  7719. }
  7720. if orgin == 2 {
  7721. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7722. list, _ := service.GetHisAdviceExecutionById(idArray)
  7723. fmt.Println(err)
  7724. c.ServeSuccessJSON(map[string]interface{}{
  7725. "list": list,
  7726. })
  7727. return
  7728. }
  7729. }
  7730. func (c *DialysisAPIController) UpdateStockGoods() {
  7731. good_id, _ := c.GetInt64("good_id")
  7732. record_time, _ := c.GetInt64("record_time")
  7733. patient_id, _ := c.GetInt64("patient_id")
  7734. count, _ := c.GetInt64("count")
  7735. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7736. fmt.Print("err", err)
  7737. c.ServeSuccessJSON(map[string]interface{}{
  7738. "msg": "更新成功",
  7739. })
  7740. return
  7741. }
  7742. // 当前数据比上一次出库数据少
  7743. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7744. //查询该患者当天已经出库的耗材信息
  7745. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7746. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7747. for i := len(goods_yc) - 1; i >= 0; i-- {
  7748. goods_yc_temp := goods_yc[i]
  7749. for j := len(goods) - 1; j >= 0; j-- {
  7750. goods_temp := goods[j]
  7751. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7752. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7753. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7754. if goods_yc_temp.Count == goods_temp.Count {
  7755. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7756. goods = append(goods[:j], goods[j+1:]...)
  7757. break
  7758. }
  7759. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7760. if goods_yc_temp.Count > goods_temp.Count {
  7761. temp_count := goods_yc_temp.Count - goods_temp.Count
  7762. goods_yc[i].Count = temp_count
  7763. goods = append(goods[:j], goods[j+1:]...)
  7764. break
  7765. }
  7766. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7767. if goods_yc_temp.Count < goods_temp.Count {
  7768. temp_count := goods_temp.Count - goods_yc_temp.Count
  7769. goods[j].Count = temp_count
  7770. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7771. break
  7772. }
  7773. }
  7774. }
  7775. }
  7776. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7777. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7778. //退库
  7779. if len(goods_yc) > 0 {
  7780. for _, good_yc := range goods_yc {
  7781. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7782. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7783. }
  7784. }
  7785. return nil
  7786. }
  7787. // 耗材出库删除
  7788. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7789. // 先根据相关信息查询当天该耗材的出库信息
  7790. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7791. if err != nil {
  7792. return err
  7793. }
  7794. var delete_count int64 = 0
  7795. delete_count = warehouseOutInfos.Count - count
  7796. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7797. // 在出库记录表里记录退库详情
  7798. warehouseOutInfo := &models.WarehouseOutInfo{
  7799. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7800. WarehouseOutId: warehouseOut.ID,
  7801. Status: 1,
  7802. Ctime: time.Now().Unix(),
  7803. OrgId: orgID,
  7804. Type: 1,
  7805. IsSys: 1,
  7806. SysRecordTime: record_time,
  7807. GoodTypeId: good_yc.GoodTypeId,
  7808. GoodId: good_yc.GoodId,
  7809. PatientId: good_yc.PatientId,
  7810. ConsumableType: 2,
  7811. StorehouseId: houseConfig.StorehouseOutInfo,
  7812. IsCheck: 1,
  7813. }
  7814. warehouseOutInfo.Count = count
  7815. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7816. warehouseOutInfo.Price = stockInInfo.Price
  7817. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7818. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7819. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7820. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7821. warehouseOutInfo.Number = warehouseOutInfos.Number
  7822. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7823. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7824. //查找当天是否存在出库记录
  7825. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7826. if errcod == gorm.ErrRecordNotFound {
  7827. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7828. //插入详情明细表
  7829. stockFlow := models.VmStockFlow{
  7830. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7831. WarehouseOutId: warehouseOut.ID,
  7832. GoodId: good_yc.GoodId,
  7833. Number: warehouseOutInfos.Number,
  7834. ProductDate: stockInInfo.ProductDate,
  7835. ExpireDate: stockInInfo.ExpiryDate,
  7836. Count: count,
  7837. Price: stockInInfo.Price,
  7838. Status: 1,
  7839. Ctime: time.Now().Unix(),
  7840. UserOrgId: good_yc.OrgId,
  7841. Manufacturer: stockInInfo.Manufacturer,
  7842. Dealer: stockInInfo.Dealer,
  7843. LicenseNumber: stockInInfo.LicenseNumber,
  7844. IsEdit: 2,
  7845. Creator: creater,
  7846. SystemTime: record_time,
  7847. ConsumableType: 3,
  7848. WarehousingDetailId: 0,
  7849. IsSys: 1,
  7850. UpdateCreator: creater,
  7851. PatientId: patient_id,
  7852. StorehouseId: houseConfig.StorehouseOutInfo,
  7853. }
  7854. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7855. if errflow == gorm.ErrRecordNotFound {
  7856. //创建流水表
  7857. err := service.CreateStockFlowOne(stockFlow)
  7858. fmt.Println("err", err)
  7859. } else if errflow == nil {
  7860. //插入详情明细表
  7861. stockFlow := models.VmStockFlow{
  7862. ID: exsit.ID,
  7863. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7864. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7865. WarehouseOutId: warehouseOut.ID,
  7866. GoodId: good_yc.GoodId,
  7867. Number: warehouseOutInfos.Number,
  7868. ProductDate: stockInInfo.ProductDate,
  7869. ExpireDate: stockInInfo.ExpiryDate,
  7870. Count: exsit.Count - delete_count,
  7871. Price: stockInInfo.Price,
  7872. Status: 1,
  7873. Ctime: time.Now().Unix(),
  7874. UserOrgId: good_yc.OrgId,
  7875. Manufacturer: stockInInfo.Manufacturer,
  7876. Dealer: stockInInfo.Dealer,
  7877. LicenseNumber: stockInInfo.LicenseNumber,
  7878. IsEdit: 2,
  7879. Creator: creater,
  7880. SystemTime: record_time,
  7881. ConsumableType: 3,
  7882. WarehousingDetailId: 0,
  7883. IsSys: 1,
  7884. UpdateCreator: creater,
  7885. PatientId: patient_id,
  7886. StorehouseId: houseConfig.StorehouseOutInfo,
  7887. }
  7888. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7889. }
  7890. if errOne != nil {
  7891. return errOne
  7892. }
  7893. } else if errcod == nil {
  7894. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7895. //插入详情明细表
  7896. stockFlow := models.VmStockFlow{
  7897. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7898. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7899. WarehouseOutId: warehouseOut.ID,
  7900. GoodId: good_yc.GoodId,
  7901. Number: warehouseOutInfos.Number,
  7902. ProductDate: stockInInfo.ProductDate,
  7903. ExpireDate: stockInInfo.ExpiryDate,
  7904. Count: count,
  7905. Price: stockInInfo.Price,
  7906. Status: 1,
  7907. Ctime: time.Now().Unix(),
  7908. UserOrgId: good_yc.OrgId,
  7909. Manufacturer: stockInInfo.Manufacturer,
  7910. Dealer: stockInInfo.Dealer,
  7911. LicenseNumber: stockInInfo.LicenseNumber,
  7912. IsEdit: 2,
  7913. Creator: creater,
  7914. SystemTime: record_time,
  7915. ConsumableType: 3,
  7916. WarehousingDetailId: 0,
  7917. IsSys: 1,
  7918. UpdateCreator: creater,
  7919. PatientId: patient_id,
  7920. ReturnCount: delete_count,
  7921. StorehouseId: houseConfig.StorehouseOutInfo,
  7922. }
  7923. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7924. if errflows == gorm.ErrRecordNotFound {
  7925. //创建流水表
  7926. service.CreateStockFlowOne(stockFlow)
  7927. } else if errflows == nil {
  7928. stockFlow := models.VmStockFlow{
  7929. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7930. ID: exsit.ID,
  7931. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7932. WarehouseOutId: warehouseOut.ID,
  7933. GoodId: good_yc.GoodId,
  7934. Number: warehouseOutInfos.Number,
  7935. ProductDate: stockInInfo.ProductDate,
  7936. ExpireDate: stockInInfo.ExpiryDate,
  7937. Count: exsit.Count - delete_count,
  7938. Price: stockInInfo.Price,
  7939. Status: 1,
  7940. Ctime: time.Now().Unix(),
  7941. UserOrgId: good_yc.OrgId,
  7942. Manufacturer: stockInInfo.Manufacturer,
  7943. Dealer: stockInInfo.Dealer,
  7944. LicenseNumber: stockInInfo.LicenseNumber,
  7945. IsEdit: 2,
  7946. Creator: creater,
  7947. SystemTime: record_time,
  7948. ConsumableType: 3,
  7949. WarehousingDetailId: 0,
  7950. IsSys: 1,
  7951. UpdateCreator: creater,
  7952. PatientId: patient_id,
  7953. ReturnCount: delete_count,
  7954. StorehouseId: houseConfig.StorehouseOutInfo,
  7955. }
  7956. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7957. }
  7958. }
  7959. //更改自动出库的表格
  7960. details := models.BloodAutomaticReduceDetail{
  7961. WarehouseOutId: warehouseOutInfo.ID,
  7962. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7963. PatientId: patient_id,
  7964. Ctime: time.Now().Unix(),
  7965. Mtime: time.Now().Unix(),
  7966. Status: 1,
  7967. RecordTime: record_time,
  7968. OrgId: orgID,
  7969. GoodId: good_yc.GoodId,
  7970. GoodTypeId: good_yc.GoodTypeId,
  7971. Count: count,
  7972. StorehouseId: houseConfig.StorehouseOutInfo,
  7973. }
  7974. //查询当天耗材是否已经存在数据
  7975. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7976. if errcode == gorm.ErrRecordNotFound {
  7977. errTwo := service.CreateAutoReduceRecord(&details)
  7978. if errTwo != nil {
  7979. return errTwo
  7980. }
  7981. } else if errcode == nil {
  7982. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7983. service.CreateAutoReduceRecord(&details)
  7984. }
  7985. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7986. //增加出库库存数量
  7987. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7988. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7989. fmt.Println("errOne", errOne)
  7990. // 删除出库完成后,要增加对应批次的库存数量
  7991. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7992. if errThree != nil {
  7993. return errThree
  7994. }
  7995. if good_yc.Count == 0 {
  7996. return nil
  7997. } else {
  7998. return errors.New("退库和出库数据不匹配")
  7999. }
  8000. }
  8001. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8002. //查询该患者当天已经出库的耗材信息
  8003. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8004. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8005. for i := len(goods_yc) - 1; i >= 0; i-- {
  8006. goods_yc_temp := goods_yc[i]
  8007. for j := len(goods) - 1; j >= 0; j-- {
  8008. goods_temp := goods[j]
  8009. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8010. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8011. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8012. if goods_yc_temp.Count == goods_temp.Count {
  8013. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8014. goods = append(goods[:j], goods[j+1:]...)
  8015. break
  8016. }
  8017. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8018. if goods_yc_temp.Count > goods_temp.Count {
  8019. temp_count := goods_yc_temp.Count - goods_temp.Count
  8020. goods_yc[i].Count = temp_count
  8021. goods = append(goods[:j], goods[j+1:]...)
  8022. break
  8023. }
  8024. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8025. if goods_yc_temp.Count < goods_temp.Count {
  8026. temp_count := goods_temp.Count - goods_yc_temp.Count
  8027. goods[j].Count = temp_count
  8028. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8029. break
  8030. }
  8031. }
  8032. }
  8033. }
  8034. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8035. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8036. fmt.Println("剩余需要出库的", len(goods))
  8037. if len(goods) > 0 {
  8038. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8039. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8040. if err == gorm.ErrRecordNotFound {
  8041. //没有记录,则创建出库单
  8042. timeStr := time.Now().Format("2006-01-02")
  8043. timeArr := strings.Split(timeStr, "-")
  8044. total, _ := service.FindAllWarehouseOut(orgID)
  8045. total = total + 1
  8046. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8047. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8048. number = number + total
  8049. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8050. warehouseOut := models.WarehouseOut{
  8051. WarehouseOutOrderNumber: warehousing_out_order,
  8052. OperationTime: time.Now().Unix(),
  8053. OrgId: orgID,
  8054. Creater: creater,
  8055. Ctime: time.Now().Unix(),
  8056. Status: 1,
  8057. WarehouseOutTime: record_time,
  8058. Dealer: 0,
  8059. Manufacturer: 0,
  8060. Type: 1,
  8061. IsSys: 1,
  8062. StorehouseId: houseConfig.StorehouseOutInfo,
  8063. IsCheck: 1,
  8064. }
  8065. err := service.AddSigleWarehouseOut(&warehouseOut)
  8066. if err != nil {
  8067. utils.TraceLog("创建出库单失败 err = %v", err)
  8068. return err
  8069. } else {
  8070. out = warehouseOut
  8071. }
  8072. }
  8073. for _, item := range goods {
  8074. var newCount int64 = 0
  8075. for _, it := range goodOne {
  8076. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8077. newCount = it.Count
  8078. }
  8079. }
  8080. prepare := models.DialysisBeforePrepare{
  8081. GoodTypeId: item.GoodTypeId,
  8082. GoodId: item.GoodId,
  8083. Count: item.Count,
  8084. StorehouseId: houseConfig.StorehouseOutInfo,
  8085. }
  8086. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8087. //增加出库数量
  8088. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8089. }
  8090. }
  8091. if len(goods_yc) > 0 {
  8092. for _, good_yc := range goods_yc {
  8093. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8094. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8095. }
  8096. }
  8097. return nil
  8098. }
  8099. // 耗材出库删除
  8100. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8101. // 先根据相关信息查询当天该耗材的出库信息
  8102. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8103. if err != nil {
  8104. return err
  8105. }
  8106. var delete_count int64 = 0
  8107. for _, ware := range warehouseOutInfos {
  8108. // 判断当前出库的数据和删除出库数量
  8109. if good_yc.Count <= ware.Count {
  8110. delete_count = good_yc.Count
  8111. } else {
  8112. delete_count = ware.Count
  8113. }
  8114. warehouseOutInfo := &models.WarehouseOutInfo{
  8115. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8116. WarehouseOutId: warehouseOut.ID,
  8117. Status: 1,
  8118. Ctime: time.Now().Unix(),
  8119. Remark: "",
  8120. OrgId: orgID,
  8121. Type: 1,
  8122. Manufacturer: 0,
  8123. Dealer: 0,
  8124. IsSys: 0,
  8125. SysRecordTime: record_time,
  8126. GoodTypeId: good_yc.GoodTypeId,
  8127. GoodId: good_yc.GoodId,
  8128. StorehouseId: warehouseOut.StorehouseId,
  8129. IsCheck: 1,
  8130. }
  8131. warehouseOutInfo.Count = delete_count
  8132. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8133. warehouseOutInfo.Price = stockInInfo.Price
  8134. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8135. if errOne != nil {
  8136. return errOne
  8137. }
  8138. // 删除出库完成后,要改变流水库存(有疑问)
  8139. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8140. fmt.Println("errOne", errOne)
  8141. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8142. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8143. //扣减出库数量
  8144. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8145. if errThree != nil {
  8146. return errThree
  8147. }
  8148. }
  8149. if good_yc.Count == 0 {
  8150. return nil
  8151. } else {
  8152. return errors.New("退库和出库数据不匹配")
  8153. }
  8154. }
  8155. func (this *DialysisAPIController) GetMobileScheduleList() {
  8156. limit, _ := this.GetInt64("limit")
  8157. page, _ := this.GetInt64("page")
  8158. type_options_visible, _ := this.GetInt64("type_options_visible")
  8159. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8160. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8161. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8162. }
  8163. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8164. newArr = make([]*models.HisPrescriptionProject, 0)
  8165. for i := 0; i < len(arr); i++ {
  8166. repeat := false
  8167. for j := i + 1; j < len(arr); j++ {
  8168. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8169. repeat = true
  8170. break
  8171. }
  8172. }
  8173. if !repeat {
  8174. newArr = append(newArr, arr[i])
  8175. }
  8176. }
  8177. return
  8178. }
  8179. func (this *DialysisAPIController) GetRoleList() {
  8180. admin_user_id, _ := this.GetInt64("admin_user_id")
  8181. orgid := this.GetMobileAdminUserInfo().Org.Id
  8182. list, err := service.GetRoleList(orgid, admin_user_id)
  8183. fmt.Println(err)
  8184. this.ServeSuccessJSON(map[string]interface{}{
  8185. "list": list,
  8186. })
  8187. return
  8188. }
  8189. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8190. // 先根据相关信息查询当天该耗材的出库信息
  8191. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8192. if err != nil {
  8193. return err
  8194. }
  8195. var delete_count int64 = 0
  8196. delete_count = warehouseOutInfos.Count - count
  8197. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8198. // 删除出库完成后,要增加对应批次的库存数量
  8199. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8200. if errThree != nil {
  8201. return errThree
  8202. }
  8203. //增加退库数量
  8204. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8205. //扣减出库数量
  8206. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8207. //查询剩余库存
  8208. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8209. var sum_count int64
  8210. for _, item := range goodList {
  8211. sum_count += item.StockCount
  8212. }
  8213. // 在出库记录表里记录退库详情
  8214. warehouseOutInfo := &models.WarehouseOutInfo{
  8215. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8216. WarehouseOutId: warehouseOut.ID,
  8217. Status: 1,
  8218. Ctime: time.Now().Unix(),
  8219. OrgId: orgID,
  8220. Type: 1,
  8221. IsSys: 1,
  8222. SysRecordTime: record_time,
  8223. GoodTypeId: good_yc.GoodTypeId,
  8224. GoodId: good_yc.GoodId,
  8225. PatientId: good_yc.PatientId,
  8226. ConsumableType: 2,
  8227. StorehouseId: houseConfig.StorehouseOutInfo,
  8228. IsCheck: 1,
  8229. OverCount: sum_count,
  8230. }
  8231. warehouseOutInfo.Count = count
  8232. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8233. warehouseOutInfo.Price = stockInInfo.Price
  8234. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8235. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8236. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8237. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8238. warehouseOutInfo.Number = warehouseOutInfos.Number
  8239. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8240. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8241. //查找当天是否存在出库记录
  8242. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8243. if errcod == gorm.ErrRecordNotFound {
  8244. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  8245. //插入详情明细表
  8246. if errOne != nil {
  8247. return errOne
  8248. }
  8249. //插入详情明细表
  8250. stockFlow := models.VmStockFlow{
  8251. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8252. WarehouseOutId: warehouseOut.ID,
  8253. GoodId: good_yc.GoodId,
  8254. Number: warehouseOutInfos.Number,
  8255. ProductDate: stockInInfo.ProductDate,
  8256. ExpireDate: stockInInfo.ExpiryDate,
  8257. Count: count,
  8258. Price: stockInInfo.Price,
  8259. Status: 1,
  8260. Ctime: record_time,
  8261. UserOrgId: good_yc.OrgId,
  8262. Manufacturer: stockInInfo.Manufacturer,
  8263. Dealer: stockInInfo.Dealer,
  8264. LicenseNumber: stockInInfo.LicenseNumber,
  8265. IsEdit: 2,
  8266. Creator: creater,
  8267. SystemTime: record_time,
  8268. ConsumableType: 3,
  8269. WarehousingDetailId: 0,
  8270. IsSys: 1,
  8271. UpdateCreator: creater,
  8272. PatientId: patient_id,
  8273. StorehouseId: houseConfig.StorehouseOutInfo,
  8274. OverCount: sum_count,
  8275. ProjectId: good_yc.ProjectId,
  8276. }
  8277. err := service.CreateStockFlowOne(stockFlow)
  8278. fmt.Println("err", err)
  8279. } else if errcod == nil {
  8280. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8281. }
  8282. //创建退库单
  8283. operation_time := time.Now().Unix()
  8284. //创建退库单
  8285. timeStr := time.Now().Format("2006-01-02")
  8286. timeArr := strings.Split(timeStr, "-")
  8287. total, _ := service.FindAllCancelStockTotal(orgID)
  8288. total = total + 1
  8289. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8290. cancelStock := models.CancelStock{
  8291. OrderNumber: orderNumber,
  8292. OperaTime: operation_time,
  8293. OrgId: orgID,
  8294. Creater: warehouseOut.Creater,
  8295. Ctime: time.Now().Unix(),
  8296. Status: 1,
  8297. ReturnTime: record_time,
  8298. Type: 1,
  8299. StorehouseId: stockInInfo.StorehouseId,
  8300. IsCheck: 1,
  8301. }
  8302. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8303. if msgerrkonde == gorm.ErrRecordNotFound {
  8304. service.AddSigleCancelStock(&cancelStock)
  8305. }
  8306. cancel, _ := service.GetLastCancelStockById(orgID)
  8307. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8308. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8309. cancelStockInfo := models.CancelStockInfo{
  8310. GoodId: stockInInfo.GoodId,
  8311. CancelStockId: cancel.ID,
  8312. GoodTypeId: stockInInfo.GoodTypeId,
  8313. Count: delete_count,
  8314. Price: stockInInfo.PackingPrice,
  8315. Total: 0,
  8316. ProductDate: stockInInfo.ProductDate,
  8317. ExpiryDate: stockInInfo.ExpiryDate,
  8318. Ctime: record_time,
  8319. Status: 1,
  8320. OrgId: orgID,
  8321. OrderNumber: cancel.OrderNumber,
  8322. Type: 0,
  8323. Dealer: deaerler.DealerName,
  8324. Manufacturer: manufacturer.ManufacturerName,
  8325. Number: stockInInfo.Number,
  8326. RegisterAccount: "",
  8327. Remark: "",
  8328. WarehouseInfoId: stockInInfo.ID,
  8329. PatientId: patient_id,
  8330. RecordDate: record_time,
  8331. StorehouseId: stockInInfo.StorehouseId,
  8332. IsCheck: 1,
  8333. }
  8334. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8335. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8336. flow := models.VmStockFlow{
  8337. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8338. GoodId: good_yc.GoodId,
  8339. Number: warehouseOutInfos.Number,
  8340. LicenseNumber: stockInInfo.LicenseNumber,
  8341. Count: delete_count,
  8342. UserOrgId: orgID,
  8343. PatientId: patient_id,
  8344. SystemTime: record_time,
  8345. ConsumableType: 7,
  8346. IsSys: 0,
  8347. WarehousingOrder: "",
  8348. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8349. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8350. IsEdit: 0,
  8351. CancelStockId: cancel.ID,
  8352. CancelOrderNumber: cancel.OrderNumber,
  8353. Manufacturer: manufacturer.ID,
  8354. Dealer: 0,
  8355. Creator: warehouseOut.Creater,
  8356. UpdateCreator: 0,
  8357. Status: 1,
  8358. Ctime: record_time,
  8359. Mtime: 0,
  8360. Price: stockInInfo.Price,
  8361. WarehousingDetailId: stockInInfo.ID,
  8362. WarehouseOutDetailId: warehouseOutInfos.ID,
  8363. CancelOutDetailId: cancelInfo.ID,
  8364. ProductDate: stockInInfo.ProductDate,
  8365. ExpireDate: stockInInfo.ExpiryDate,
  8366. StorehouseId: houseConfig.StorehouseOutInfo,
  8367. OverCount: sum_count,
  8368. }
  8369. service.CreateStockFlowOne(flow)
  8370. //更改自动出库的表格
  8371. details := models.BloodAutomaticReduceDetail{
  8372. WarehouseOutId: warehouseOutInfo.ID,
  8373. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8374. PatientId: patient_id,
  8375. Ctime: time.Now().Unix(),
  8376. Mtime: time.Now().Unix(),
  8377. Status: 1,
  8378. RecordTime: record_time,
  8379. OrgId: orgID,
  8380. GoodId: good_yc.GoodId,
  8381. GoodTypeId: good_yc.GoodTypeId,
  8382. Count: count,
  8383. StorehouseId: houseConfig.StorehouseOutInfo,
  8384. }
  8385. //查询当天耗材是否已经存在数据
  8386. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8387. if errcode == gorm.ErrRecordNotFound {
  8388. errTwo := service.CreateAutoReduceRecord(&details)
  8389. if errTwo != nil {
  8390. return errTwo
  8391. }
  8392. } else if errcode == nil {
  8393. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8394. service.CreateAutoReduceRecord(&details)
  8395. }
  8396. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8397. //增加出库库存数量
  8398. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8399. if good_yc.Count == 0 {
  8400. return nil
  8401. } else {
  8402. return errors.New("退库和出库数据不匹配")
  8403. }
  8404. }
  8405. func (this *DialysisAPIController) SavePatientSign() {
  8406. adminUserInfo := this.GetMobileAdminUserInfo()
  8407. patient_id, _ := this.GetInt64("patient_id")
  8408. dialysis_date, _ := this.GetInt64("dialysis_date")
  8409. orgid := adminUserInfo.Org.Id
  8410. var esdata models.DialysisOrder
  8411. var err error
  8412. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8413. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8414. return
  8415. }
  8416. esdata.Hash = esdata.Hash
  8417. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8418. order := models.DialysisOrder{
  8419. Hash: esdata.Hash,
  8420. Url: esdata.Url,
  8421. }
  8422. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8423. redis := service.RedisClient()
  8424. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8425. redis.Set(key, "", time.Second)
  8426. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8427. //清空key 值
  8428. redis.Set(keyOne, "", time.Second)
  8429. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8430. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8431. //redis.Set(keyTwo, "", time.Second)
  8432. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8433. redis.Set(keyThree, "", time.Second)
  8434. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8435. redis.Set(keyFour, "", time.Second)
  8436. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8437. redis.Set(keyFive, "", time.Second)
  8438. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8439. redis.Set(keySix, "", time.Second)
  8440. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8441. redis.Set(keySeven, "", time.Second)
  8442. if err != nil {
  8443. fmt.Println(err)
  8444. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8445. return
  8446. }
  8447. this.ServeSuccessJSON(map[string]interface{}{
  8448. "electronic_signature": esdata,
  8449. })
  8450. }
  8451. func (this *DialysisAPIController) GetPatientSign() {
  8452. patient_id, _ := this.GetInt64("patient_id")
  8453. dialysis_date, _ := this.GetInt64("dialysis_date")
  8454. adminUserInfo := this.GetMobileAdminUserInfo()
  8455. orgId := adminUserInfo.Org.Id
  8456. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8457. if err != nil {
  8458. fmt.Println(err)
  8459. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8460. return
  8461. }
  8462. this.ServeSuccessJSON(map[string]interface{}{
  8463. "dialysisOrder": dialysisOrder,
  8464. })
  8465. }
  8466. func (this *DialysisAPIController) GetScheduleByPatient() {
  8467. patient_id, _ := this.GetInt64("patient_id")
  8468. schedule_date, _ := this.GetInt64("schedule_date")
  8469. orgid := this.GetMobileAdminUserInfo().Org.Id
  8470. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8471. this.ServeSuccessJSON(map[string]interface{}{
  8472. "schedule": schedule,
  8473. })
  8474. }
  8475. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8476. org_id := this.GetMobileAdminUserInfo().Org.Id
  8477. patient_id, _ := this.GetInt64("patient_id")
  8478. schedule_date, _ := this.GetInt64("schedule_date")
  8479. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8480. this.ServeSuccessJSON(map[string]interface{}{
  8481. "order": order,
  8482. })
  8483. }
  8484. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8485. org_id := this.GetMobileAdminUserInfo().Org.Id
  8486. schedule_date := this.GetString("schedule_date")
  8487. schedule_type, _ := this.GetInt64("schedule_type")
  8488. timeLayout := "2006-01-02"
  8489. loc, _ := time.LoadLocation("Local")
  8490. var startdateunix int64
  8491. if len(schedule_date) > 0 {
  8492. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8493. if err != nil {
  8494. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8495. return
  8496. }
  8497. startdateunix = theTime.Unix()
  8498. }
  8499. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8500. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8501. devices, _ := service.GetAllDevicetByListSix(org_id)
  8502. for key, item := range scheduals {
  8503. // 床位信息
  8504. for _, device := range devices {
  8505. if item.BedId == device.ID {
  8506. scheduals[key].DeviceNumber = device
  8507. break
  8508. }
  8509. }
  8510. }
  8511. this.ServeSuccessJSON(map[string]interface{}{
  8512. "list": list,
  8513. "scheduals": scheduals,
  8514. })
  8515. }
  8516. func (this *DialysisAPIController) SavePatientPicture() {
  8517. patient_id, _ := this.GetInt64("patient_id")
  8518. dialysis_date, _ := this.GetInt64("schedule_date")
  8519. avatar := this.GetString("avatar")
  8520. fmt.Println("patient_id", patient_id)
  8521. orgId := this.GetMobileAdminUserInfo().Org.Id
  8522. order := models.DialysisOrder{
  8523. Url: avatar,
  8524. }
  8525. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8526. redis := service.RedisClient()
  8527. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8528. redis.Set(key, "", time.Second)
  8529. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8530. //清空key 值
  8531. redis.Set(keyOne, "", time.Second)
  8532. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8533. redis.Set(keyThree, "", time.Second)
  8534. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8535. redis.Set(keyFour, "", time.Second)
  8536. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8537. redis.Set(keyFive, "", time.Second)
  8538. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8539. redis.Set(keySix, "", time.Second)
  8540. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8541. redis.Set(keySeven, "", time.Second)
  8542. if err != nil {
  8543. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8544. return
  8545. }
  8546. this.ServeSuccessJSON(map[string]interface{}{
  8547. "order": order,
  8548. })
  8549. }
  8550. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8551. ids := this.GetString("ids")
  8552. idSplit := strings.Split(ids, ",")
  8553. orgId := this.GetMobileAdminUserInfo().Org.Id
  8554. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8555. execution_time := this.GetString("exce_time")
  8556. timeLayout2 := "2006-01-02 15:04:05"
  8557. loc, _ := time.LoadLocation("Local")
  8558. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8559. if errs != nil {
  8560. utils.ErrorLog(errs.Error())
  8561. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8562. return
  8563. }
  8564. //his客户
  8565. if config.IsOpen == 1 {
  8566. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8567. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8568. for _, item := range list {
  8569. for _, it := range adviceList {
  8570. if item.DrugId == it.DrugId {
  8571. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8572. }
  8573. }
  8574. }
  8575. for _, item := range list {
  8576. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8577. var sum_out_count int64
  8578. for _, itemThree := range item.ChildDoctorAdvice {
  8579. var prescribing_number int64
  8580. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8581. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8582. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8583. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8584. }
  8585. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8586. prescribing_number = parseIntPrescribingNumber
  8587. }
  8588. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8589. prescribing_number = parseIntPrescribingNumber
  8590. }
  8591. sum_out_count += prescribing_number
  8592. }
  8593. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8594. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8595. //库存不足
  8596. if sum_out_count > drugStockOut.FlushCount {
  8597. this.ServeSuccessJSON(map[string]interface{}{
  8598. "msg": "2",
  8599. "drug": medical,
  8600. "ids": ids,
  8601. })
  8602. return
  8603. }
  8604. }
  8605. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8606. //执行医嘱
  8607. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8608. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8609. for _, item := range advices {
  8610. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8611. redis := service.RedisClient()
  8612. //清空key 值
  8613. redis.Set(key, "", time.Second)
  8614. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8615. redis.Set(keyTwo, "", time.Second)
  8616. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8617. redis.Set(keyThree, "", time.Second)
  8618. recordDate := theTime.Format("2006-01-02")
  8619. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8620. redis.Set(keyFour, "", time.Second)
  8621. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8622. redis.Set(keyFive, "", time.Second)
  8623. defer redis.Close()
  8624. }
  8625. if errs == nil {
  8626. //药品管理信息
  8627. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8628. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8629. if drugStockConfig.IsOpen == 1 {
  8630. for _, item := range advices {
  8631. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8632. config, _ := service.GetDrugOpenConfigOne(orgId)
  8633. if config.IsOpen != 1 {
  8634. //查询该药品是否有库存
  8635. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8636. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8637. if medical.IsUse == 2 {
  8638. if config.IsOpen != 1 {
  8639. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8640. service.HisDrugsDelivery(orgId, creater, &advice)
  8641. if orgId == 3877 || orgId == 10265 {
  8642. //查询该药品是否有出库记录
  8643. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8644. if len(flowMap) == 0 {
  8645. errs := service.UpdateHisAdviceById(advice.ID)
  8646. if errs != nil {
  8647. drugError := models.XtDrugError{
  8648. UserOrgId: orgId,
  8649. DrugId: item.DrugId,
  8650. RecordDate: item.AdviceDate,
  8651. PatientId: item.PatientId,
  8652. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8653. Status: 1,
  8654. Ctime: time.Now().Unix(),
  8655. Mtime: 0,
  8656. SumCount: 0,
  8657. Prescribingnumber: advice.PrescribingNumber,
  8658. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8659. }
  8660. service.CreateDrugError(drugError)
  8661. }
  8662. this.ServeSuccessJSON(map[string]interface{}{
  8663. "msg": "2",
  8664. "drug": medical,
  8665. "ids": ids,
  8666. })
  8667. return
  8668. }
  8669. }
  8670. }
  8671. if pharmacyConfig.IsOpen != 1 {
  8672. service.HisDrugsDelivery(orgId, creater, &advice)
  8673. if orgId == 3877 || orgId == 10265 {
  8674. //查询该药品是否有出库记录
  8675. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8676. if len(flowMap) == 0 {
  8677. errs := service.UpdateHisAdviceById(advice.ID)
  8678. if errs != nil {
  8679. drugError := models.XtDrugError{
  8680. UserOrgId: orgId,
  8681. DrugId: item.DrugId,
  8682. RecordDate: item.AdviceDate,
  8683. PatientId: item.PatientId,
  8684. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8685. Status: 1,
  8686. Ctime: time.Now().Unix(),
  8687. Mtime: 0,
  8688. SumCount: 0,
  8689. Prescribingnumber: advice.PrescribingNumber,
  8690. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8691. }
  8692. service.CreateDrugError(drugError)
  8693. }
  8694. this.ServeSuccessJSON(map[string]interface{}{
  8695. "msg": "2",
  8696. "drug": medical,
  8697. "ids": ids,
  8698. })
  8699. return
  8700. }
  8701. }
  8702. }
  8703. //更新字典里面的库存
  8704. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8705. var sum_count int64
  8706. for _, its := range stockInfo {
  8707. if its.MaxUnit == medical.MaxUnit {
  8708. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8709. }
  8710. sum_count += its.StockMaxNumber + its.StockMinNumber
  8711. }
  8712. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8713. //剩余库存
  8714. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8715. }
  8716. }
  8717. }
  8718. }
  8719. }
  8720. this.ServeSuccessJSON(map[string]interface{}{
  8721. "msg": "1",
  8722. "ids": ids,
  8723. })
  8724. return
  8725. } else {
  8726. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8727. }
  8728. }
  8729. //血透客户
  8730. if config.IsOpen == 2 || config.IsOpen == 0 {
  8731. //药品管理信息
  8732. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8733. if drugStockConfig.IsOpen == 1 {
  8734. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8735. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8736. for _, item := range list {
  8737. for _, it := range adviceList {
  8738. if item.DrugId == it.DrugId {
  8739. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8740. }
  8741. }
  8742. }
  8743. for _, item := range list {
  8744. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8745. var sum_out_count int64
  8746. for _, itemThree := range item.ChildDoctorAdvice {
  8747. var prescribing_number int64
  8748. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8749. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8750. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8751. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8752. }
  8753. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8754. prescribing_number = parseIntPrescribingNumber
  8755. }
  8756. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8757. prescribing_number = parseIntPrescribingNumber
  8758. }
  8759. sum_out_count += prescribing_number
  8760. }
  8761. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8762. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8763. //库存不足
  8764. if sum_out_count > drugStockOut.FlushCount {
  8765. this.ServeSuccessJSON(map[string]interface{}{
  8766. "msg": "2",
  8767. "drug": medical,
  8768. "ids": ids,
  8769. })
  8770. return
  8771. }
  8772. }
  8773. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8774. //执行医嘱
  8775. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8776. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8777. for _, item := range advices {
  8778. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8779. redis := service.RedisClient()
  8780. //清空key 值
  8781. redis.Set(key, "", time.Second)
  8782. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8783. redis.Set(keyTwo, "", time.Second)
  8784. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8785. redis.Set(keyThree, "", time.Second)
  8786. recordDate := theTime.Format("2006-01-02")
  8787. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8788. redis.Set(keyFour, "", time.Second)
  8789. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8790. redis.Set(keyFive, "", time.Second)
  8791. defer redis.Close()
  8792. }
  8793. if errs == nil {
  8794. for _, item := range advices {
  8795. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8796. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8797. //查询是否出库按钮开启
  8798. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8799. if adviceSetting.IsAdviceOpen == 1 {
  8800. //查询是否出库按钮开启
  8801. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8802. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8803. if prescriptionConfig.IsOpen == 1 {
  8804. if medical.IsUse == 2 {
  8805. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8806. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8807. }
  8808. if pharmacyConfig.IsOpen != 1 {
  8809. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8810. }
  8811. //更新字典里面的库存
  8812. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8813. var sum_count int64
  8814. for _, its := range stockInfo {
  8815. if its.MaxUnit == medical.MaxUnit {
  8816. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8817. }
  8818. sum_count += its.StockMaxNumber + its.StockMinNumber
  8819. }
  8820. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8821. //剩余库存
  8822. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8823. }
  8824. }
  8825. } else {
  8826. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8827. if medical.IsUse == 2 {
  8828. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8829. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8830. }
  8831. if pharmacyConfig.IsOpen != 1 {
  8832. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8833. }
  8834. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8835. var sum_count int64
  8836. for _, its := range stockInfo {
  8837. if its.MaxUnit == medical.MaxUnit {
  8838. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8839. }
  8840. sum_count += its.StockMaxNumber + its.StockMinNumber
  8841. }
  8842. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8843. //剩余库存
  8844. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8845. }
  8846. }
  8847. }
  8848. }
  8849. this.ServeSuccessJSON(map[string]interface{}{
  8850. "msg": "1",
  8851. "ids": ids,
  8852. })
  8853. return
  8854. } else {
  8855. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8856. //执行医嘱
  8857. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8858. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8859. for _, item := range advices {
  8860. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8861. redis := service.RedisClient()
  8862. //清空key 值
  8863. redis.Set(key, "", time.Second)
  8864. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8865. redis.Set(keyTwo, "", time.Second)
  8866. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8867. redis.Set(keyThree, "", time.Second)
  8868. recordDate := theTime.Format("2006-01-02")
  8869. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8870. redis.Set(keyFour, "", time.Second)
  8871. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8872. redis.Set(keyFive, "", time.Second)
  8873. defer redis.Close()
  8874. }
  8875. this.ServeSuccessJSON(map[string]interface{}{
  8876. "msg": "1",
  8877. "ids": ids,
  8878. })
  8879. return
  8880. }
  8881. }
  8882. }
  8883. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8884. ids := this.GetString("ids")
  8885. idSplit := strings.Split(ids, ",")
  8886. orgId := this.GetMobileAdminUserInfo().Org.Id
  8887. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8888. if config.IsOpen == 1 {
  8889. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8890. this.ServeSuccessJSON(map[string]interface{}{
  8891. "msg": "1",
  8892. "ids": ids,
  8893. })
  8894. return
  8895. }
  8896. if config.IsOpen == 0 || config.IsOpen == 2 {
  8897. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8898. this.ServeSuccessJSON(map[string]interface{}{
  8899. "msg": "1",
  8900. "ids": ids,
  8901. })
  8902. return
  8903. }
  8904. }
  8905. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8906. ids := this.GetString("ids")
  8907. idSplit := strings.Split(ids, ",")
  8908. orgId := this.GetMobileAdminUserInfo().Org.Id
  8909. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8910. //his
  8911. if config.IsOpen == 1 {
  8912. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8913. theTime := time.Now()
  8914. advices := models.HisDoctorAdviceThirty{
  8915. CheckTime: theTime.Unix(),
  8916. Checker: checker,
  8917. UpdatedTime: time.Now().Unix(),
  8918. }
  8919. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8920. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8921. for _, item := range list {
  8922. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8923. redis := service.RedisClient()
  8924. //清空key 值
  8925. redis.Set(key, "", time.Second)
  8926. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8927. redis.Set(keyTwo, "", time.Second)
  8928. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8929. redis.Set(keyThree, "", time.Second)
  8930. recordDate := theTime.Format("2006-01-02")
  8931. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8932. redis.Set(keyFour, "", time.Second)
  8933. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8934. redis.Set(keyFive, "", time.Second)
  8935. defer redis.Close()
  8936. }
  8937. this.ServeSuccessJSON(map[string]interface{}{
  8938. "msg": "1",
  8939. "ids": ids,
  8940. })
  8941. return
  8942. }
  8943. //血透
  8944. if config.IsOpen == 0 || config.IsOpen == 2 {
  8945. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8946. theTime := time.Now()
  8947. advices := models.DoctorAdvice{
  8948. CheckTime: theTime.Unix(),
  8949. Checker: checker,
  8950. UpdatedTime: time.Now().Unix(),
  8951. }
  8952. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8953. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8954. for _, item := range list {
  8955. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8956. redis := service.RedisClient()
  8957. //清空key 值
  8958. redis.Set(key, "", time.Second)
  8959. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8960. redis.Set(keyTwo, "", time.Second)
  8961. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8962. redis.Set(keyThree, "", time.Second)
  8963. recordDate := theTime.Format("2006-01-02")
  8964. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8965. redis.Set(keyFour, "", time.Second)
  8966. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8967. redis.Set(keyFive, "", time.Second)
  8968. defer redis.Close()
  8969. }
  8970. this.ServeSuccessJSON(map[string]interface{}{
  8971. "msg": "1",
  8972. "ids": ids,
  8973. })
  8974. return
  8975. }
  8976. }
  8977. func (this *DialysisAPIController) CheckSchedule() {
  8978. patientID, _ := this.GetInt64("patient_id")
  8979. recordDateStr := this.GetString("record_date")
  8980. nurseID, _ := this.GetInt64("start_nurse")
  8981. schedual_type, _ := this.GetInt64("schedual_type")
  8982. bedID, _ := this.GetInt64("bed")
  8983. start_time := this.GetString("start_time")
  8984. fmt.Println("patientID", patientID)
  8985. fmt.Println("recordDateStr", recordDateStr)
  8986. fmt.Println("nurseID", nurseID)
  8987. fmt.Println("schedual_type------", schedual_type)
  8988. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8990. return
  8991. }
  8992. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8993. if parseStartDateErr != nil {
  8994. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8995. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8996. return
  8997. }
  8998. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8999. if parseErr != nil {
  9000. this.ErrorLog("时间解析失败:%v", parseErr)
  9001. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9002. return
  9003. }
  9004. adminUserInfo := this.GetMobileAdminUserInfo()
  9005. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9006. if getPatientErr != nil {
  9007. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9008. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9009. return
  9010. } else if patient == nil {
  9011. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9012. return
  9013. }
  9014. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9015. if getNurseErr != nil {
  9016. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9017. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9018. return
  9019. } else if nurse == nil {
  9020. this.ErrorLog("护士不存在")
  9021. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9022. return
  9023. }
  9024. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9025. if getDeviceNumberErr != nil {
  9026. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9027. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9028. return
  9029. } else if deviceNumber == nil {
  9030. this.ErrorLog("床位号不存在")
  9031. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9032. return
  9033. }
  9034. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9035. if getRecordErr != nil {
  9036. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9037. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9038. return
  9039. } else if dialysisRecord != nil {
  9040. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9041. return
  9042. }
  9043. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9044. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9045. timeLayout := "2006-01-02 15:04:05"
  9046. loc, _ := time.LoadLocation("Local")
  9047. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9048. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9049. schedulestartTime := theStartTime.Unix()
  9050. scheduleendTime := theEndTime.Unix()
  9051. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9052. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9053. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9054. //查询该床位是否有人用了
  9055. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9056. if err == nil {
  9057. if schedule.ID == 0 {
  9058. this.ServeSuccessJSON(map[string]interface{}{
  9059. "status": 0,
  9060. "msg": "请求失败",
  9061. })
  9062. } else {
  9063. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9064. if order.ID > 0 { //该机位被其他人占用了
  9065. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9066. return
  9067. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9068. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9069. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9070. this.ServeSuccessJSON(map[string]interface{}{
  9071. "status": 1,
  9072. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9073. })
  9074. return
  9075. } else {
  9076. this.ServeSuccessJSON(map[string]interface{}{
  9077. "status": 0,
  9078. "msg": "",
  9079. })
  9080. }
  9081. }
  9082. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9083. this.ServeSuccessJSON(map[string]interface{}{
  9084. "status": 2,
  9085. "msg": "当前机位已有患者在使用,请重新选择!",
  9086. })
  9087. }
  9088. }
  9089. } else {
  9090. this.ServeSuccessJSON(map[string]interface{}{
  9091. "status": 0,
  9092. "msg": "",
  9093. })
  9094. }
  9095. }
  9096. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9097. orgId := this.GetMobileAdminUserInfo().Org.Id
  9098. schedule_type, _ := this.GetInt64("schedule_type")
  9099. partion_type, _ := this.GetInt64("partion_type")
  9100. start_time := this.GetString("start_time")
  9101. timeLayout := "2006-01-02"
  9102. loc, _ := time.LoadLocation("Local")
  9103. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9104. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9105. _, config := service.FindXTHisRecordByOrgId(orgId)
  9106. appId := this.GetMobileAdminUserInfo().App.Id
  9107. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9108. if err == nil {
  9109. this.ServeSuccessJSON(map[string]interface{}{
  9110. "list": list,
  9111. "config": config,
  9112. "doctorList": doctorList,
  9113. })
  9114. return
  9115. } else {
  9116. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9117. return
  9118. }
  9119. }
  9120. func (this *DialysisAPIController) SaveMobileInformation() {
  9121. patient_id, _ := this.GetInt64("patient_id")
  9122. record_date, _ := this.GetInt64("record_date")
  9123. startTime := this.GetString("start_time")
  9124. module, _ := this.GetInt64("module")
  9125. remark := this.GetString("remark")
  9126. timeLayout := "2006-01-02 15:04"
  9127. loc, _ := time.LoadLocation("Local")
  9128. if len(startTime) == 0 {
  9129. utils.ErrorLog("len(start_time) == 0")
  9130. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9131. return
  9132. }
  9133. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9134. if err != nil {
  9135. utils.ErrorLog(err.Error())
  9136. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9137. return
  9138. }
  9139. StartTime := theTime.Unix()
  9140. fmt.Println("startime-------------", StartTime)
  9141. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9142. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9143. information := models.XtDialysisInformation{
  9144. Module: module,
  9145. PatientId: patient_id,
  9146. RecordDate: record_date,
  9147. ApplicationDate: StartTime,
  9148. Creater: creater,
  9149. ApplicationStatus: 2,
  9150. Checker: 0,
  9151. CheckTime: 0,
  9152. Remark: remark,
  9153. UserOrgId: user_org_id,
  9154. Ctime: time.Now().Unix(),
  9155. Status: 1,
  9156. Mtime: 0,
  9157. }
  9158. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9159. if infor.ID == 0 {
  9160. service.SaveDialysisInformation(information)
  9161. }
  9162. if infor.ID > 0 {
  9163. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9164. }
  9165. this.ServeSuccessJSON(map[string]interface{}{
  9166. "information": information,
  9167. })
  9168. return
  9169. }
  9170. func (this *DialysisAPIController) GetMobileInformation() {
  9171. limit, _ := this.GetInt64("limit")
  9172. page, _ := this.GetInt64("page")
  9173. orgid := this.GetMobileAdminUserInfo().Org.Id
  9174. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9175. appid := this.GetMobileAdminUserInfo().App.Id
  9176. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9177. patients, _ := service.GetAllpatientThirty(orgid)
  9178. this.ServeSuccessJSON(map[string]interface{}{
  9179. "information": information,
  9180. "total": total,
  9181. "doclist": doclist,
  9182. "patients": patients,
  9183. })
  9184. return
  9185. }
  9186. func (this *DialysisAPIController) GetMobileInformationOne() {
  9187. limit, _ := this.GetInt64("limit")
  9188. page, _ := this.GetInt64("page")
  9189. orgid := this.GetMobileAdminUserInfo().Org.Id
  9190. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9191. appid := this.GetMobileAdminUserInfo().App.Id
  9192. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9193. patients, _ := service.GetAllpatientThirty(orgid)
  9194. this.ServeSuccessJSON(map[string]interface{}{
  9195. "information": information,
  9196. "total": total,
  9197. "doclist": doclist,
  9198. "patients": patients,
  9199. })
  9200. return
  9201. }
  9202. func (this *DialysisAPIController) CheckMobileInformation() {
  9203. id, _ := this.GetInt64("id")
  9204. application_status, _ := this.GetInt64("application_status")
  9205. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9206. checktime := time.Now().Unix()
  9207. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9208. if err == nil {
  9209. this.ServeSuccessJSON(map[string]interface{}{
  9210. "msg": "ok",
  9211. })
  9212. return
  9213. }
  9214. }
  9215. func (c *DialysisAPIController) GetControlMonitorList() {
  9216. partition, _ := c.GetInt64("partition")
  9217. monitorDate := c.GetString("date")
  9218. patient_id, _ := c.GetInt64("patient_id")
  9219. pat_type, _ := c.GetInt64("pat_type")
  9220. timeLayout := "2006-01-02"
  9221. loc, _ := time.LoadLocation("Local")
  9222. var theStartTime int64
  9223. if len(monitorDate) > 0 {
  9224. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9225. if err != nil {
  9226. theStartTime = 0
  9227. }
  9228. theStartTime = theTime.Unix()
  9229. }
  9230. adminInfo := c.GetMobileAdminUserInfo()
  9231. orgID := adminInfo.Org.Id
  9232. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9233. if err != nil {
  9234. c.ErrorLog("获取排班信息失败:%v", err)
  9235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9236. } else {
  9237. if len(monitor) > 0 {
  9238. //获取所有床位
  9239. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9240. //获取所有分区
  9241. zoneList, _ := service.GetAllZoneByList(orgID)
  9242. //获取透析处方
  9243. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9244. //获取透前评估
  9245. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9246. //获取上机
  9247. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9248. //获取透后
  9249. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9250. //获取透后监测
  9251. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9252. //获取所有的患者
  9253. patients, _ := service.GetAllPatientListByListOne(orgID)
  9254. //获取所有透析模式
  9255. treatments, _ := service.GetAllTreatModeByList(orgID)
  9256. //获取所有医嘱
  9257. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9258. //获取双人核对
  9259. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9260. //治疗小结
  9261. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9262. //待消毒
  9263. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9264. for key, item := range monitor {
  9265. // 获取床位信息
  9266. for _, it := range numberList {
  9267. if item.BedId == it.ID {
  9268. monitor[key].DeviceNumber = it
  9269. break
  9270. }
  9271. }
  9272. //获取分区信息
  9273. for _, it := range zoneList {
  9274. if item.PartitionId == it.ID {
  9275. monitor[key].DeviceZone = it
  9276. }
  9277. }
  9278. for _, prescription := range prescriptions {
  9279. if item.PatientId == prescription.PatientId {
  9280. monitor[key].Prescription = prescription
  9281. break
  9282. }
  9283. }
  9284. for _, it := range checkList {
  9285. if item.PatientId == it.PatientId {
  9286. monitor[key].DoubleCheck = it
  9287. break
  9288. }
  9289. }
  9290. for _, it := range summaryList {
  9291. if item.PatientId == it.PatientId {
  9292. monitor[key].TreatmentSummaryForList = it
  9293. break
  9294. }
  9295. }
  9296. // 透前评估
  9297. for _, assessmentBefore := range assessmentBefores {
  9298. if item.PatientId == assessmentBefore.PatientId {
  9299. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9300. break
  9301. }
  9302. }
  9303. // 透析上下机
  9304. for _, dialysisOrder := range dialysisOrders {
  9305. if item.PatientId == dialysisOrder.PatientId {
  9306. monitor[key].DialysisOrder = dialysisOrder
  9307. break
  9308. }
  9309. }
  9310. // 治疗小节
  9311. for _, afterDislysis := range AssessmentAfterDislysis {
  9312. if item.PatientId == afterDislysis.PatientId {
  9313. monitor[key].AssessmentAfterDislysis = afterDislysis
  9314. break
  9315. }
  9316. }
  9317. for _, it := range monitorlist {
  9318. if item.PatientId == it.PatientId {
  9319. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9320. }
  9321. }
  9322. for _, it := range adviceList {
  9323. if item.PatientId == it.PatientId {
  9324. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9325. }
  9326. }
  9327. for _, patient := range patients {
  9328. if item.PatientId == patient.ID {
  9329. monitor[key].MonitorPatients = patient
  9330. break
  9331. }
  9332. }
  9333. for _, treatment := range treatments {
  9334. if item.ModeId == treatment.ID {
  9335. monitor[key].TreatmentMode = treatment
  9336. break
  9337. }
  9338. }
  9339. for _, infor := range informationList {
  9340. if item.PatientId == infor.PatientId {
  9341. monitor[key].NewDeviceInformation = infor
  9342. break
  9343. }
  9344. }
  9345. }
  9346. }
  9347. }
  9348. patients, err := service.GetAllpatientFourty(orgID)
  9349. var mds []*models.NewMonitorDialysisScheduleList
  9350. if pat_type == 0 {
  9351. for _, item := range monitor {
  9352. mds = append(mds, item)
  9353. }
  9354. }
  9355. //待医嘱核对
  9356. if pat_type == 1 {
  9357. for _, item := range monitor {
  9358. if len(item.AdviceList) > 0 {
  9359. mds = append(mds, item)
  9360. }
  9361. }
  9362. }
  9363. //待开小结
  9364. if pat_type == 2 {
  9365. for _, item := range monitor {
  9366. if item.TreatmentSummaryForList == nil {
  9367. mds = append(mds, item)
  9368. }
  9369. }
  9370. }
  9371. //待下机
  9372. if pat_type == 3 {
  9373. for _, item := range monitor {
  9374. if item.DialysisOrder != nil {
  9375. if item.DialysisOrder.ID > 0 {
  9376. mds = append(mds, item)
  9377. }
  9378. }
  9379. }
  9380. }
  9381. //待消毒
  9382. if pat_type == 4 {
  9383. for _, item := range monitor {
  9384. if item.NewDeviceInformation == nil {
  9385. mds = append(mds, item)
  9386. }
  9387. }
  9388. }
  9389. //待双人核对
  9390. if pat_type == 5 {
  9391. for _, item := range monitor {
  9392. if item.DoubleCheck == nil {
  9393. mds = append(mds, item)
  9394. }
  9395. }
  9396. }
  9397. //医嘱未执行
  9398. if pat_type == 6 {
  9399. for _, item := range monitor {
  9400. if len(item.AdviceList) > 0 {
  9401. mds = append(mds, item)
  9402. }
  9403. }
  9404. }
  9405. //患者未签名
  9406. if pat_type == 7 {
  9407. for _, item := range monitor {
  9408. if item.DialysisOrder != nil {
  9409. if item.DialysisOrder.ID > 0 {
  9410. mds = append(mds, item)
  9411. }
  9412. }
  9413. }
  9414. }
  9415. //目标超滤于实际超滤不同
  9416. if pat_type == 8 {
  9417. for _, item := range monitor {
  9418. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9419. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9420. mds = append(mds, item)
  9421. }
  9422. }
  9423. }
  9424. }
  9425. //血压少于5次
  9426. if pat_type == 9 {
  9427. for _, item := range monitor {
  9428. if len(item.MonitoringRecord) < 5 {
  9429. mds = append(mds, item)
  9430. }
  9431. }
  9432. }
  9433. if pat_type == 10 {
  9434. for _, item := range monitor {
  9435. if len(item.MonitoringRecord) == 0 {
  9436. mds = append(mds, item)
  9437. }
  9438. }
  9439. }
  9440. if pat_type == 11 {
  9441. for _, item := range monitor {
  9442. if len(item.MonitoringRecord) > 0 {
  9443. mds = append(mds, item)
  9444. }
  9445. }
  9446. }
  9447. if pat_type == 12 {
  9448. for _, item := range monitor {
  9449. if len(item.MonitoringRecord) > 0 {
  9450. mds = append(mds, item)
  9451. }
  9452. }
  9453. }
  9454. if err == nil {
  9455. c.ServeSuccessJSON(map[string]interface{}{
  9456. "monitor": mds,
  9457. "patients": patients,
  9458. })
  9459. } else {
  9460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9461. }
  9462. }
  9463. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9464. admin_user_id, _ := c.GetInt64("admin_user_id")
  9465. timeStr := time.Now().Format("2006-01-02")
  9466. timeLayout := "2006-01-02 15:04:05"
  9467. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9468. timenow := timeStringToTime.Unix()
  9469. orgId := c.GetMobileAdminUserInfo().Org.Id
  9470. //查询当前护士的患者
  9471. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9472. var patientIds []int64
  9473. for _, item := range orderList {
  9474. patientIds = append(patientIds, item.PatientId)
  9475. }
  9476. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9477. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9478. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9479. //药品管理信息
  9480. _, drugStockConfig := service.FindHisConfig(orgId)
  9481. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9482. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9483. c.ServeSuccessJSON(map[string]interface{}{
  9484. "adviceList": adviceList,
  9485. "hisAdviceList": hisAdviceList,
  9486. "projectList": projectList,
  9487. "drugStockConfig": drugStockConfig,
  9488. "patientList": patientList,
  9489. "projectConfig": projectConfig,
  9490. })
  9491. }
  9492. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9493. patient_id, _ := c.GetInt64("patient_id")
  9494. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9495. c.ServeSuccessJSON(map[string]interface{}{
  9496. "recrods": recrods,
  9497. })
  9498. }
  9499. func (c *DialysisAPIController) ExMobileChangeSch() {
  9500. id_one, _ := c.GetInt64("id_one")
  9501. id_two, _ := c.GetInt64("id_two")
  9502. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9503. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9504. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9505. //if order2.ID > 0 {
  9506. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9507. // return
  9508. //}
  9509. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9510. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9511. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9512. if count > 0 {
  9513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9514. return
  9515. }
  9516. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9517. if count1 > 0 {
  9518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9519. return
  9520. }
  9521. }
  9522. err := service.UpdateScheduleThree(sch, sch_two)
  9523. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9524. if order.ID > 0 {
  9525. //查询该患者的排班机位
  9526. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9527. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  9528. redis := service.RedisClient()
  9529. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9530. redis.Set(key, "", time.Second)
  9531. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9532. //清空key 值
  9533. redis.Set(keyOne, "", time.Second)
  9534. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  9535. //return
  9536. }
  9537. if err == nil {
  9538. //去除当天患者排班中重复数据,保留最后一条数据
  9539. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9540. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9541. c.ServeSuccessJSON(map[string]interface{}{
  9542. "msg": "交换成功",
  9543. })
  9544. } else {
  9545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9546. return
  9547. }
  9548. }
  9549. func (c *DialysisAPIController) MobileCoverSch() {
  9550. id_one, _ := c.GetInt64("id_one")
  9551. id_two, _ := c.GetInt64("id_two")
  9552. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9553. //针对凤凰医院
  9554. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  9555. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9556. if len(advice) > 0 {
  9557. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9558. }
  9559. }
  9560. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  9561. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9562. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9563. if len(hisAdvice) > 0 {
  9564. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9565. }
  9566. if len(project) > 0 {
  9567. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  9568. }
  9569. }
  9570. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9571. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9572. if order.ID > 0 {
  9573. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9574. redis := service.RedisClient()
  9575. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9576. redis.Set(key, "", time.Second)
  9577. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9578. //清空key 值
  9579. redis.Set(keyOne, "", time.Second)
  9580. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9581. //return
  9582. }
  9583. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9584. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9585. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9586. if count > 0 {
  9587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9588. return
  9589. }
  9590. }
  9591. var new_sch models.Schedule
  9592. new_sch = sch
  9593. new_sch.BedId = sch_two.BedId
  9594. new_sch.ScheduleDate = sch_two.ScheduleDate
  9595. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9596. new_sch.PartitionId = sch_two.PartitionId
  9597. new_sch.ScheduleType = sch_two.ScheduleType
  9598. new_sch.ID = 0
  9599. //删除原来的排班
  9600. err := service.SaveSchTwo(sch, sch_two)
  9601. //生成新的排班
  9602. if err == nil {
  9603. err2 := service.SaveSch(&new_sch)
  9604. if err2 == nil {
  9605. //去除当天患者排班中重复数据,保留最后一条数据
  9606. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9607. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9608. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9609. c.ServeSuccessJSON(map[string]interface{}{
  9610. "msg": "覆盖成功",
  9611. "new_sch": new_sch,
  9612. })
  9613. } else {
  9614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9615. return
  9616. }
  9617. } else {
  9618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9619. return
  9620. }
  9621. }
  9622. func (c *DialysisAPIController) BatchCheckAdvice() {
  9623. patient_id, _ := c.GetInt64("patient_id")
  9624. advice_date, _ := c.GetInt64("advice_date")
  9625. org_id := c.GetMobileAdminUserInfo().Org.Id
  9626. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  9627. //查询是his系统还是血透系统
  9628. _, configs := service.FindXTHisRecordByOrgId(org_id)
  9629. //his客户
  9630. if configs.IsOpen == 1 {
  9631. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  9632. for _, item := range adviceList {
  9633. service.BatchCheckHisAdvice(item.ID, creater)
  9634. }
  9635. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9636. for _, item := range projectList {
  9637. service.BatchCheckProject(item.ID, creater)
  9638. }
  9639. c.ServeSuccessJSON(map[string]interface{}{
  9640. "adviceList": adviceList,
  9641. "projectList": projectList,
  9642. })
  9643. }
  9644. if configs.IsOpen != 1 {
  9645. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  9646. for _, item := range adviceList {
  9647. service.BatchAdviceList(item.ID, creater)
  9648. }
  9649. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  9650. for _, item := range projectList {
  9651. service.BatchCheckProject(item.ID, creater)
  9652. }
  9653. c.ServeSuccessJSON(map[string]interface{}{
  9654. "adviceList": adviceList,
  9655. "projectList": projectList,
  9656. })
  9657. }
  9658. return
  9659. }
  9660. func (c *DialysisAPIController) GetAllMobileDrugList() {
  9661. org_id := c.GetMobileAdminUserInfo().Org.Id
  9662. drugList, _ := service.GetAllDrugList(org_id)
  9663. c.ServeSuccessJSON(map[string]interface{}{
  9664. "drugList": drugList,
  9665. })
  9666. }
  9667. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  9668. org_id := c.GetMobileAdminUserInfo().Org.Id
  9669. dataBody := make(map[string]interface{}, 0)
  9670. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9671. if err != nil {
  9672. utils.ErrorLog(err.Error())
  9673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9674. return
  9675. }
  9676. timeLayout := "2006-01-02"
  9677. loc, _ := time.LoadLocation("Local")
  9678. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  9679. utils.ErrorLog("advice_type")
  9680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9681. return
  9682. }
  9683. adviceType := int64(dataBody["advice_type"].(float64))
  9684. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9685. utils.ErrorLog("start_time")
  9686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9687. return
  9688. }
  9689. startTime2, _ := dataBody["start_time"].(string)
  9690. time_arr := strings.Split(startTime2, " ")
  9691. if len(time_arr) > 0 {
  9692. startTime2 = time_arr[0]
  9693. }
  9694. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9695. utils.ErrorLog("advice_date")
  9696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9697. return
  9698. }
  9699. advice_date, _ := dataBody["advice_date"].(string)
  9700. var advicedateunix int64
  9701. if len(advice_date) > 0 {
  9702. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9703. if err != nil {
  9704. fmt.Println(err)
  9705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9706. return
  9707. }
  9708. advicedateunix = theTime.Unix()
  9709. }
  9710. adviceDate := startTime2
  9711. if len(adviceDate) == 0 {
  9712. utils.ErrorLog("len(adviceDate) == 0")
  9713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9714. return
  9715. }
  9716. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9717. if err != nil {
  9718. utils.ErrorLog(err.Error())
  9719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9720. return
  9721. }
  9722. AdviceDate := advicedateunix
  9723. RecordDate := advicedateunix
  9724. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9725. utils.ErrorLog("start_time")
  9726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9727. return
  9728. }
  9729. startTime, _ := dataBody["start_time"].(string)
  9730. if len(startTime) == 0 {
  9731. utils.ErrorLog("len(start_time) == 0")
  9732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9733. return
  9734. }
  9735. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9736. if err != nil {
  9737. utils.ErrorLog(err.Error())
  9738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9739. return
  9740. }
  9741. StartTime := theTime.Unix()
  9742. advice_name, _ := dataBody["advice_name"].(string)
  9743. advice_desc, _ := dataBody["advice_desc"].(string)
  9744. delivery_way, _ := dataBody["delivery_way"].(string)
  9745. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9746. frequency_type := int64(dataBody["frequency_type"].(float64))
  9747. frequency_week, _ := dataBody["frequency_week"].(string)
  9748. prescribing_number := dataBody["prescribing_number"].(float64)
  9749. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9750. remark := dataBody["remark"].(string)
  9751. single_dose := dataBody["single_dose"].(float64)
  9752. single_dose_unit := dataBody["single_dose_unit"].(string)
  9753. patient_id := int64(dataBody["patient_id"].(float64))
  9754. day_count := int64(dataBody["day_count"].(float64))
  9755. groupNo := int64(dataBody["group_no"].(float64))
  9756. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9757. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  9758. if groupNo <= 0 {
  9759. group := service.GetMaxAdviceGroupID(org_id)
  9760. groupNo = group + 1
  9761. }
  9762. var template_id = ""
  9763. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  9764. template_id = "M" + adviceLastId
  9765. advice := models.DoctorAdvice{
  9766. UserOrgId: org_id,
  9767. PatientId: patient_id,
  9768. AdviceType: adviceType,
  9769. AdviceDate: AdviceDate,
  9770. StartTime: StartTime,
  9771. AdviceName: advice_name,
  9772. AdviceDesc: advice_desc,
  9773. ReminderDate: 0,
  9774. SingleDose: single_dose,
  9775. SingleDoseUnit: single_dose_unit,
  9776. DrugSpec: 0,
  9777. DrugSpecUnit: "",
  9778. PrescribingNumber: prescribing_number,
  9779. PrescribingNumberUnit: prescribing_number_unit,
  9780. DeliveryWay: delivery_way,
  9781. ExecutionFrequency: execution_frequency,
  9782. AdviceDoctor: advice_doctor,
  9783. Status: 1,
  9784. CreatedTime: time.Now().Unix(),
  9785. UpdatedTime: 0,
  9786. AdviceAffirm: "",
  9787. Remark: remark,
  9788. StopTime: 0,
  9789. StopReason: "",
  9790. StopDoctor: 0,
  9791. StopState: 0,
  9792. ParentId: 0,
  9793. ExecutionTime: 0,
  9794. ExecutionStaff: 0,
  9795. ExecutionState: 0,
  9796. Checker: 0,
  9797. RecordDate: RecordDate,
  9798. DialysisOrderId: 0,
  9799. CheckTime: 0,
  9800. CheckState: 0,
  9801. AdviceId: 0,
  9802. RemindType: 0,
  9803. FrequencyType: frequency_type,
  9804. DayCount: day_count,
  9805. WeekDay: frequency_week,
  9806. ChildDoctorAdvice: nil,
  9807. TemplateId: template_id,
  9808. Modifier: 0,
  9809. IsCheck: 0,
  9810. Way: 0,
  9811. DrugId: 0,
  9812. DrugNameId: 0,
  9813. IsMedicine: 0,
  9814. PushStartTime: 0,
  9815. IsSettle: 0,
  9816. IsPrescription: 0,
  9817. GroupNo: groupNo,
  9818. }
  9819. service.CreateMobileAdivce(advice)
  9820. c.ServeSuccessJSON(map[string]interface{}{
  9821. "msg": "保存成功!",
  9822. })
  9823. }
  9824. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  9825. patient_id, _ := c.GetInt64("patient_id")
  9826. org_id := c.GetMobileAdminUserInfo().Org.Id
  9827. app_id := c.GetMobileAdminUserInfo().App.Id
  9828. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  9829. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  9830. c.ServeSuccessJSON(map[string]interface{}{
  9831. "adviceList": adviceList,
  9832. "adminRoles": adminRoles,
  9833. })
  9834. }
  9835. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  9836. org_id := c.GetMobileAdminUserInfo().Org.Id
  9837. dataBody := make(map[string]interface{}, 0)
  9838. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9839. if err != nil {
  9840. utils.ErrorLog(err.Error())
  9841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9842. return
  9843. }
  9844. timeLayout := "2006-01-02"
  9845. loc, _ := time.LoadLocation("Local")
  9846. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9847. utils.ErrorLog("start_time")
  9848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9849. return
  9850. }
  9851. startTime2, _ := dataBody["start_time"].(string)
  9852. time_arr := strings.Split(startTime2, " ")
  9853. if len(time_arr) > 0 {
  9854. startTime2 = time_arr[0]
  9855. }
  9856. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  9857. utils.ErrorLog("advice_date")
  9858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9859. return
  9860. }
  9861. advice_date, _ := dataBody["advice_date"].(string)
  9862. var advicedateunix int64
  9863. if len(advice_date) > 0 {
  9864. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  9865. if err != nil {
  9866. fmt.Println(err)
  9867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9868. return
  9869. }
  9870. advicedateunix = theTime.Unix()
  9871. }
  9872. adviceDate := startTime2
  9873. if len(adviceDate) == 0 {
  9874. utils.ErrorLog("len(adviceDate) == 0")
  9875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9876. return
  9877. }
  9878. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  9879. if err != nil {
  9880. utils.ErrorLog(err.Error())
  9881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9882. return
  9883. }
  9884. AdviceDate := advicedateunix
  9885. RecordDate := advicedateunix
  9886. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9887. utils.ErrorLog("start_time")
  9888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9889. return
  9890. }
  9891. startTime, _ := dataBody["start_time"].(string)
  9892. if len(startTime) == 0 {
  9893. utils.ErrorLog("len(start_time) == 0")
  9894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9895. return
  9896. }
  9897. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  9898. if err != nil {
  9899. utils.ErrorLog(err.Error())
  9900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9901. return
  9902. }
  9903. StartTime := theTime.Unix()
  9904. advice_name, _ := dataBody["advice_name"].(string)
  9905. advice_desc, _ := dataBody["advice_desc"].(string)
  9906. delivery_way, _ := dataBody["delivery_way"].(string)
  9907. execution_frequency, _ := dataBody["execution_frequency"].(string)
  9908. prescribing_number := dataBody["prescribing_number"].(float64)
  9909. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  9910. remark := dataBody["remark"].(string)
  9911. single_dose := dataBody["single_dose"].(float64)
  9912. single_dose_unit := dataBody["single_dose_unit"].(string)
  9913. patient_id := int64(dataBody["patient_id"].(float64))
  9914. groupNo := int64(dataBody["group_no"].(float64))
  9915. parent_id := int64(dataBody["parent_id"].(float64))
  9916. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  9917. advice := models.XtDoctorAdviceOne{
  9918. UserOrgId: org_id,
  9919. PatientId: patient_id,
  9920. AdviceType: 1,
  9921. AdviceDate: AdviceDate,
  9922. StartTime: StartTime,
  9923. AdviceName: advice_name,
  9924. AdviceDesc: advice_desc,
  9925. ReminderDate: 0,
  9926. SingleDose: single_dose,
  9927. SingleDoseUnit: single_dose_unit,
  9928. PrescribingNumber: prescribing_number,
  9929. PrescribingNumberUnit: prescribing_number_unit,
  9930. DeliveryWay: delivery_way,
  9931. ExecutionFrequency: execution_frequency,
  9932. AdviceDoctor: advice_doctor,
  9933. Status: 1,
  9934. CreatedTime: time.Now().Unix(),
  9935. UpdatedTime: time.Now().Unix(),
  9936. AdviceAffirm: "",
  9937. Remark: remark,
  9938. StopTime: 0,
  9939. StopReason: "",
  9940. StopDoctor: 0,
  9941. StopState: 0,
  9942. ParentId: parent_id,
  9943. ExecutionTime: 0,
  9944. ExecutionStaff: 0,
  9945. ExecutionState: 0,
  9946. Checker: 0,
  9947. RecordDate: RecordDate,
  9948. DialysisOrderId: 0,
  9949. CheckTime: 0,
  9950. CheckState: 0,
  9951. DrugSpec: 0,
  9952. DrugSpecUnit: "",
  9953. Groupno: groupNo,
  9954. RemindType: 0,
  9955. FrequencyType: 0,
  9956. DayCount: 0,
  9957. WeekDay: "",
  9958. TemplateId: "",
  9959. Modifier: 0,
  9960. }
  9961. service.CreateMobileAdivceOne(advice)
  9962. c.ServeSuccessJSON(map[string]interface{}{
  9963. "msg": "保存成功!",
  9964. })
  9965. }
  9966. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  9967. id, _ := c.GetInt64("id")
  9968. service.DeleteSelfAdviceSubAdvice(id)
  9969. c.ServeSuccessJSON(map[string]interface{}{
  9970. "msg": "保存成功!",
  9971. })
  9972. }
  9973. func (c *DialysisAPIController) GetEditAdviceAction() {
  9974. id, _ := c.GetInt64("id")
  9975. org_id := c.GetMobileAdminUserInfo().Org.Id
  9976. advice, _ := service.GetEditAdviceActionList(id, org_id)
  9977. drugList, _ := service.GetAllDrugList(org_id)
  9978. c.ServeSuccessJSON(map[string]interface{}{
  9979. "advice": advice,
  9980. "drugList": drugList,
  9981. })
  9982. }
  9983. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  9984. dataBody := make(map[string]interface{}, 0)
  9985. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9986. if err != nil {
  9987. utils.ErrorLog(err.Error())
  9988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9989. return
  9990. }
  9991. timeLayout := "2006-01-02"
  9992. loc, _ := time.LoadLocation("Local")
  9993. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  9994. utils.ErrorLog("start_time")
  9995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9996. return
  9997. }
  9998. startTime2, _ := dataBody["start_time"].(string)
  9999. time_arr := strings.Split(startTime2, " ")
  10000. if len(time_arr) > 0 {
  10001. startTime2 = time_arr[0]
  10002. }
  10003. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10004. utils.ErrorLog("advice_date")
  10005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10006. return
  10007. }
  10008. advice_date, _ := dataBody["advice_date"].(string)
  10009. var advicedateunix int64
  10010. if len(advice_date) > 0 {
  10011. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10012. if err != nil {
  10013. fmt.Println(err)
  10014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10015. return
  10016. }
  10017. advicedateunix = theTime.Unix()
  10018. }
  10019. adviceDate := startTime2
  10020. if len(adviceDate) == 0 {
  10021. utils.ErrorLog("len(adviceDate) == 0")
  10022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10023. return
  10024. }
  10025. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10026. if err != nil {
  10027. utils.ErrorLog(err.Error())
  10028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10029. return
  10030. }
  10031. AdviceDate := advicedateunix
  10032. RecordDate := advicedateunix
  10033. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10034. utils.ErrorLog("start_time")
  10035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10036. return
  10037. }
  10038. startTime, _ := dataBody["start_time"].(string)
  10039. if len(startTime) == 0 {
  10040. utils.ErrorLog("len(start_time) == 0")
  10041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10042. return
  10043. }
  10044. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10045. if err != nil {
  10046. utils.ErrorLog(err.Error())
  10047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10048. return
  10049. }
  10050. StartTime := theTime.Unix()
  10051. advice_name, _ := dataBody["advice_name"].(string)
  10052. advice_desc, _ := dataBody["advice_desc"].(string)
  10053. delivery_way, _ := dataBody["delivery_way"].(string)
  10054. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10055. prescribing_number := dataBody["prescribing_number"].(float64)
  10056. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10057. remark := dataBody["remark"].(string)
  10058. single_dose := dataBody["single_dose"].(float64)
  10059. single_dose_unit := dataBody["single_dose_unit"].(string)
  10060. id := int64(dataBody["id"].(float64))
  10061. frequency_type := int64(dataBody["frequency_type"].(float64))
  10062. frequency_week, _ := dataBody["frequency_week"].(string)
  10063. day_count := int64(dataBody["day_count"].(float64))
  10064. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10065. advice := models.XtDoctorAdviceOne{
  10066. AdviceDate: AdviceDate,
  10067. StartTime: StartTime,
  10068. AdviceName: advice_name,
  10069. AdviceDesc: advice_desc,
  10070. SingleDose: single_dose,
  10071. SingleDoseUnit: single_dose_unit,
  10072. PrescribingNumber: prescribing_number,
  10073. PrescribingNumberUnit: prescribing_number_unit,
  10074. DeliveryWay: delivery_way,
  10075. ExecutionFrequency: execution_frequency,
  10076. AdviceDoctor: advice_doctor,
  10077. Remark: remark,
  10078. RecordDate: RecordDate,
  10079. FrequencyType: frequency_type,
  10080. DayCount: day_count,
  10081. WeekDay: frequency_week,
  10082. }
  10083. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10084. c.ServeSuccessJSON(map[string]interface{}{
  10085. "advice": advice,
  10086. })
  10087. }
  10088. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10089. dataBody := make(map[string]interface{}, 0)
  10090. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10091. if err != nil {
  10092. utils.ErrorLog(err.Error())
  10093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10094. return
  10095. }
  10096. timeLayout := "2006-01-02"
  10097. loc, _ := time.LoadLocation("Local")
  10098. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10099. utils.ErrorLog("start_time")
  10100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10101. return
  10102. }
  10103. startTime2, _ := dataBody["start_time"].(string)
  10104. time_arr := strings.Split(startTime2, " ")
  10105. if len(time_arr) > 0 {
  10106. startTime2 = time_arr[0]
  10107. }
  10108. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10109. utils.ErrorLog("advice_date")
  10110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10111. return
  10112. }
  10113. advice_date, _ := dataBody["advice_date"].(string)
  10114. var advicedateunix int64
  10115. if len(advice_date) > 0 {
  10116. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10117. if err != nil {
  10118. fmt.Println(err)
  10119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10120. return
  10121. }
  10122. advicedateunix = theTime.Unix()
  10123. }
  10124. adviceDate := startTime2
  10125. if len(adviceDate) == 0 {
  10126. utils.ErrorLog("len(adviceDate) == 0")
  10127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10128. return
  10129. }
  10130. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10131. if err != nil {
  10132. utils.ErrorLog(err.Error())
  10133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10134. return
  10135. }
  10136. AdviceDate := advicedateunix
  10137. RecordDate := advicedateunix
  10138. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10139. utils.ErrorLog("start_time")
  10140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10141. return
  10142. }
  10143. startTime, _ := dataBody["start_time"].(string)
  10144. if len(startTime) == 0 {
  10145. utils.ErrorLog("len(start_time) == 0")
  10146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10147. return
  10148. }
  10149. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10150. if err != nil {
  10151. utils.ErrorLog(err.Error())
  10152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10153. return
  10154. }
  10155. StartTime := theTime.Unix()
  10156. advice_name, _ := dataBody["advice_name"].(string)
  10157. advice_desc, _ := dataBody["advice_desc"].(string)
  10158. delivery_way, _ := dataBody["delivery_way"].(string)
  10159. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10160. prescribing_number := dataBody["prescribing_number"].(float64)
  10161. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10162. remark := dataBody["remark"].(string)
  10163. single_dose := dataBody["single_dose"].(float64)
  10164. single_dose_unit := dataBody["single_dose_unit"].(string)
  10165. id := int64(dataBody["id"].(float64))
  10166. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10167. advice := models.XtDoctorAdviceOne{
  10168. AdviceDate: AdviceDate,
  10169. StartTime: StartTime,
  10170. AdviceName: advice_name,
  10171. AdviceDesc: advice_desc,
  10172. SingleDose: single_dose,
  10173. SingleDoseUnit: single_dose_unit,
  10174. PrescribingNumber: prescribing_number,
  10175. PrescribingNumberUnit: prescribing_number_unit,
  10176. DeliveryWay: delivery_way,
  10177. ExecutionFrequency: execution_frequency,
  10178. AdviceDoctor: advice_doctor,
  10179. Remark: remark,
  10180. RecordDate: RecordDate,
  10181. }
  10182. service.UpdateMobileDoctorAdviceById(id, advice)
  10183. c.ServeSuccessJSON(map[string]interface{}{
  10184. "advice": advice,
  10185. })
  10186. }
  10187. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10188. dataBody := make(map[string]interface{}, 0)
  10189. timeLayout := "2006-01-02"
  10190. loc, _ := time.LoadLocation("Local")
  10191. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10192. if err != nil {
  10193. utils.ErrorLog(err.Error())
  10194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10195. return
  10196. }
  10197. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10198. utils.ErrorLog("start_time")
  10199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10200. return
  10201. }
  10202. startTime2, _ := dataBody["start_time"].(string)
  10203. time_arr := strings.Split(startTime2, " ")
  10204. if len(time_arr) > 0 {
  10205. startTime2 = time_arr[0]
  10206. }
  10207. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10208. utils.ErrorLog("advice_date")
  10209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10210. return
  10211. }
  10212. advice_date, _ := dataBody["advice_date"].(string)
  10213. var advicedateunix int64
  10214. if len(advice_date) > 0 {
  10215. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10216. if err != nil {
  10217. fmt.Println(err)
  10218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10219. return
  10220. }
  10221. advicedateunix = theTime.Unix()
  10222. }
  10223. adviceDate := startTime2
  10224. if len(adviceDate) == 0 {
  10225. utils.ErrorLog("len(adviceDate) == 0")
  10226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10227. return
  10228. }
  10229. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10230. if err != nil {
  10231. utils.ErrorLog(err.Error())
  10232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10233. return
  10234. }
  10235. RecordDate := advicedateunix
  10236. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10237. utils.ErrorLog("start_time")
  10238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10239. return
  10240. }
  10241. startTime, _ := dataBody["start_time"].(string)
  10242. if len(startTime) == 0 {
  10243. utils.ErrorLog("len(start_time) == 0")
  10244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10245. return
  10246. }
  10247. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10248. if err != nil {
  10249. utils.ErrorLog(err.Error())
  10250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10251. return
  10252. }
  10253. StartTime := theTime.Unix()
  10254. patient_id := int64(dataBody["patient_id"].(float64))
  10255. group_no := int64(dataBody["group_no"].(float64))
  10256. org_id := c.GetMobileAdminUserInfo().Org.Id
  10257. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10258. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10259. utils.ErrorLog("advices")
  10260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10261. return
  10262. }
  10263. adviceNames := dataBody["advices"].([]interface{})
  10264. var advices []*models.GroupAdvice
  10265. for _, adviceNameMap := range adviceNames {
  10266. var advice models.GroupAdvice
  10267. adviceNameM := adviceNameMap.(map[string]interface{})
  10268. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10269. utils.ErrorLog("advice_name")
  10270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10271. return
  10272. }
  10273. adviceName, _ := adviceNameM["advice_name"].(string)
  10274. if len(adviceName) == 0 {
  10275. utils.ErrorLog("len(advice_name) == 0")
  10276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10277. return
  10278. }
  10279. advice.AdviceName = adviceName
  10280. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10281. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10282. advice.DrugSpec = drugSpec
  10283. }
  10284. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10285. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10286. advice.AdviceDesc = adviceDesc
  10287. }
  10288. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10289. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10290. advice.DrugSpecUnit = drugSpecUnit
  10291. }
  10292. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10293. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10294. advice.SingleDose = singleDose
  10295. }
  10296. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10297. singleDose := adviceNameM["single_dose"].(float64)
  10298. advice.SingleDose = singleDose
  10299. }
  10300. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10301. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10302. advice.SingleDoseUnit = singleDoseUnit
  10303. }
  10304. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10305. tmp := adviceNameM["single_dose_unit"].(float64)
  10306. singleDoseUnit := service.TypeConversion(tmp)
  10307. advice.SingleDoseUnit = singleDoseUnit
  10308. }
  10309. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10310. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10311. advice.PrescribingNumber = prescribingNumber
  10312. }
  10313. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10314. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10315. advice.PrescribingNumber = prescribingNumber
  10316. }
  10317. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10318. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10319. advice.PrescribingNumberUnit = prescribingNumberUnit
  10320. }
  10321. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10322. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10323. advice.DeliveryWay = deliveryWay
  10324. }
  10325. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10326. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10327. advice.ExecutionFrequency = executionFrequency
  10328. }
  10329. remark, _ := adviceNameM["remark"].(string)
  10330. advice.Remark = remark
  10331. advice.AdviceType = 1
  10332. advice.StartTime = StartTime
  10333. advice.RecordDate = RecordDate
  10334. advice.PatientId = patient_id
  10335. advice.UserOrgId = org_id
  10336. advice.AdviceDoctor = advice_doctor
  10337. advices = append(advices, &advice)
  10338. }
  10339. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10340. c.ServeSuccessJSON(map[string]interface{}{
  10341. "advice": newAdvices,
  10342. })
  10343. }