patient_api_controller.go 254KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math"
  6. "strings"
  7. "XT_New/enums"
  8. "XT_New/models"
  9. "XT_New/service"
  10. "XT_New/utils"
  11. // "fmt"
  12. "reflect"
  13. "strconv"
  14. "time"
  15. )
  16. type PatientApiController struct {
  17. MobileBaseAPIAuthController
  18. }
  19. func (c *PatientApiController) GetPatientInfoWithDiseases() {
  20. id, _ := c.GetInt64("patient", 0)
  21. if id <= 0 {
  22. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  23. return
  24. }
  25. adminUserInfo := c.GetMobileAdminUserInfo()
  26. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  27. if patient.ID == 0 {
  28. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  29. return
  30. }
  31. Registrars, err := service.GetAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, patient.RegistrarsId)
  32. if err != nil {
  33. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  34. return
  35. }
  36. if Registrars != nil {
  37. patient.Registrars = Registrars.Name
  38. }
  39. c.ServeSuccessJSON(map[string]interface{}{
  40. "patient": patient,
  41. })
  42. return
  43. }
  44. func (c *PatientApiController) CreateDialysisSolution() {
  45. id, _ := c.GetInt64("patient", 0)
  46. if id <= 0 {
  47. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  48. return
  49. }
  50. adminUserInfo := c.GetMobileAdminUserInfo()
  51. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  52. if patient.ID == 0 {
  53. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  54. return
  55. }
  56. //根据路由来做权限
  57. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  58. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  59. //if template.TemplateId == 2 || template.TemplateId == 6 {
  60. // if appRole.UserType == 3 {
  61. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  62. // if getPermissionErr != nil {
  63. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  64. // return
  65. // } else if headNursePermission == nil {
  66. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  67. // return
  68. // }
  69. // }
  70. //}
  71. var solution models.DialysisSolution
  72. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  73. if code > 0 {
  74. c.ServeFailJSONWithSGJErrorCode(code)
  75. return
  76. }
  77. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  78. solution.Doctor = adminUserInfo.AdminUser.Id
  79. solution.Status = 1
  80. solution.PatientId = id
  81. solution.CreatedTime = time.Now().Unix()
  82. solution.UserOrgId = adminUserInfo.Org.Id
  83. solution.UpdatedTime = time.Now().Unix()
  84. solution.SubName = ""
  85. solution.ParentId = 0
  86. err := service.CreatePatientDialysisSolution(&solution)
  87. if err != nil {
  88. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  89. return
  90. }
  91. c.ServeSuccessJSON(map[string]interface{}{
  92. "msg": "ok",
  93. "solution": solution,
  94. })
  95. return
  96. }
  97. func (c *PatientApiController) EditDialysisSolution() {
  98. id, _ := c.GetInt64("id", 0)
  99. if id <= 0 {
  100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  101. return
  102. }
  103. adminUserInfo := c.GetMobileAdminUserInfo()
  104. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.Org.Id, id)
  105. if solution.ID == 0 {
  106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  107. return
  108. }
  109. //if solution.Doctor != adminUserInfo.AdminUser.Id {
  110. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  111. // if getPermissionErr != nil {
  112. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  113. // return
  114. // } else if headNursePermission == nil {
  115. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  116. // return
  117. // }
  118. //}
  119. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "update")
  120. if code > 0 {
  121. c.ServeFailJSONWithSGJErrorCode(code)
  122. return
  123. }
  124. // solution.RegistrarsId = adminUserInfo.AdminUser.Id
  125. solution.Doctor = adminUserInfo.AdminUser.Id
  126. solution.Status = 1
  127. // solution.PatientId = id
  128. // solution.CreatedTime = time.Now().Unix()
  129. // solution.UserOrgId = adminUserInfo.Org.Id
  130. solution.UpdatedTime = time.Now().Unix()
  131. // solution.SubName = ""
  132. // solution.ParentId = 0
  133. err := service.UpdatePatientDialysisSolution(&solution)
  134. if err != nil {
  135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  136. return
  137. }
  138. c.ServeSuccessJSON(map[string]interface{}{
  139. "msg": "ok",
  140. "solution": solution,
  141. })
  142. return
  143. }
  144. func (c *PatientApiController) CreateDoctorAdvice() {
  145. patient, _ := c.GetInt64("id", 0)
  146. if patient <= 0 {
  147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  148. return
  149. }
  150. adminUserInfo := c.GetMobileAdminUserInfo()
  151. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  152. if patientInfo.ID == 0 {
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  154. return
  155. }
  156. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  157. //if appRole.UserType == 3{
  158. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  159. // return
  160. //}
  161. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  162. //
  163. //if appRole.UserType == 3 {
  164. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  165. // if getPermissionErr != nil {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  167. // return
  168. // } else if headNursePermission == nil {
  169. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  170. // return
  171. // }
  172. //}
  173. var advice models.DoctorAdvice
  174. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  175. if code > 0 {
  176. c.ServeFailJSONWithSGJErrorCode(code)
  177. return
  178. }
  179. if advice.ParentId > 0 {
  180. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  181. if old.ID == 0 || old.PatientId != patient {
  182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  183. return
  184. }
  185. if old.StopState == 1 || old.ExecutionState == 1 {
  186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  187. return
  188. }
  189. if old.ParentId > 0 {
  190. advice.ParentId = old.ParentId
  191. }
  192. advice.StartTime = old.StartTime
  193. advice.AdviceDoctor = old.AdviceDoctor
  194. advice.DeliveryWay = old.DeliveryWay
  195. advice.ExecutionFrequency = old.ExecutionFrequency
  196. advice.GroupNo = old.GroupNo
  197. }
  198. advice.Status = 1
  199. advice.CreatedTime = time.Now().Unix()
  200. advice.UpdatedTime = time.Now().Unix()
  201. advice.StopState = 2
  202. advice.ExecutionState = 2
  203. advice.UserOrgId = adminUserInfo.Org.Id
  204. advice.PatientId = patient
  205. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  206. err := service.CreateDoctorAdvice(&advice)
  207. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  208. redis := service.RedisClient()
  209. defer redis.Close()
  210. redis.Set(key, "", time.Second)
  211. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  212. redis.Set(keyOne, "", time.Second)
  213. if err != nil {
  214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  215. return
  216. }
  217. c.ServeSuccessJSON(map[string]interface{}{
  218. "msg": "ok",
  219. "advice": advice,
  220. })
  221. return
  222. }
  223. func (c *PatientApiController) EditDoctorAdvice() {
  224. id, _ := c.GetInt64("id", 0)
  225. patient_id, _ := c.GetInt64("patient_id")
  226. doc_advice_date, _ := c.GetInt64("advice_date")
  227. if id <= 0 {
  228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  229. return
  230. }
  231. redis := service.RedisClient()
  232. adminUserInfo := c.GetMobileAdminUserInfo()
  233. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  234. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  235. //
  236. //if appRole.UserType == 3 {
  237. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  238. // if getPermissionErr != nil {
  239. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  240. // return
  241. // } else if headNursePermission == nil {
  242. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  243. // return
  244. // }
  245. //}
  246. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  247. if advice.ID == 0 {
  248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  249. return
  250. }
  251. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  252. if code > 0 {
  253. c.ServeFailJSONWithSGJErrorCode(code)
  254. return
  255. }
  256. advice.Status = 1
  257. advice.UpdatedTime = time.Now().Unix()
  258. advice.UserOrgId = adminUserInfo.Org.Id
  259. advice.Modifier = adminUserInfo.AdminUser.Id
  260. if adminUserInfo.Org.Id == 10580 {
  261. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  262. }
  263. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  264. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  265. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  266. var err error
  267. var isChangeGroup bool
  268. if advice.ParentId == 0 {
  269. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  270. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  271. if len(adviceSlice) == 1 {
  272. // 查询信息规挡的设置天数
  273. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  274. if infor.ID > 0 && infor.WeekDay > 0 {
  275. var cha_time int64
  276. timeNowStr := time.Now().Format("2006-01-02")
  277. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  278. //今日的日期减去设置的日期
  279. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  280. if cha_time >= sourceAdvice.AdviceDate {
  281. //查询审核是否允许
  282. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id, 4)
  283. //申请状态不允许的情况 拒绝修改
  284. if infor.ApplicationStatus != 1 {
  285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  286. return
  287. }
  288. }
  289. }
  290. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  291. if advice.StartTime == sourceAdvice.StartTime {
  292. err = service.UpdateDoctorAdvice(&advice)
  293. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  294. defer redis.Close()
  295. redis.Set(key, "", time.Second)
  296. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
  297. redis.Set(keyOne, "", time.Second)
  298. isChangeGroup = false
  299. } else {
  300. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  301. isChangeGroup = false
  302. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  303. defer redis.Close()
  304. redis.Set(key, "", time.Second)
  305. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  306. redis.Set(keyOne, "", time.Second)
  307. }
  308. } else if len(adviceSlice) > 1 {
  309. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  310. if infor.ID > 0 {
  311. var cha_time int64
  312. timeNowStr := time.Now().Format("2006-01-02")
  313. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  314. //今日的日期减去设置的日期
  315. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  316. if cha_time >= sourceAdvice.AdviceDate {
  317. //查询审核是否允许
  318. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id, 4)
  319. //申请状态不允许的情况 拒绝修改
  320. if infor.ApplicationStatus != 1 {
  321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  322. return
  323. }
  324. }
  325. }
  326. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  327. if advice.StartTime == sourceAdvice.StartTime {
  328. err = service.UpdateDoctorAdvice(&advice)
  329. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  330. defer redis.Close()
  331. redis.Set(key, "", time.Second)
  332. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  333. redis.Set(keyOne, "", time.Second)
  334. isChangeGroup = false
  335. } else {
  336. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  337. gruopNo = gruopNo + 1
  338. advice.GroupNo = gruopNo
  339. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  340. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  341. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  342. defer redis.Close()
  343. redis.Set(key, "", time.Second)
  344. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  345. redis.Set(keyOne, "", time.Second)
  346. isChangeGroup = true
  347. }
  348. }
  349. } else {
  350. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  351. if infor.ID > 0 {
  352. var cha_time int64
  353. timeNowStr := time.Now().Format("2006-01-02")
  354. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  355. //今日的日期减去设置的日期
  356. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  357. if cha_time >= advice.AdviceDate {
  358. //查询审核是否允许
  359. infor, _ := service.GetDialysisInformationByRecordDate(id, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  360. //申请状态不允许的情况 拒绝修改
  361. if infor.ApplicationStatus != 1 {
  362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  363. return
  364. }
  365. }
  366. }
  367. isChangeGroup = false
  368. err = service.UpdateDoctorAdvice(&advice)
  369. redis := service.RedisClient()
  370. defer redis.Close()
  371. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  372. redis.Set(key, "", time.Second)
  373. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  374. redis.Set(keyOne, "", time.Second)
  375. }
  376. if err != nil {
  377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  378. return
  379. }
  380. if !isChangeGroup {
  381. c.ServeSuccessJSON(map[string]interface{}{
  382. "msg": "ok",
  383. "advice": advice,
  384. "isChange": isChangeGroup, //方便前端处理数据
  385. })
  386. } else {
  387. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  388. if err != nil {
  389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  390. return
  391. }
  392. c.ServeSuccessJSON(map[string]interface{}{
  393. "msg": "ok",
  394. "advice": newGroupAdvice,
  395. "isChange": isChangeGroup, //方便前端处理数据
  396. })
  397. }
  398. return
  399. }
  400. func (c *PatientApiController) StopDoctorAdvice() {
  401. id, _ := c.GetInt64("id", 0)
  402. if id <= 0 {
  403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  404. return
  405. }
  406. adminUserInfo := c.GetMobileAdminUserInfo()
  407. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  408. if advice.ID == 0 {
  409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  410. return
  411. }
  412. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  413. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  414. // return
  415. //}
  416. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  417. //
  418. //if appRole.UserType == 3 {
  419. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  420. // if getPermissionErr != nil {
  421. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  422. // return
  423. // } else if headNursePermission == nil {
  424. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  425. // return
  426. // }
  427. //}
  428. if advice.StopState == 1 {
  429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  430. return
  431. }
  432. dataBody := make(map[string]interface{}, 0)
  433. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  434. if err != nil {
  435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  436. return
  437. }
  438. timeLayout := "2006-01-02"
  439. loc, _ := time.LoadLocation("Local")
  440. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  441. utils.ErrorLog("stop_time")
  442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  443. return
  444. }
  445. stopTime, _ := dataBody["stop_time"].(string)
  446. if len(stopTime) == 0 {
  447. utils.ErrorLog("len(stop_time) == 0")
  448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  449. return
  450. }
  451. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  452. if err != nil {
  453. utils.ErrorLog(err.Error())
  454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  455. return
  456. }
  457. advice.StopTime = theTime.Unix()
  458. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  459. utils.ErrorLog("stop_reason")
  460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  461. return
  462. }
  463. stopReason, _ := dataBody["stop_reason"].(string)
  464. if len(stopReason) == 0 {
  465. utils.ErrorLog("len(stop_reason) == 0")
  466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  467. return
  468. }
  469. advice.StopReason = stopReason
  470. advice.Status = 1
  471. advice.UpdatedTime = time.Now().Unix()
  472. advice.StopDoctor = adminUserInfo.AdminUser.Id
  473. advice.StopState = 1
  474. advice.StopTime = time.Now().Unix()
  475. advice.Modifier = adminUserInfo.AdminUser.Id
  476. err = service.StopDoctorAdvice(&advice)
  477. if err != nil {
  478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  479. return
  480. }
  481. c.ServeSuccessJSON(map[string]interface{}{
  482. "msg": "ok",
  483. "advice": advice,
  484. })
  485. return
  486. }
  487. func (c *PatientApiController) DeleteDoctorAdvice() {
  488. id, _ := c.GetInt64("id", 0)
  489. if id <= 0 {
  490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  491. return
  492. }
  493. adminUserInfo := c.GetMobileAdminUserInfo()
  494. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  495. if advice.ID == 0 {
  496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  497. return
  498. }
  499. //自备药
  500. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  501. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  502. //查询库存是否是自备药
  503. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  504. if selfBasedrug.IsSelfDrug == 1 {
  505. creater := adminUserInfo.AdminUser.Id
  506. //退库
  507. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  508. }
  509. }
  510. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  511. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  512. // return
  513. //}
  514. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  515. //
  516. //if appRole.UserType == 3 {
  517. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  518. // if getPermissionErr != nil {
  519. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  520. // return
  521. // } else if headNursePermission == nil {
  522. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  523. // return
  524. // }
  525. //}
  526. advice.UpdatedTime = time.Now().Unix()
  527. advice.Status = 0
  528. advice.Modifier = adminUserInfo.AdminUser.Id
  529. err := service.DeleteDoctorAdvice(&advice)
  530. if err != nil {
  531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  532. return
  533. }
  534. c.ServeSuccessJSON(map[string]interface{}{
  535. "msg": "ok",
  536. })
  537. return
  538. }
  539. func (c *PatientApiController) ExecDoctorAdvice() {
  540. execution_time := c.GetString("execution_time")
  541. origin, _ := c.GetInt64("origin", 0)
  542. groupno, _ := c.GetInt64("groupno", -1)
  543. record_date, _ := c.GetInt64("record_date")
  544. patient_id, _ := c.GetInt64("patient_id")
  545. if origin != 2 {
  546. adminUserInfo := c.GetMobileAdminUserInfo()
  547. execution_staff := adminUserInfo.AdminUser.Id
  548. var ids []string
  549. advice_ids := c.GetString("advice_id")
  550. if groupno == 0 {
  551. ids = strings.Split(advice_ids, ",")
  552. }
  553. if groupno < 0 {
  554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  555. return
  556. }
  557. if len(execution_time) <= 0 {
  558. utils.ErrorLog("execution_time")
  559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  560. return
  561. }
  562. timeLayout2 := "2006-01-02 15:04:05"
  563. loc, _ := time.LoadLocation("Local")
  564. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  565. if errs != nil {
  566. utils.ErrorLog(errs.Error())
  567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  568. return
  569. }
  570. var advice models.DoctorAdvice
  571. if groupno > 0 {
  572. advices, _ := service.FindAllDoctorAdviceByGoroupNoThree(adminUserInfo.Org.Id, groupno, patient_id, record_date)
  573. fmt.Println("advices---------------------------------------------", advices)
  574. for _, item := range advices {
  575. //自备药
  576. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  577. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  578. //查询库存是否
  579. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  580. if selfBasedrug.IsSelfDrug == 1 {
  581. selfDrugStockCount, _ := service.GetSelfDrugStockCountByPatientId(advice.DrugId, advice.PatientId, advice.UserOrgId)
  582. var prescribing_number_total_one int64
  583. //判断单位是否相等
  584. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  585. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  586. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  587. //转化为最小单位
  588. prescribing_number_total_one = count * selfBasedrug.MinNumber
  589. }
  590. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  591. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  592. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  593. prescribing_number_total_one = count
  594. }
  595. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  596. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  597. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  598. prescribing_number_total_one = count
  599. }
  600. if prescribing_number_total_one > selfDrugStockCount.FlushCount {
  601. c.ServeSuccessJSON(map[string]interface{}{
  602. "msg": "2",
  603. "advice": advice,
  604. "ids": ids,
  605. })
  606. return
  607. }
  608. }
  609. }
  610. //恒泰中医院
  611. if item.UserOrgId == 10490 || item.UserOrgId == 10602 || item.UserOrgId == 10697 {
  612. if item.DrugId == 0 || item.DrugNameId == 0 {
  613. //从字典里面查找
  614. drug, _ := service.GetBaseDrugByName(item.AdviceName, item.UserOrgId)
  615. service.UpdateDoctorAdviceByGoroupNo(item.ID, drug.ID)
  616. }
  617. }
  618. if item.ExecutionState == 2 {
  619. advice = item
  620. }
  621. //记录日志
  622. byterequest, _ := json.Marshal(item)
  623. adviceLog := models.XtDoctorAdviceLog{
  624. UserOrgId: item.UserOrgId,
  625. PatientId: item.PatientId,
  626. AdminUserId: adminUserInfo.AdminUser.Id,
  627. Module: 2,
  628. ErrLog: string(byterequest),
  629. Status: 1,
  630. Ctime: time.Now().Unix(),
  631. Mtime: 0,
  632. Source: "手机端执行医嘱",
  633. RecordDate: item.AdviceDate,
  634. }
  635. service.CreateDoctorAdviceLog(adviceLog)
  636. }
  637. advicesOne, _ := service.FindAllDoctorAdviceByGoroupNoOne(adminUserInfo.Org.Id, groupno)
  638. for _, item := range advicesOne {
  639. //自备药
  640. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  641. if selfPrescriptionOutOpen.IsOpen == 1 {
  642. db := service.XTWriteDB()
  643. tx := db.Begin()
  644. defer func() {
  645. if r := recover(); r != nil {
  646. tx.Rollback()
  647. } else {
  648. tx.Commit()
  649. }
  650. }()
  651. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  652. if selfBasedrug.IsSelfDrug == 1 {
  653. //查询是否有库存
  654. infoList, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(item.DrugId, item.PatientId, item.UserOrgId, tx)
  655. var total_count int64
  656. var prescribing_number_total int64
  657. for _, items := range infoList {
  658. if items.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  659. items.StockMaxNumber = items.StockMaxNumber * selfBasedrug.MinNumber
  660. }
  661. total_count += items.StockMaxNumber + items.StockMinNumber
  662. }
  663. if total_count == 0 {
  664. c.ServeSuccessJSON(map[string]interface{}{
  665. "msg": "2",
  666. "advice": item,
  667. "ids": ids,
  668. })
  669. return
  670. }
  671. //判断单位是否相等
  672. if selfBasedrug.MaxUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  673. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  674. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  675. //转化为最小单位
  676. prescribing_number_total = count * selfBasedrug.MinNumber
  677. }
  678. if selfBasedrug.MinUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  679. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  680. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  681. prescribing_number_total = count
  682. }
  683. if selfBasedrug.MinUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  684. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  685. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  686. prescribing_number_total = count
  687. }
  688. if prescribing_number_total > total_count {
  689. c.ServeSuccessJSON(map[string]interface{}{
  690. "msg": "3",
  691. "advice": item,
  692. })
  693. return
  694. }
  695. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  696. //出库
  697. if prescribing_number_total <= total_count {
  698. timeStr := time.Now().Format("2006-01-02")
  699. timeArr := strings.Split(timeStr, "-")
  700. total, _ := service.FindAllSelfDrugWarehouseOut(adminUserInfo.Org.Id, tx)
  701. total = total + 1
  702. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  703. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  704. number = number + total
  705. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  706. operation_time := time.Now().Unix()
  707. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  708. //创建一个出库单
  709. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  710. WarehouseOutOrderNumber: warehousing_out_order,
  711. OperationTime: operation_time,
  712. OrgId: adminUserInfo.Org.Id,
  713. Creater: creater,
  714. Ctime: time.Now().Unix(),
  715. Status: 1,
  716. WarehouseOutTime: item.AdviceDate,
  717. Type: 0,
  718. PatientId: advice.PatientId,
  719. IsCheck: 1,
  720. IsSys: 1,
  721. }
  722. //查询今日是否有出库数据
  723. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(adminUserInfo.Org.Id, item.AdviceDate, tx, 1)
  724. if lastWarehouseOut.ID == 0 {
  725. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  726. }
  727. //查询今日是否有出库数据
  728. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(adminUserInfo.Org.Id, item.AdviceDate, tx, 1)
  729. var warehousing_out_order_str string
  730. if lastWarehouseOut.ID == 0 {
  731. warehousing_out_order_str = warehousing_out_order
  732. } else {
  733. warehousing_out_order_str = lastWarehouseOut.WarehouseOutOrderNumber
  734. }
  735. //出库
  736. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  737. WarehouseOutId: lastWarehouseOutOne.ID,
  738. WarehouseOutOrderNumber: warehousing_out_order_str,
  739. DrugId: item.DrugId,
  740. Count: prescribing_number_total,
  741. Price: 0,
  742. TotalPrice: 0,
  743. Status: 1,
  744. Ctime: item.AdviceDate,
  745. Mtime: item.AdviceDate,
  746. Remark: "",
  747. OrgId: item.UserOrgId,
  748. Type: 0,
  749. Manufacturer: selfBasedrug.Manufacturer,
  750. Dealer: selfBasedrug.Dealer,
  751. RetailPrice: 0,
  752. RetailTotalPrice: 0,
  753. CountUnit: selfBasedrug.MinUnit,
  754. ExpiryDate: 0,
  755. ProductDate: 0,
  756. Number: "",
  757. BatchNumber: "",
  758. IsSys: 0,
  759. WarehouseInfoId: 0,
  760. AdminUserId: 0,
  761. StockCount: "",
  762. IsCheck: 1,
  763. SysRecordTime: item.AdviceDate,
  764. PatientId: item.PatientId,
  765. AdviceId: item.ID,
  766. ClassType: "",
  767. }
  768. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  769. for _, it := range warehousingOutInfo {
  770. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  771. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  772. //出库逻辑
  773. service.AutoSelfDrugDeliverInfoFourtyTwo(adminUserInfo.Org.Id, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  774. //查询剩余库存
  775. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  776. var sum_count int64
  777. for _, its := range stockInfo {
  778. if its.MaxUnit == medical.MaxUnit {
  779. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  780. }
  781. sum_count += its.StockMaxNumber + its.StockMinNumber
  782. }
  783. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  784. }
  785. }
  786. }
  787. }
  788. }
  789. } else {
  790. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  791. for _, item := range advices {
  792. //自备药
  793. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  794. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  795. //查询库存是否
  796. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  797. if selfBasedrug.IsSelfDrug == 1 {
  798. selfDrugStockCount, _ := service.GetSelfDrugStockCountByPatientId(advice.DrugId, advice.PatientId, advice.UserOrgId)
  799. var prescribing_number_total_one int64
  800. //判断单位是否相等
  801. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  802. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  803. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  804. //转化为最小单位
  805. prescribing_number_total_one = count * selfBasedrug.MinNumber
  806. }
  807. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  808. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  809. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  810. prescribing_number_total_one = count
  811. }
  812. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  813. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  814. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  815. prescribing_number_total_one = count
  816. }
  817. if prescribing_number_total_one > selfDrugStockCount.FlushCount {
  818. c.ServeSuccessJSON(map[string]interface{}{
  819. "msg": "2",
  820. "advice": advice,
  821. "ids": ids,
  822. })
  823. return
  824. }
  825. }
  826. }
  827. //恒泰中医院
  828. if item.UserOrgId == 10490 || item.UserOrgId == 10602 {
  829. if item.DrugId == 0 || item.DrugNameId == 0 {
  830. //从字典里面查找
  831. drug, _ := service.GetBaseDrugByName(item.AdviceName, item.UserOrgId)
  832. service.UpdateDoctorAdviceByGoroupNo(item.ID, drug.ID)
  833. }
  834. }
  835. if item.ExecutionState == 2 {
  836. advice = item
  837. }
  838. }
  839. advicesOne, _ := service.FindDoctorAdviceByIdsOne(adminUserInfo.Org.Id, ids)
  840. for _, item := range advicesOne {
  841. //自备药
  842. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  843. if selfPrescriptionOutOpen.IsOpen == 1 {
  844. db := service.XTWriteDB()
  845. tx := db.Begin()
  846. defer func() {
  847. if r := recover(); r != nil {
  848. tx.Rollback()
  849. } else {
  850. tx.Commit()
  851. }
  852. }()
  853. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  854. if selfBasedrug.IsSelfDrug == 1 {
  855. //查询是否有库存
  856. infoList, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(item.DrugId, item.PatientId, item.UserOrgId, tx)
  857. var total_count int64
  858. var prescribing_number_total int64
  859. for _, items := range infoList {
  860. if items.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  861. items.StockMaxNumber = items.StockMaxNumber * selfBasedrug.MinNumber
  862. }
  863. total_count += items.StockMaxNumber + items.StockMinNumber
  864. }
  865. if total_count == 0 {
  866. c.ServeSuccessJSON(map[string]interface{}{
  867. "msg": "2",
  868. "advice": item,
  869. "ids": ids,
  870. })
  871. return
  872. }
  873. //判断单位是否相等
  874. if selfBasedrug.MaxUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  875. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  876. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  877. //转化为最小单位
  878. prescribing_number_total = count * selfBasedrug.MinNumber
  879. }
  880. if selfBasedrug.MinUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  881. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  882. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  883. prescribing_number_total = count
  884. }
  885. if selfBasedrug.MinUnit == item.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  886. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  887. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  888. prescribing_number_total = count
  889. }
  890. if prescribing_number_total > total_count {
  891. c.ServeSuccessJSON(map[string]interface{}{
  892. "msg": "3",
  893. "advice": item,
  894. })
  895. return
  896. }
  897. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  898. //出库
  899. if prescribing_number_total <= total_count {
  900. timeStr := time.Now().Format("2006-01-02")
  901. timeArr := strings.Split(timeStr, "-")
  902. total, _ := service.FindAllSelfDrugWarehouseOut(adminUserInfo.Org.Id, tx)
  903. total = total + 1
  904. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  905. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  906. number = number + total
  907. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  908. operation_time := time.Now().Unix()
  909. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  910. //创建一个出库单
  911. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  912. WarehouseOutOrderNumber: warehousing_out_order,
  913. OperationTime: operation_time,
  914. OrgId: adminUserInfo.Org.Id,
  915. Creater: creater,
  916. Ctime: time.Now().Unix(),
  917. Status: 1,
  918. WarehouseOutTime: item.AdviceDate,
  919. Type: 0,
  920. PatientId: advice.PatientId,
  921. IsCheck: 1,
  922. IsSys: 1,
  923. }
  924. //查询今日是否有出库数据
  925. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(adminUserInfo.Org.Id, item.AdviceDate, tx, 1)
  926. if lastWarehouseOut.ID == 0 {
  927. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  928. }
  929. //查询今日是否有出库数据
  930. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(adminUserInfo.Org.Id, item.AdviceDate, tx, 1)
  931. var warehousing_out_order_str string
  932. if lastWarehouseOut.ID == 0 {
  933. warehousing_out_order_str = warehousing_out_order
  934. } else {
  935. warehousing_out_order_str = lastWarehouseOut.WarehouseOutOrderNumber
  936. }
  937. //出库
  938. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  939. WarehouseOutId: lastWarehouseOutOne.ID,
  940. WarehouseOutOrderNumber: warehousing_out_order_str,
  941. DrugId: item.DrugId,
  942. Count: prescribing_number_total,
  943. Price: 0,
  944. TotalPrice: 0,
  945. Status: 1,
  946. Ctime: item.AdviceDate,
  947. Mtime: item.AdviceDate,
  948. Remark: "",
  949. OrgId: item.UserOrgId,
  950. Type: 0,
  951. Manufacturer: selfBasedrug.Manufacturer,
  952. Dealer: selfBasedrug.Dealer,
  953. RetailPrice: 0,
  954. RetailTotalPrice: 0,
  955. CountUnit: selfBasedrug.MinUnit,
  956. ExpiryDate: 0,
  957. ProductDate: 0,
  958. Number: "",
  959. BatchNumber: "",
  960. IsSys: 0,
  961. WarehouseInfoId: 0,
  962. AdminUserId: 0,
  963. StockCount: "",
  964. IsCheck: 1,
  965. SysRecordTime: item.AdviceDate,
  966. PatientId: item.PatientId,
  967. AdviceId: item.ID,
  968. ClassType: "",
  969. }
  970. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  971. for _, it := range warehousingOutInfo {
  972. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  973. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  974. //出库逻辑
  975. service.AutoSelfDrugDeliverInfoFourtyTwo(adminUserInfo.Org.Id, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  976. //查询剩余库存
  977. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  978. var sum_count int64
  979. for _, its := range stockInfo {
  980. if its.MaxUnit == medical.MaxUnit {
  981. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  982. }
  983. sum_count += its.StockMaxNumber + its.StockMinNumber
  984. }
  985. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  986. }
  987. }
  988. }
  989. }
  990. }
  991. }
  992. if advice.ExecutionState == 1 {
  993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  994. return
  995. }
  996. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  998. return
  999. }
  1000. //针对普宁
  1001. if adminUserInfo.Org.Id != 10599 {
  1002. fmt.Println("开始时间--------------------", advice.StartTime)
  1003. fmt.Println("theTime---------------------", theTime.Unix())
  1004. if advice.StartTime > theTime.Unix() {
  1005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1006. return
  1007. }
  1008. }
  1009. advices := models.DoctorAdvice{
  1010. ExecutionStaff: execution_staff,
  1011. ExecutionTime: theTime.Unix(),
  1012. UpdatedTime: time.Now().Unix(),
  1013. }
  1014. var err error
  1015. if groupno > 0 {
  1016. // 查询信息规挡的设置天数
  1017. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1018. if infor.ID > 0 && infor.WeekDay > 0 {
  1019. var cha_time int64
  1020. timeNowStr := time.Now().Format("2006-01-02")
  1021. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1022. //今日的日期减去设置的日期
  1023. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1024. if cha_time >= record_date {
  1025. //查询审核是否允许
  1026. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1027. //申请状态不允许的情况 拒绝修改
  1028. if infor.ApplicationStatus != 1 {
  1029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1030. return
  1031. }
  1032. }
  1033. }
  1034. err = service.ExceDoctorAdviceByGroupNoOne(&advices, groupno, adminUserInfo.Org.Id, patient_id, record_date)
  1035. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1036. redis := service.RedisClient()
  1037. //清空key 值
  1038. redis.Set(key, "", time.Second)
  1039. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1040. redis.Set(keyTwo, "", time.Second)
  1041. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1042. redis.Set(keyThree, "", time.Second)
  1043. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  1044. theTime := toTime.Format("2006-01-02")
  1045. fmt.Println("theTIME", theTime)
  1046. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1047. redis.Set(keyFour, "", time.Second)
  1048. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1049. redis.Set(keyFive, "", time.Second)
  1050. defer redis.Close()
  1051. } else {
  1052. // 查询信息规挡的设置天数
  1053. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1054. if infor.ID > 0 {
  1055. var cha_time int64
  1056. timeNowStr := time.Now().Format("2006-01-02")
  1057. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1058. //今日的日期减去设置的日期
  1059. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1060. if cha_time >= record_date {
  1061. //查询审核是否允许
  1062. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1063. //申请状态不允许的情况 拒绝修改
  1064. if infor.ApplicationStatus != 1 {
  1065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1066. return
  1067. }
  1068. }
  1069. }
  1070. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  1071. //记录日志
  1072. byterequest, _ := json.Marshal(advice)
  1073. adviceLog := models.XtDoctorAdviceLog{
  1074. UserOrgId: advice.UserOrgId,
  1075. PatientId: advice.PatientId,
  1076. AdminUserId: adminUserInfo.AdminUser.Id,
  1077. Module: 2,
  1078. ErrLog: string(byterequest),
  1079. Status: 1,
  1080. Ctime: time.Now().Unix(),
  1081. Mtime: 0,
  1082. Source: "手机端执行医嘱",
  1083. RecordDate: advices.RecordDate,
  1084. }
  1085. service.CreateDoctorAdviceLog(adviceLog)
  1086. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1087. redis := service.RedisClient()
  1088. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1089. redis.Set(keyTwo, "", time.Second)
  1090. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1091. redis.Set(keyThree, "", time.Second)
  1092. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  1093. theTime := toTime.Format("2006-01-02")
  1094. fmt.Println("theTIME", theTime)
  1095. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1096. redis.Set(keyFour, "", time.Second)
  1097. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1098. redis.Set(keySix, "", time.Second)
  1099. defer redis.Close()
  1100. //清空key 值
  1101. redis.Set(key, "", time.Second)
  1102. }
  1103. if err != nil {
  1104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1105. return
  1106. }
  1107. advice.ExecutionStaff = execution_staff
  1108. advice.ExecutionTime = theTime.Unix()
  1109. advice.ExecutionState = 1
  1110. advice.Modifier = adminUserInfo.AdminUser.Id
  1111. //处理出库相关逻辑
  1112. //1.判断是否启用药品管理和自备药出库功能
  1113. //药品管理信息
  1114. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  1115. //自备药信息
  1116. //privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  1117. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.Org.Id)
  1118. if drugStockConfig.IsOpen == 1 {
  1119. if groupno > 0 {
  1120. advices, _ := service.FindAllDoctorAdviceByGoroupNoTwety(adminUserInfo.Org.Id, groupno)
  1121. if len(advices) > 0 {
  1122. var total int64
  1123. var prescribing_number_total int64
  1124. //出库
  1125. for _, item := range advices {
  1126. if item.Way == 1 {
  1127. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  1128. //查询该药品的剩余库存
  1129. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  1130. //查询改药品信息
  1131. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1132. //判断单位是否相等
  1133. if medical.MaxUnit == item.PrescribingNumberUnit {
  1134. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1135. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1136. //转化为最小单位
  1137. total = list.Count * medical.MinNumber
  1138. prescribing_number_total = count * medical.MinNumber
  1139. }
  1140. if medical.MinUnit == item.PrescribingNumberUnit {
  1141. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1142. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1143. total = list.Count*medical.MinNumber + list.StockMinNumber
  1144. prescribing_number_total = count
  1145. }
  1146. if medical.IsUse == 1 {
  1147. c.ServeSuccessJSON(map[string]interface{}{
  1148. "msg": "1",
  1149. "advice": advice,
  1150. "ids": ids,
  1151. })
  1152. return
  1153. }
  1154. if medical.IsUse != 1 {
  1155. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1156. if advice.UserOrgId != 10278 && advice.UserOrgId != 10697 && advice.UserOrgId != 10635 && advice.UserOrgId != 10724 && advice.UserOrgId != 10571 && advice.UserOrgId != 10731 {
  1157. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  1158. advice.ExecutionTime = 0
  1159. advice.ExecutionState = 2
  1160. advice.ExecutionStaff = 0
  1161. }
  1162. c.ServeSuccessJSON(map[string]interface{}{
  1163. "msg": "3",
  1164. "advice": advice,
  1165. "ids": ids,
  1166. })
  1167. return
  1168. }
  1169. if prescribing_number_total > total {
  1170. if advice.UserOrgId != 10278 && advice.UserOrgId != 10697 && advice.UserOrgId != 10635 && advice.UserOrgId != 10724 && advice.UserOrgId != 10571 && advice.UserOrgId != 10731 {
  1171. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  1172. advice.ExecutionTime = 0
  1173. advice.ExecutionState = 2
  1174. advice.ExecutionStaff = 0
  1175. }
  1176. c.ServeSuccessJSON(map[string]interface{}{
  1177. "msg": "2",
  1178. "advice": advice,
  1179. "ids": ids,
  1180. })
  1181. return
  1182. }
  1183. }
  1184. //查询是否出库按钮开启
  1185. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  1186. if adviceSetting.IsAdviceOpen == 1 {
  1187. //查询是否出库按钮开启
  1188. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  1189. //患者发药
  1190. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  1191. if prescriptionConfig.IsOpen == 1 {
  1192. if medical.IsUse == 2 {
  1193. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1194. //查询今日是否出库
  1195. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1196. if drugOutInfo.ID == 0 {
  1197. if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 && item.UserOrgId != 10724 && item.UserOrgId != 10571 && item.UserOrgId != 10731 {
  1198. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1199. }
  1200. }
  1201. }
  1202. if pharmacyConfig.IsOpen != 1 {
  1203. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1204. if drugOutInfo.ID == 0 {
  1205. if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 && item.UserOrgId != 10724 && item.UserOrgId != 10571 && item.UserOrgId != 10731 {
  1206. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1207. }
  1208. }
  1209. }
  1210. //更新字典里面的库存
  1211. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1212. var sum_count int64
  1213. for _, its := range stockInfo {
  1214. if its.MaxUnit == medical.MaxUnit {
  1215. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1216. }
  1217. sum_count += its.StockMaxNumber + its.StockMinNumber
  1218. }
  1219. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1220. //剩余库存
  1221. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1222. }
  1223. }
  1224. } else {
  1225. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  1226. if medical.IsUse == 2 {
  1227. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1228. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1229. if drugOutInfo.ID == 0 {
  1230. if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 && item.UserOrgId != 10724 && item.UserOrgId != 10571 && item.UserOrgId != 10731 {
  1231. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1232. }
  1233. }
  1234. }
  1235. if pharmacyConfig.IsOpen != 1 {
  1236. drugError := models.XtDrugError{
  1237. ID: 0,
  1238. UserOrgId: item.UserOrgId,
  1239. DrugId: item.DrugId,
  1240. RecordDate: item.AdviceDate,
  1241. PatientId: item.PatientId,
  1242. Remark: "恒泰中医院出库开始",
  1243. Status: 1,
  1244. Ctime: time.Now().Unix(),
  1245. Mtime: 0,
  1246. Prescribingnumber: item.PrescribingNumber,
  1247. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1248. SumCount: 0,
  1249. }
  1250. service.CreateDrugError(drugError)
  1251. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1252. if drugOutInfo.ID == 0 {
  1253. if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 && item.UserOrgId != 10724 && item.UserOrgId != 10571 && item.UserOrgId != 10731 {
  1254. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1255. }
  1256. }
  1257. }
  1258. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1259. var sum_count int64
  1260. for _, its := range stockInfo {
  1261. if its.MaxUnit == medical.MaxUnit {
  1262. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1263. }
  1264. sum_count += its.StockMaxNumber + its.StockMinNumber
  1265. }
  1266. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1267. //剩余库存
  1268. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1269. }
  1270. }
  1271. }
  1272. }
  1273. }
  1274. c.ServeSuccessJSON(map[string]interface{}{
  1275. "msg": "1",
  1276. "advice": advice,
  1277. "ids": ids,
  1278. })
  1279. return
  1280. } else {
  1281. advices, _ := service.FindDoctorAdviceByIdsTwety(adminUserInfo.Org.Id, ids)
  1282. if len(advices) > 0 {
  1283. var total int64
  1284. var prescribing_number_total int64
  1285. for _, item := range advices {
  1286. if item.Way == 1 {
  1287. //查询改药品信息
  1288. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1289. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  1290. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  1291. //查询该药品的剩余库存
  1292. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  1293. //判断单位是否相等
  1294. if medical.MaxUnit == item.PrescribingNumberUnit {
  1295. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1296. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1297. //转化为最小单位
  1298. total = list.Count*medical.MinNumber + list.StockMinNumber
  1299. prescribing_number_total = count * medical.MinNumber
  1300. }
  1301. if medical.MinUnit == item.PrescribingNumberUnit {
  1302. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1303. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1304. total = list.Count*medical.MinNumber + list.StockMinNumber
  1305. prescribing_number_total = count
  1306. }
  1307. if medical.IsUse == 1 {
  1308. c.ServeSuccessJSON(map[string]interface{}{
  1309. "msg": "1",
  1310. "advice": advice,
  1311. "ids": ids,
  1312. })
  1313. return
  1314. }
  1315. if medical.IsUse != 1 {
  1316. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1317. if advice.UserOrgId != 10278 && advice.UserOrgId != 10697 && advice.UserOrgId != 10635 && item.UserOrgId != 10724 && item.UserOrgId != 10571 && item.UserOrgId != 10731 {
  1318. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  1319. advice.ExecutionTime = 0
  1320. advice.ExecutionState = 2
  1321. advice.ExecutionStaff = 0
  1322. }
  1323. c.ServeSuccessJSON(map[string]interface{}{
  1324. "msg": "3",
  1325. "advice": advice,
  1326. "ids": ids,
  1327. })
  1328. return
  1329. }
  1330. if prescribing_number_total > total {
  1331. if advice.UserOrgId != 10278 && advice.UserOrgId != 10697 && advice.UserOrgId != 10635 && item.UserOrgId != 10724 && item.UserOrgId != 10571 && item.UserOrgId != 10731 {
  1332. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  1333. advice.ExecutionTime = 0
  1334. advice.ExecutionState = 2
  1335. advice.ExecutionStaff = 0
  1336. }
  1337. c.ServeSuccessJSON(map[string]interface{}{
  1338. "msg": "2",
  1339. "advice": advice,
  1340. "ids": ids,
  1341. })
  1342. return
  1343. }
  1344. }
  1345. if medical.IsUse == 2 {
  1346. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1347. //查询今日是否出库
  1348. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1349. if drugOutInfo.ID == 0 {
  1350. if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 && item.UserOrgId != 10724 && item.UserOrgId != 10571 && item.UserOrgId != 10731 {
  1351. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1352. }
  1353. }
  1354. }
  1355. if pharmacyConfig.IsOpen != 1 {
  1356. //查询今日是否出库
  1357. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1358. if drugOutInfo.ID == 0 {
  1359. if item.UserOrgId != 10644 && item.UserOrgId != 10721 && item.UserOrgId != 10138 && item.UserOrgId != 10278 && item.UserOrgId != 10724 && item.UserOrgId != 10571 && item.UserOrgId != 10731 {
  1360. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  1361. }
  1362. }
  1363. }
  1364. //更新字典里面的库存
  1365. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1366. var sum_count int64
  1367. for _, its := range stockInfo {
  1368. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  1369. if its.MaxUnit == baseDrug.MaxUnit {
  1370. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  1371. }
  1372. sum_count += its.StockMaxNumber + its.StockMinNumber
  1373. }
  1374. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1375. //剩余库存
  1376. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1377. }
  1378. if medical.IsUse == 1 {
  1379. c.ServeSuccessJSON(map[string]interface{}{
  1380. "msg": "1",
  1381. "advice": advice,
  1382. "ids": ids,
  1383. })
  1384. return
  1385. }
  1386. }
  1387. }
  1388. }
  1389. c.ServeSuccessJSON(map[string]interface{}{
  1390. "msg": "1",
  1391. "advice": advice,
  1392. "ids": ids,
  1393. })
  1394. return
  1395. }
  1396. }
  1397. //if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  1398. // if groupno > 0 {
  1399. // advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1400. // for _, item := range advices {
  1401. //
  1402. // if item.ExecutionState == 1 && item.Way == 2 {
  1403. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1404. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1405. //
  1406. // timeStr := time.Now().Format("2006-01-02")
  1407. // timeArr := strings.Split(timeStr, "-")
  1408. // total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  1409. //
  1410. // total = total + 1
  1411. // warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1412. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1413. // number = number + total
  1414. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1415. // //插入自备药出库单
  1416. // outStock := models.XtSelfOutStock{
  1417. // DrugName: item.AdviceName,
  1418. // DrugNameId: item.DrugNameId,
  1419. // DrugSpec: item.AdviceDesc,
  1420. // OutstoreNumber: count,
  1421. // AdminUserId: adminUserInfo.AdminUser.Id,
  1422. // StorckTime: item.AdviceDate,
  1423. // UserOrgId: adminUserInfo.Org.Id,
  1424. // CreatedTime: time.Now().Unix(),
  1425. // Status: 1,
  1426. // PatientId: item.PatientId,
  1427. // ExitMode: 2,
  1428. // MedicId: item.DrugId,
  1429. // StockOutNumber: warehousing_out_order,
  1430. // }
  1431. // //查询 该患者是否已出库
  1432. // out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1433. //
  1434. // if errcode == gorm.ErrRecordNotFound {
  1435. // service.CreateOutStock(&outStock)
  1436. // } else if errcode == nil {
  1437. // err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1438. // fmt.Println("err", err)
  1439. // }
  1440. // }
  1441. // }
  1442. // } else {
  1443. //
  1444. // advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1445. // for _, item := range advices {
  1446. //
  1447. // if item.ExecutionState == 1 && item.Way == 2 {
  1448. //
  1449. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1450. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1451. //
  1452. // timeStr := time.Now().Format("2006-01-02")
  1453. // timeArr := strings.Split(timeStr, "-")
  1454. // total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  1455. //
  1456. // total = total + 1
  1457. // warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1458. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1459. // number = number + total
  1460. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1461. //
  1462. // //插入自备药出库单
  1463. // outStock := models.XtSelfOutStock{
  1464. // DrugName: item.AdviceName,
  1465. // DrugNameId: item.DrugNameId,
  1466. // DrugSpec: item.AdviceDesc,
  1467. // OutstoreNumber: count,
  1468. // AdminUserId: adminUserInfo.AdminUser.Id,
  1469. // StorckTime: item.AdviceDate,
  1470. // UserOrgId: adminUserInfo.Org.Id,
  1471. // CreatedTime: time.Now().Unix(),
  1472. // Status: 1,
  1473. // PatientId: item.PatientId,
  1474. // ExitMode: 2,
  1475. // MedicId: item.DrugId,
  1476. // StockOutNumber: warehousing_out_order,
  1477. // }
  1478. //
  1479. // //查询 该患者是否已出库
  1480. // out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1481. //
  1482. // if errcode == gorm.ErrRecordNotFound {
  1483. // service.CreateOutStock(&outStock)
  1484. // } else if errcode == nil {
  1485. // err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1486. // fmt.Println("err", err)
  1487. // }
  1488. // }
  1489. // }
  1490. // c.ServeSuccessJSON(map[string]interface{}{
  1491. // "msg": "1",
  1492. // "advice": advice,
  1493. // "ids": ids,
  1494. // })
  1495. // return
  1496. // }
  1497. //}
  1498. c.ServeSuccessJSON(map[string]interface{}{
  1499. "msg": "1",
  1500. "advice": advice,
  1501. "ids": ids,
  1502. })
  1503. return
  1504. } else if origin == 2 {
  1505. // 开始主事务
  1506. db := service.XTWriteDB()
  1507. tx := db.Begin()
  1508. // 在函数结束时处理事务回滚
  1509. defer func() {
  1510. if r := recover(); r != nil {
  1511. tx.Rollback()
  1512. }
  1513. }()
  1514. adminInfo := c.GetMobileAdminUserInfo()
  1515. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  1516. var ids []string
  1517. advice_ids := c.GetString("advice_id")
  1518. ids = strings.Split(advice_ids, ",")
  1519. if len(execution_time) <= 0 {
  1520. utils.ErrorLog("execution_time")
  1521. tx.Rollback()
  1522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1523. return
  1524. }
  1525. timeLayout2 := "2006-01-02 15:04:05"
  1526. loc, _ := time.LoadLocation("Local")
  1527. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1528. if errs != nil {
  1529. utils.ErrorLog(errs.Error())
  1530. tx.Rollback()
  1531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1532. return
  1533. }
  1534. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1535. var err error
  1536. for _, item := range advices {
  1537. if item.ExecutionState == 1 {
  1538. tx.Rollback()
  1539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1540. return
  1541. }
  1542. if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
  1543. tx.Rollback()
  1544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1545. return
  1546. }
  1547. if item.StartTime > theTime.Unix() {
  1548. tx.Rollback()
  1549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1550. return
  1551. }
  1552. item.ExecutionState = 1
  1553. item.ExecutionStaff = adminInfo.AdminUser.Id
  1554. item.ExecutionTime = theTime.Unix()
  1555. item.IsMobile = 1
  1556. // 查询信息规挡的设置天数
  1557. infor, _ := service.GetDialysisInformationSetting(item.UserOrgId)
  1558. if infor.ID > 0 {
  1559. var cha_time int64
  1560. timeNowStr := time.Now().Format("2006-01-02")
  1561. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1562. //今日的日期减去设置的日期
  1563. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1564. if cha_time >= item.AdviceDate {
  1565. //查询审核是否允许
  1566. infor, _ := service.GetDialysisInformationByRecordDate(item.PatientId, item.AdviceDate, item.UserOrgId, 4)
  1567. //申请状态不允许的情况 拒绝修改
  1568. if infor.ApplicationStatus != 1 {
  1569. tx.Rollback()
  1570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1571. return
  1572. }
  1573. }
  1574. }
  1575. service.SaveHisDoctorAdviceOne(item, tx)
  1576. //记录日志
  1577. byterequest, _ := json.Marshal(item)
  1578. adviceLog := models.XtDoctorAdviceLog{
  1579. UserOrgId: item.UserOrgId,
  1580. PatientId: item.PatientId,
  1581. AdminUserId: item.ExecutionStaff,
  1582. Module: 2,
  1583. ErrLog: string(byterequest),
  1584. Status: 1,
  1585. Ctime: time.Now().Unix(),
  1586. Mtime: 0,
  1587. Source: "手机端执行his医嘱",
  1588. RecordDate: item.AdviceDate,
  1589. }
  1590. service.CreateDoctorAdviceLog(adviceLog)
  1591. if err == nil {
  1592. drugError := models.XtDrugError{
  1593. UserOrgId: adminInfo.Org.Id,
  1594. DrugId: item.DrugId,
  1595. RecordDate: item.AdviceDate,
  1596. PatientId: item.PatientId,
  1597. Remark: "执行成功",
  1598. Status: 1,
  1599. Ctime: time.Now().Unix(),
  1600. Mtime: 0,
  1601. SumCount: 0,
  1602. Prescribingnumber: item.PrescribingNumber,
  1603. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1604. }
  1605. service.CreateDrugError(drugError)
  1606. }
  1607. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1608. redis := service.RedisClient()
  1609. //清空key 值
  1610. redis.Set(key, "", time.Second)
  1611. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1612. redis.Set(keyTwo, "", time.Second)
  1613. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1614. redis.Set(keyThree, "", time.Second)
  1615. recordDate := theTime.Format("2006-01-02")
  1616. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1617. redis.Set(keyFour, "", time.Second)
  1618. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1619. redis.Set(keyFive, "", time.Second)
  1620. defer redis.Close()
  1621. }
  1622. //药品管理信息
  1623. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  1624. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  1625. if drugStockConfig.IsOpen == 1 {
  1626. for _, item := range advices {
  1627. //查询改药品信息
  1628. medical, _ := service.GetBaseDrugMedicalOne(item.DrugId, tx)
  1629. //判断单位是否合格
  1630. if item.PrescribingNumberUnit != medical.MaxUnit && item.PrescribingNumberUnit != medical.MinUnit {
  1631. //查询该药品是否有出库记录
  1632. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate, tx)
  1633. if len(flowMap) == 0 {
  1634. errs := service.UpdateHisAdviceByIdOne(item.ID, tx)
  1635. if errs != nil {
  1636. drugError := models.XtDrugError{
  1637. UserOrgId: adminInfo.Org.Id,
  1638. DrugId: item.DrugId,
  1639. RecordDate: item.AdviceDate,
  1640. PatientId: item.PatientId,
  1641. Remark: "单位不统一,执行失败",
  1642. Status: 1,
  1643. Ctime: time.Now().Unix(),
  1644. Mtime: 0,
  1645. SumCount: 0,
  1646. Prescribingnumber: item.PrescribingNumber,
  1647. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1648. }
  1649. service.CreateDrugError(drugError)
  1650. }
  1651. }
  1652. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1653. tx.Rollback()
  1654. c.ServeSuccessJSON(map[string]interface{}{
  1655. "msg": "7",
  1656. "advice": advice,
  1657. "ids": ids,
  1658. })
  1659. return
  1660. }
  1661. //查询这个患者这个患者这个药已经出库的所有数量
  1662. advicelist, _ := service.GetAllHisDoctorAdviceByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
  1663. drugoutlist, _ := service.GetAllDrugFlowByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
  1664. var total_count int64
  1665. var drug_count int64
  1666. for _, it := range advicelist {
  1667. if it.PrescribingNumberUnit == medical.MaxUnit {
  1668. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1669. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1670. total_count += prenumber * medical.MinNumber
  1671. }
  1672. if it.PrescribingNumberUnit == medical.MinUnit {
  1673. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1674. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1675. total_count += prenumber
  1676. }
  1677. }
  1678. for _, its := range drugoutlist {
  1679. if its.CountUnit == medical.MaxUnit {
  1680. drug_count += its.Count * medical.MinNumber
  1681. }
  1682. if its.CountUnit == medical.MinUnit {
  1683. drug_count += its.Count
  1684. }
  1685. }
  1686. if total_count == drug_count {
  1687. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1688. tx.Commit()
  1689. c.ServeSuccessJSON(map[string]interface{}{
  1690. "msg": "1",
  1691. "advice": advice,
  1692. "ids": ids,
  1693. })
  1694. return
  1695. }
  1696. advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
  1697. var total int64
  1698. var prescribing_number_total int64
  1699. //保存处方出库
  1700. config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
  1701. if config.IsOpen != 1 {
  1702. //查询该药品是否有库存
  1703. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1704. list, _ := service.GetDrugTotalCountTwoTwety(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut, tx)
  1705. //判断单位是否相等
  1706. if medical.MaxUnit == advice.PrescribingNumberUnit && medical.MaxUnit != medical.MinUnit {
  1707. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1708. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1709. //转化为最小单位
  1710. total = list.Count*medical.MinNumber + list.StockMinNumber
  1711. prescribing_number_total = count * medical.MinNumber
  1712. }
  1713. if medical.MinUnit == advice.PrescribingNumberUnit && medical.MaxUnit != medical.MinUnit {
  1714. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1715. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1716. total = list.Count*medical.MinNumber + list.StockMinNumber
  1717. prescribing_number_total = count
  1718. }
  1719. if medical.MinUnit == advice.PrescribingNumberUnit && medical.MaxUnit == medical.MinUnit {
  1720. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1721. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1722. total = list.Count*medical.MinNumber + list.StockMinNumber
  1723. prescribing_number_total = count
  1724. }
  1725. if medical.IsUse == 1 {
  1726. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1727. drugError := models.XtDrugError{
  1728. UserOrgId: adminInfo.Org.Id,
  1729. DrugId: item.DrugId,
  1730. RecordDate: item.AdviceDate,
  1731. PatientId: item.PatientId,
  1732. Remark: "零用药品库存不足",
  1733. Status: 1,
  1734. Ctime: time.Now().Unix(),
  1735. Mtime: 0,
  1736. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1737. Prescribingnumber: advice.PrescribingNumber,
  1738. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1739. }
  1740. service.CreateDrugError(drugError)
  1741. tx.Rollback()
  1742. c.ServeSuccessJSON(map[string]interface{}{
  1743. "msg": "1",
  1744. "advice": advice,
  1745. "ids": ids,
  1746. })
  1747. return
  1748. }
  1749. }
  1750. if medical.IsUse != 1 {
  1751. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1752. drugError := models.XtDrugError{
  1753. UserOrgId: adminInfo.Org.Id,
  1754. DrugId: item.DrugId,
  1755. RecordDate: item.AdviceDate,
  1756. PatientId: item.PatientId,
  1757. Remark: "药品库存不足",
  1758. Status: 1,
  1759. Ctime: time.Now().Unix(),
  1760. Mtime: 0,
  1761. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1762. Prescribingnumber: advice.PrescribingNumber,
  1763. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1764. }
  1765. service.CreateDrugError(drugError)
  1766. tx.Rollback()
  1767. c.ServeSuccessJSON(map[string]interface{}{
  1768. "msg": "3",
  1769. "advice": advice,
  1770. "ids": ids,
  1771. })
  1772. return
  1773. }
  1774. if prescribing_number_total > total {
  1775. drugError := models.XtDrugError{
  1776. UserOrgId: adminInfo.Org.Id,
  1777. DrugId: item.DrugId,
  1778. RecordDate: item.AdviceDate,
  1779. PatientId: item.PatientId,
  1780. Remark: "出库数量大于库存",
  1781. Status: 1,
  1782. Ctime: time.Now().Unix(),
  1783. Mtime: 0,
  1784. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1785. Prescribingnumber: advice.PrescribingNumber,
  1786. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1787. }
  1788. service.CreateDrugError(drugError)
  1789. tx.Rollback()
  1790. c.ServeSuccessJSON(map[string]interface{}{
  1791. "msg": "2",
  1792. "advice": advice,
  1793. "ids": ids,
  1794. })
  1795. return
  1796. }
  1797. }
  1798. if prescribing_number_total <= total {
  1799. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1800. //判断药品是否零用
  1801. if medical.IsUse == 2 {
  1802. if config.IsOpen != 1 {
  1803. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1804. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1805. //查询该药品是否有出库记录
  1806. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
  1807. if len(flowMap) == 0 {
  1808. errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
  1809. if errs != nil {
  1810. drugError := models.XtDrugError{
  1811. UserOrgId: adminInfo.Org.Id,
  1812. DrugId: item.DrugId,
  1813. RecordDate: item.AdviceDate,
  1814. PatientId: item.PatientId,
  1815. Remark: "出库记录为空,更新执行人失败",
  1816. Status: 1,
  1817. Ctime: time.Now().Unix(),
  1818. Mtime: 0,
  1819. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1820. Prescribingnumber: advice.PrescribingNumber,
  1821. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1822. }
  1823. service.CreateDrugError(drugError)
  1824. }
  1825. tx.Rollback()
  1826. c.ServeSuccessJSON(map[string]interface{}{
  1827. "msg": "6",
  1828. "advice": advice,
  1829. "ids": ids,
  1830. })
  1831. return
  1832. }
  1833. }
  1834. }
  1835. if pharmacyConfig.IsOpen != 1 {
  1836. //查询已经出库数量
  1837. outListExport, _ := service.GetWarehouseOutListExport(advice.DrugId, advice.PatientId, advice.AdviceDate, advice.ID)
  1838. var out_count int64
  1839. if len(outListExport) > 0 {
  1840. for _, item := range outListExport {
  1841. if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1842. out_count = item.Count * medical.MinNumber
  1843. }
  1844. if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1845. out_count = item.Count
  1846. }
  1847. if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  1848. out_count = item.Count * medical.MinNumber
  1849. }
  1850. }
  1851. }
  1852. newadviceInfo := &models.HisDoctorAdviceInfo{
  1853. ID: advice.ID,
  1854. UserOrgId: advice.UserOrgId,
  1855. PatientId: advice.PatientId,
  1856. HisPatientId: advice.HisPatientId,
  1857. AdviceType: advice.AdviceType,
  1858. AdviceDate: advice.AdviceDate,
  1859. StartTime: advice.StartTime,
  1860. AdviceName: advice.AdviceName,
  1861. AdviceDesc: advice.AdviceDesc,
  1862. ReminderDate: advice.ReminderDate,
  1863. SingleDose: advice.SingleDose,
  1864. SingleDoseUnit: advice.SingleDoseUnit,
  1865. PrescribingNumber: advice.PrescribingNumber,
  1866. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1867. DeliveryWay: advice.DeliveryWay,
  1868. ExecutionFrequency: advice.ExecutionFrequency,
  1869. AdviceDoctor: advice.AdviceDoctor,
  1870. Status: advice.Status,
  1871. CreatedTime: advice.CreatedTime,
  1872. UpdatedTime: advice.UpdatedTime,
  1873. AdviceAffirm: advice.AdviceAffirm,
  1874. Remark: advice.Remark,
  1875. StopTime: advice.StopTime,
  1876. StopReason: advice.StopReason,
  1877. StopDoctor: advice.StopDoctor,
  1878. StopState: advice.StopState,
  1879. ParentId: advice.ParentId,
  1880. ExecutionTime: advice.ExecutionTime,
  1881. ExecutionStaff: advice.ExecutionStaff,
  1882. ExecutionState: advice.ExecutionState,
  1883. Checker: advice.Checker,
  1884. RecordDate: advice.RecordDate,
  1885. DialysisOrderId: advice.DialysisOrderId,
  1886. CheckTime: advice.CheckTime,
  1887. CheckState: advice.CheckState,
  1888. DrugSpec: advice.DrugSpec,
  1889. DrugSpecUnit: advice.DrugSpecUnit,
  1890. Groupno: advice.Groupno,
  1891. RemindType: advice.RemindType,
  1892. FrequencyType: advice.FrequencyType,
  1893. DayCount: advice.DayCount,
  1894. WeekDay: advice.WeekDay,
  1895. TemplateId: advice.TemplateId,
  1896. Modifier: advice.Modifier,
  1897. DrugId: advice.DrugId,
  1898. Price: advice.Price,
  1899. PrescriptionId: advice.PrescriptionId,
  1900. MedListCodg: advice.MedListCodg,
  1901. FeedetlSn: advice.FeedetlSn,
  1902. Day: advice.DayCount,
  1903. ChildDoctorAdvice: nil,
  1904. Drug: models.Drug{},
  1905. Diagnosis: advice.Diagnosis,
  1906. Way: advice.Way,
  1907. HospApprFlag: advice.HospApprFlag,
  1908. LmtUsedFlag: advice.LmtUsedFlag,
  1909. HisOrderInfo: models.HisOrderInfo{},
  1910. IsMedicine: advice.IsMedicine,
  1911. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  1912. Child: nil,
  1913. IsSettle: advice.IsSettle,
  1914. IsMobile: advice.IsMobile,
  1915. IsSelfDrug: advice.IsSelfDrug,
  1916. DrugWayCount: advice.DrugWayCount,
  1917. }
  1918. //如果当前医嘱数量大于历史出库数据则需要出库
  1919. if prescribing_number_total > out_count {
  1920. //按最小单位出库
  1921. var cha_count = prescribing_number_total - out_count
  1922. newadviceInfo.PrescribingNumber = float64(cha_count)
  1923. newadviceInfo.PrescribingNumberUnit = medical.MinUnit
  1924. if advice.UserOrgId != 10644 {
  1925. service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
  1926. }
  1927. }
  1928. //如果当前医嘱数量小于历史出库数据则需要退库
  1929. if prescribing_number_total < out_count {
  1930. var cha_count = out_count - prescribing_number_total
  1931. drug, _ := service.FindBaseDrugLibRecordSeven(advice.UserOrgId, advice.DrugId)
  1932. service.NewHisDrugCancelInfo(advice.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  1933. service.NewHisDrugAutoCancelInfo(advice.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  1934. }
  1935. if prescribing_number_total == out_count {
  1936. if out_count == 0 {
  1937. if advice.UserOrgId != 10644 {
  1938. service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
  1939. }
  1940. }
  1941. }
  1942. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1943. //查询该药品是否有出库记录
  1944. flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
  1945. if len(flowMap) == 0 {
  1946. errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
  1947. if errs != nil {
  1948. drugError := models.XtDrugError{
  1949. UserOrgId: adminInfo.Org.Id,
  1950. DrugId: item.DrugId,
  1951. RecordDate: item.AdviceDate,
  1952. PatientId: item.PatientId,
  1953. Remark: "出库记录为空,更新执行人失败",
  1954. Status: 1,
  1955. Ctime: time.Now().Unix(),
  1956. Mtime: 0,
  1957. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1958. Prescribingnumber: advice.PrescribingNumber,
  1959. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1960. }
  1961. service.CreateDrugError(drugError)
  1962. }
  1963. tx.Rollback()
  1964. c.ServeSuccessJSON(map[string]interface{}{
  1965. "msg": "6",
  1966. "advice": advice,
  1967. "ids": ids,
  1968. })
  1969. return
  1970. }
  1971. }
  1972. }
  1973. //更新字典里面的库存
  1974. stockInfo, _ := service.GetNewDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId, tx)
  1975. var sum_count int64
  1976. for _, its := range stockInfo {
  1977. if its.MaxUnit == medical.MaxUnit {
  1978. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1979. }
  1980. sum_count += its.StockMaxNumber + its.StockMinNumber
  1981. }
  1982. service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId, tx)
  1983. //剩余库存
  1984. service.UpdateNewDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count, tx)
  1985. }
  1986. }
  1987. }
  1988. }
  1989. //自备药
  1990. selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminInfo.Org.Id)
  1991. if selfPrescriptionOutOpen.IsOpen == 1 {
  1992. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  1993. if selfBasedrug.IsSelfDrug == 1 {
  1994. //查询是否有库存
  1995. info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
  1996. if len(info) > 0 {
  1997. var total_count int64
  1998. var prescribing_number_total int64
  1999. for _, item := range info {
  2000. if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  2001. item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
  2002. }
  2003. total_count += item.StockMaxNumber + item.StockMinNumber
  2004. }
  2005. //判断单位是否相等
  2006. if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  2007. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2008. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2009. //转化为最小单位
  2010. prescribing_number_total = count * selfBasedrug.MinNumber
  2011. }
  2012. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  2013. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2014. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2015. prescribing_number_total = count
  2016. }
  2017. if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  2018. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2019. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2020. prescribing_number_total = count
  2021. }
  2022. if prescribing_number_total > total_count {
  2023. tx.Rollback()
  2024. c.ServeSuccessJSON(map[string]interface{}{
  2025. "msg": "3",
  2026. "advice": advice,
  2027. })
  2028. return
  2029. }
  2030. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  2031. //出库
  2032. if prescribing_number_total <= total_count {
  2033. timeStr := time.Now().Format("2006-01-02")
  2034. timeArr := strings.Split(timeStr, "-")
  2035. total, _ := service.FindAllSelfDrugWarehouseOut(adminInfo.Org.Id, tx)
  2036. total = total + 1
  2037. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2038. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2039. number = number + total
  2040. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  2041. operation_time := time.Now().Unix()
  2042. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  2043. //创建一个出库单
  2044. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  2045. WarehouseOutOrderNumber: warehousing_out_order,
  2046. OperationTime: operation_time,
  2047. OrgId: adminInfo.Org.Id,
  2048. Creater: creater,
  2049. Ctime: time.Now().Unix(),
  2050. Status: 1,
  2051. WarehouseOutTime: advice.AdviceDate,
  2052. Type: 0,
  2053. PatientId: advice.PatientId,
  2054. IsCheck: 1,
  2055. IsSys: 1,
  2056. }
  2057. //查询今日是否有出库数据
  2058. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(adminInfo.Org.Id, advice.AdviceDate, tx, 1)
  2059. if lastWarehouseOut.ID == 0 {
  2060. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  2061. }
  2062. //查询今日是否有出库数据
  2063. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(adminInfo.Org.Id, advice.AdviceDate, tx, 1)
  2064. //出库
  2065. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  2066. WarehouseOutId: lastWarehouseOutOne.ID,
  2067. WarehouseOutOrderNumber: warehousing_out_order,
  2068. DrugId: advice.DrugId,
  2069. Count: prescribing_number_total,
  2070. Price: 0,
  2071. TotalPrice: 0,
  2072. Status: 1,
  2073. Ctime: advice.AdviceDate,
  2074. Mtime: advice.AdviceDate,
  2075. Remark: "",
  2076. OrgId: advice.UserOrgId,
  2077. Type: 0,
  2078. Manufacturer: selfBasedrug.Manufacturer,
  2079. Dealer: selfBasedrug.Dealer,
  2080. RetailPrice: 0,
  2081. RetailTotalPrice: 0,
  2082. CountUnit: selfBasedrug.MinUnit,
  2083. ExpiryDate: 0,
  2084. ProductDate: 0,
  2085. Number: "",
  2086. BatchNumber: "",
  2087. IsSys: 0,
  2088. WarehouseInfoId: 0,
  2089. AdminUserId: 0,
  2090. StockCount: "",
  2091. IsCheck: 1,
  2092. SysRecordTime: advice.AdviceDate,
  2093. PatientId: advice.PatientId,
  2094. AdviceId: advice.ID,
  2095. ClassType: "",
  2096. }
  2097. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  2098. for _, it := range warehousingOutInfo {
  2099. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  2100. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  2101. //出库逻辑
  2102. service.AutoSelfDrugDeliverInfoFourtyTwo(adminInfo.Org.Id, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  2103. //查询剩余库存
  2104. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  2105. var sum_count int64
  2106. for _, its := range stockInfo {
  2107. if its.MaxUnit == medical.MaxUnit {
  2108. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2109. }
  2110. sum_count += its.StockMaxNumber + its.StockMinNumber
  2111. }
  2112. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  2113. }
  2114. }
  2115. } else {
  2116. tx.Rollback()
  2117. c.ServeSuccessJSON(map[string]interface{}{
  2118. "msg": "3",
  2119. "advice": advice,
  2120. })
  2121. return
  2122. }
  2123. }
  2124. }
  2125. //针对异常未出库问题的脚本
  2126. //if adminInfo.Org.Id == 10265 {
  2127. //
  2128. // newadviceInfo := &models.HisDoctorAdviceInfo{
  2129. // ID: advice.ID,
  2130. // UserOrgId: advice.UserOrgId,
  2131. // PatientId: advice.PatientId,
  2132. // HisPatientId: advice.HisPatientId,
  2133. // AdviceType: advice.AdviceType,
  2134. // AdviceDate: advice.AdviceDate,
  2135. // StartTime: advice.StartTime,
  2136. // AdviceName: advice.AdviceName,
  2137. // AdviceDesc: advice.AdviceDesc,
  2138. // ReminderDate: advice.ReminderDate,
  2139. // SingleDose: advice.SingleDose,
  2140. // SingleDoseUnit: advice.SingleDoseUnit,
  2141. // PrescribingNumber: advice.PrescribingNumber,
  2142. // PrescribingNumberUnit: advice.PrescribingNumberUnit,
  2143. // DeliveryWay: advice.DeliveryWay,
  2144. // ExecutionFrequency: advice.ExecutionFrequency,
  2145. // AdviceDoctor: advice.AdviceDoctor,
  2146. // Status: advice.Status,
  2147. // CreatedTime: advice.CreatedTime,
  2148. // UpdatedTime: advice.UpdatedTime,
  2149. // AdviceAffirm: advice.AdviceAffirm,
  2150. // Remark: advice.Remark,
  2151. // StopTime: advice.StopTime,
  2152. // StopReason: advice.StopReason,
  2153. // StopDoctor: advice.StopDoctor,
  2154. // StopState: advice.StopState,
  2155. // ParentId: advice.ParentId,
  2156. // ExecutionTime: advice.ExecutionTime,
  2157. // ExecutionStaff: advice.ExecutionStaff,
  2158. // ExecutionState: advice.ExecutionState,
  2159. // Checker: advice.Checker,
  2160. // RecordDate: advice.RecordDate,
  2161. // DialysisOrderId: advice.DialysisOrderId,
  2162. // CheckTime: advice.CheckTime,
  2163. // CheckState: advice.CheckState,
  2164. // DrugSpec: advice.DrugSpec,
  2165. // DrugSpecUnit: advice.DrugSpecUnit,
  2166. // Groupno: advice.Groupno,
  2167. // RemindType: advice.RemindType,
  2168. // FrequencyType: advice.FrequencyType,
  2169. // DayCount: advice.DayCount,
  2170. // WeekDay: advice.WeekDay,
  2171. // TemplateId: advice.TemplateId,
  2172. // Modifier: advice.Modifier,
  2173. // DrugId: advice.DrugId,
  2174. // Price: advice.Price,
  2175. // PrescriptionId: advice.PrescriptionId,
  2176. // MedListCodg: advice.MedListCodg,
  2177. // FeedetlSn: advice.FeedetlSn,
  2178. // Day: advice.DayCount,
  2179. // ChildDoctorAdvice: nil,
  2180. // Drug: models.Drug{},
  2181. // Diagnosis: advice.Diagnosis,
  2182. // Way: advice.Way,
  2183. // HospApprFlag: advice.HospApprFlag,
  2184. // LmtUsedFlag: advice.LmtUsedFlag,
  2185. // HisOrderInfo: models.HisOrderInfo{},
  2186. // IsMedicine: advice.IsMedicine,
  2187. // ExecutionFrequencyId: advice.ExecutionFrequencyId,
  2188. // Child: nil,
  2189. // IsSettle: advice.IsSettle,
  2190. // IsMobile: advice.IsMobile,
  2191. // IsSelfDrug: advice.IsSelfDrug,
  2192. // DrugWayCount: advice.DrugWayCount,
  2193. // }
  2194. // outListExport, _ := service.GetWarehouseOutListExport(advice.DrugId, advice.PatientId, advice.AdviceDate, advice.ID)
  2195. // fmt.Println(outListExport)
  2196. // //var out_count int64
  2197. // //if len(outListExport) > 0 {
  2198. // // for _, item := range outListExport {
  2199. // // if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2200. // // out_count = item.Count * medical.MinNumber
  2201. // // }
  2202. // // if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2203. // // out_count = item.Count
  2204. // // }
  2205. // // if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2206. // // out_count = item.Count * medical.MinNumber
  2207. // // }
  2208. // //
  2209. // // }
  2210. // //}
  2211. // //按最小单位出库
  2212. // //var cha_count = total_count - out_count
  2213. //
  2214. // var cha_count = 40
  2215. //
  2216. // newadviceInfo.PrescribingNumber = float64(cha_count)
  2217. // newadviceInfo.PrescribingNumberUnit = medical.MinUnit
  2218. // service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
  2219. //
  2220. // //查询剩余库存
  2221. // stockInfo, _ := service.GetSelfDrugAllStockInfo(newadviceInfo.PatientId, newadviceInfo.UserOrgId, newadviceInfo.DrugId, tx)
  2222. // var sum_count int64
  2223. // for _, its := range stockInfo {
  2224. // if its.MaxUnit == medical.MaxUnit {
  2225. // its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2226. // }
  2227. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2228. // }
  2229. // service.UpdateSelfDrugStockCount(newadviceInfo.DrugId, newadviceInfo.UserOrgId, newadviceInfo.PatientId, sum_count, tx)
  2230. //}
  2231. }
  2232. }
  2233. tx.Commit()
  2234. for _, item := range advices {
  2235. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  2236. c.ServeSuccessJSON(map[string]interface{}{
  2237. "msg": "1",
  2238. "advice": advice,
  2239. "ids": ids,
  2240. })
  2241. }
  2242. }
  2243. }
  2244. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  2245. execution_time := c.GetString("execution_time")
  2246. fmt.Println("execution_time", execution_time)
  2247. groupno, _ := c.GetInt64("groupno", -1)
  2248. patient_id, _ := c.GetInt64("patient_id")
  2249. advice_date, _ := c.GetInt64("advice_date")
  2250. record_date, _ := c.GetInt64("record_date")
  2251. var ids []string
  2252. if groupno == 0 {
  2253. advice_ids := c.GetString("advice_id")
  2254. ids = strings.Split(advice_ids, ",")
  2255. }
  2256. if groupno < 0 {
  2257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2258. return
  2259. }
  2260. if len(execution_time) <= 0 {
  2261. utils.ErrorLog("execution_time")
  2262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2263. return
  2264. }
  2265. timeLayout2 := "2006-01-02 15:04:05"
  2266. loc, _ := time.LoadLocation("Local")
  2267. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  2268. if errs != nil {
  2269. utils.ErrorLog(errs.Error())
  2270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2271. return
  2272. }
  2273. adminUserInfo := c.GetMobileAdminUserInfo()
  2274. var advice models.DoctorAdvice
  2275. if groupno > 0 {
  2276. advices, _ := service.FindAllDoctorAdviceByGoroupNoThree(adminUserInfo.Org.Id, groupno, patient_id, record_date)
  2277. for _, item := range advices {
  2278. if item.ExecutionState == 1 {
  2279. advice = item
  2280. }
  2281. }
  2282. } else {
  2283. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2284. for _, item := range advices {
  2285. if item.ExecutionState == 1 {
  2286. advice = item
  2287. }
  2288. }
  2289. }
  2290. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  2291. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2292. // if getPermissionErr != nil {
  2293. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2294. // return
  2295. // } else if headNursePermission == nil {
  2296. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2297. // return
  2298. // }
  2299. //}
  2300. if advice.StartTime > theTime.Unix() {
  2301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2302. return
  2303. }
  2304. advices := models.DoctorAdvice{
  2305. ExecutionTime: theTime.Unix(),
  2306. UpdatedTime: time.Now().Unix(),
  2307. }
  2308. var err error
  2309. if groupno > 0 {
  2310. // 查询信息规挡的设置天数
  2311. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2312. if infor.ID > 0 {
  2313. var cha_time int64
  2314. timeNowStr := time.Now().Format("2006-01-02")
  2315. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2316. //今日的日期减去设置的日期
  2317. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2318. if cha_time >= advices.AdviceDate {
  2319. //查询审核是否允许
  2320. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2321. //申请状态不允许的情况 拒绝修改
  2322. if infor.ApplicationStatus != 1 {
  2323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2324. return
  2325. }
  2326. }
  2327. }
  2328. err = service.ModifyExceDoctorAdviceByGroupNoTwo(&advices, groupno, adminUserInfo.Org.Id, patient_id, record_date)
  2329. //记录日志
  2330. byterequest, _ := json.Marshal(advices)
  2331. adviceLog := models.XtDoctorAdviceLog{
  2332. UserOrgId: adminUserInfo.Org.Id,
  2333. PatientId: advices.PatientId,
  2334. AdminUserId: adminUserInfo.AdminUser.Id,
  2335. Module: 1,
  2336. ErrLog: string(byterequest),
  2337. Status: 1,
  2338. Ctime: time.Now().Unix(),
  2339. Mtime: 0,
  2340. Source: "手机端编辑医嘱",
  2341. RecordDate: advices.AdviceDate,
  2342. }
  2343. service.CreateDoctorAdviceLog(adviceLog)
  2344. redis := service.RedisClient()
  2345. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2346. redis.Set(key, "", time.Second)
  2347. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2348. redis.Set(keyOne, "", time.Second)
  2349. defer redis.Close()
  2350. } else {
  2351. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2352. if infor.ID > 0 {
  2353. var cha_time int64
  2354. timeNowStr := time.Now().Format("2006-01-02")
  2355. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2356. //今日的日期减去设置的日期
  2357. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2358. if cha_time >= advices.AdviceDate {
  2359. //查询审核是否允许
  2360. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2361. //申请状态不允许的情况 拒绝修改
  2362. if infor.ApplicationStatus != 1 {
  2363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2364. return
  2365. }
  2366. }
  2367. }
  2368. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  2369. err = service.ModifyExceDoctorAdviceByGroupNoOne(&advices, ids)
  2370. //记录日志
  2371. byterequest, _ := json.Marshal(advices)
  2372. adviceLog := models.XtDoctorAdviceLog{
  2373. UserOrgId: adminUserInfo.Org.Id,
  2374. PatientId: advices.PatientId,
  2375. AdminUserId: adminUserInfo.AdminUser.Id,
  2376. Module: 1,
  2377. ErrLog: string(byterequest),
  2378. Status: 1,
  2379. Ctime: time.Now().Unix(),
  2380. Mtime: 0,
  2381. Source: "手机端编辑执行医嘱",
  2382. RecordDate: advices.AdviceDate,
  2383. }
  2384. service.CreateDoctorAdviceLog(adviceLog)
  2385. redis := service.RedisClient()
  2386. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2387. redis.Set(key, "", time.Second)
  2388. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice_date, 10) + ":advice_list_all"
  2389. redis.Set(keyOne, "", time.Second)
  2390. defer redis.Close()
  2391. }
  2392. //判断是否开启his
  2393. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  2394. //如果开启去修改执行时间
  2395. if config.IsOpen == 1 {
  2396. advicesinfo := models.HisDoctorAdviceInfo{
  2397. ExecutionTime: theTime.Unix(),
  2398. UpdatedTime: time.Now().Unix(),
  2399. }
  2400. var advicehis models.HisDoctorAdviceInfo
  2401. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  2402. //记录日志
  2403. byterequest, _ := json.Marshal(advicesinfo)
  2404. adviceLog := models.XtDoctorAdviceLog{
  2405. UserOrgId: adminUserInfo.Org.Id,
  2406. PatientId: advices.PatientId,
  2407. AdminUserId: adminUserInfo.AdminUser.Id,
  2408. Module: 1,
  2409. ErrLog: string(byterequest),
  2410. Status: 1,
  2411. Ctime: time.Now().Unix(),
  2412. Mtime: 0,
  2413. Source: "手机端his编辑医嘱",
  2414. RecordDate: advices.AdviceDate,
  2415. }
  2416. service.CreateDoctorAdviceLog(adviceLog)
  2417. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  2418. for _, item := range his_advices {
  2419. if item.ExecutionState == 1 {
  2420. advicehis = item
  2421. }
  2422. }
  2423. redis := service.RedisClient()
  2424. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  2425. redis.Set(keyThree, "", time.Second)
  2426. recordDate := theTime.Format("2006-01-02")
  2427. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2428. redis.Set(keyFour, "", time.Second)
  2429. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  2430. redis.Set(keyFive, "", time.Second)
  2431. defer redis.Close()
  2432. project := models.HisPrescriptionProject{
  2433. ExecutionTime: theTime.Unix(),
  2434. Mtime: time.Now().Unix(),
  2435. }
  2436. service.ModifyHisPrescriptionProject(&project, ids)
  2437. //记录日志
  2438. projectquerst, _ := json.Marshal(project)
  2439. projectLog := models.XtDoctorAdviceLog{
  2440. UserOrgId: adminUserInfo.Org.Id,
  2441. PatientId: advices.PatientId,
  2442. AdminUserId: adminUserInfo.AdminUser.Id,
  2443. Module: 1,
  2444. ErrLog: string(projectquerst),
  2445. Status: 1,
  2446. Ctime: time.Now().Unix(),
  2447. Mtime: 0,
  2448. Source: "手机端his编辑项目医嘱",
  2449. RecordDate: advices.AdviceDate,
  2450. }
  2451. service.CreateDoctorAdviceLog(projectLog)
  2452. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  2453. redis.Set(keyEnd, "", time.Second)
  2454. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2455. redis.Set(keyFours, "", time.Second)
  2456. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  2457. redis.Set(keyFives, "", time.Second)
  2458. defer redis.Close()
  2459. }
  2460. if err != nil {
  2461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2462. return
  2463. }
  2464. advice.ExecutionTime = theTime.Unix()
  2465. c.ServeSuccessJSON(map[string]interface{}{
  2466. "msg": "ok",
  2467. "advice": advice,
  2468. "ids": ids,
  2469. })
  2470. return
  2471. }
  2472. func (c *PatientApiController) CheckMobileDoctorAdvice() {
  2473. origin, _ := c.GetInt64("origin", 0)
  2474. record_date, _ := c.GetInt64("record_date")
  2475. patient_id, _ := c.GetInt64("patient_id")
  2476. check_time := c.GetString("check_time")
  2477. if len(check_time) <= 0 {
  2478. utils.ErrorLog("check_time")
  2479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2480. return
  2481. }
  2482. timeLayout2 := "2006-01-02 15:04:05"
  2483. loc, _ := time.LoadLocation("Local")
  2484. theTime, errs := time.ParseInLocation(timeLayout2, check_time, loc)
  2485. fmt.Println("theTimewowowow", theTime)
  2486. if errs != nil {
  2487. utils.ErrorLog(errs.Error())
  2488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2489. return
  2490. }
  2491. if origin != 2 {
  2492. groupno, _ := c.GetInt64("groupno", -1)
  2493. var ids []string
  2494. if groupno == 0 {
  2495. advice_ids := c.GetString("advice_id")
  2496. if advice_ids == "" {
  2497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2498. return
  2499. } else {
  2500. ids = strings.Split(advice_ids, ",")
  2501. if len(ids) <= 0 {
  2502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2503. return
  2504. }
  2505. }
  2506. }
  2507. if groupno < 0 {
  2508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2509. return
  2510. }
  2511. adminUserInfo := c.GetMobileAdminUserInfo()
  2512. var advice models.DoctorAdvice
  2513. if groupno > 0 {
  2514. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2515. for _, item := range advices {
  2516. if item.CheckState == 0 {
  2517. advice = item
  2518. }
  2519. //记录日志
  2520. byterequest, _ := json.Marshal(advices)
  2521. adviceLog := models.XtDoctorAdviceLog{
  2522. UserOrgId: adminUserInfo.Org.Id,
  2523. PatientId: item.PatientId,
  2524. AdminUserId: adminUserInfo.AdminUser.Id,
  2525. Module: 3,
  2526. ErrLog: string(byterequest),
  2527. Status: 1,
  2528. Ctime: time.Now().Unix(),
  2529. Mtime: 0,
  2530. Source: "手机端核对医嘱",
  2531. RecordDate: item.AdviceDate,
  2532. }
  2533. service.CreateDoctorAdviceLog(adviceLog)
  2534. }
  2535. if advice.CheckState == 1 {
  2536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2537. return
  2538. }
  2539. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2541. return
  2542. }
  2543. } else {
  2544. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2545. for _, item := range advices {
  2546. if item.CheckState == 0 {
  2547. advice = item
  2548. }
  2549. //记录日志
  2550. byterequest, _ := json.Marshal(advices)
  2551. adviceLog := models.XtDoctorAdviceLog{
  2552. UserOrgId: adminUserInfo.Org.Id,
  2553. PatientId: item.PatientId,
  2554. AdminUserId: adminUserInfo.AdminUser.Id,
  2555. Module: 3,
  2556. ErrLog: string(byterequest),
  2557. Status: 1,
  2558. Ctime: time.Now().Unix(),
  2559. Mtime: 0,
  2560. Source: "手机端核对医嘱",
  2561. RecordDate: item.AdviceDate,
  2562. }
  2563. service.CreateDoctorAdviceLog(adviceLog)
  2564. }
  2565. if advice.CheckState == 1 {
  2566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2567. return
  2568. }
  2569. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2571. return
  2572. }
  2573. }
  2574. checker := adminUserInfo.AdminUser.Id
  2575. advices := models.DoctorAdvice{
  2576. CheckTime: theTime.Unix(),
  2577. Checker: checker,
  2578. UpdatedTime: time.Now().Unix(),
  2579. }
  2580. fmt.Println("groupnowowowowoowowow", groupno)
  2581. var err error
  2582. if groupno > 0 {
  2583. // 查询信息规挡的设置天数
  2584. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2585. if infor.ID > 0 && infor.WeekDay > 0 {
  2586. var cha_time int64
  2587. timeNowStr := time.Now().Format("2006-01-02")
  2588. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2589. //今日的日期减去设置的日期
  2590. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2591. if cha_time >= record_date {
  2592. //查询审核是否允许
  2593. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  2594. //申请状态不允许的情况 拒绝修改
  2595. if infor.ApplicationStatus != 1 {
  2596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2597. return
  2598. }
  2599. }
  2600. }
  2601. err = service.CheckDoctorAdviceByGroupNoOne(&advices, groupno, adminUserInfo.Org.Id)
  2602. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2603. redis := service.RedisClient()
  2604. //清空key 值
  2605. redis.Set(key, "", time.Second)
  2606. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2607. redis.Set(keyTwo, "", time.Second)
  2608. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2609. redis.Set(keyThree, "", time.Second)
  2610. recordDate := theTime.Format("2006-01-02")
  2611. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2612. redis.Set(keyFour, "", time.Second)
  2613. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2614. redis.Set(keyFive, "", time.Second)
  2615. defer redis.Close()
  2616. } else {
  2617. if len(ids[0]) <= 0 {
  2618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2619. return
  2620. } else {
  2621. //t := time.Now().Format("2006-01-02")/**/
  2622. //timeLayout2 := "2006-01-02"
  2623. //loc, _ := time.LoadLocation("Local")
  2624. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  2625. // 查询信息规挡的设置天数
  2626. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2627. if infor.ID > 0 {
  2628. var cha_time int64
  2629. timeNowStr := time.Now().Format("2006-01-02")
  2630. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2631. //今日的日期减去设置的日期
  2632. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2633. if cha_time >= advices.AdviceDate {
  2634. //查询审核是否允许
  2635. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2636. //申请状态不允许的情况 拒绝修改
  2637. if infor.ApplicationStatus != 1 {
  2638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2639. return
  2640. }
  2641. }
  2642. }
  2643. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  2644. //记录日志
  2645. byterequest, _ := json.Marshal(advices)
  2646. adviceLog := models.XtDoctorAdviceLog{
  2647. UserOrgId: adminUserInfo.Org.Id,
  2648. PatientId: advices.PatientId,
  2649. AdminUserId: advices.Checker,
  2650. Module: 3,
  2651. ErrLog: string(byterequest),
  2652. Status: 1,
  2653. Ctime: time.Now().Unix(),
  2654. Mtime: 0,
  2655. Source: "手机端核对医嘱",
  2656. RecordDate: advices.AdviceDate,
  2657. }
  2658. service.CreateDoctorAdviceLog(adviceLog)
  2659. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2660. redis := service.RedisClient()
  2661. //清空key 值
  2662. redis.Set(key, "", time.Second)
  2663. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2664. redis.Set(keyTwo, "", time.Second)
  2665. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2666. redis.Set(keyThree, "", time.Second)
  2667. recordDate := theTime.Format("2006-01-02")
  2668. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2669. redis.Set(keyFour, "", time.Second)
  2670. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2671. redis.Set(keyFive, "", time.Second)
  2672. defer redis.Close()
  2673. }
  2674. }
  2675. if err != nil {
  2676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2677. return
  2678. }
  2679. advice.Checker = checker
  2680. advice.CheckTime = theTime.Unix()
  2681. advice.CheckState = 1
  2682. c.ServeSuccessJSON(map[string]interface{}{
  2683. "msg": "ok",
  2684. "advice": advice,
  2685. })
  2686. }
  2687. return
  2688. }
  2689. func (c *PatientApiController) CheckDoctorAdvice() {
  2690. origin, _ := c.GetInt64("origin", 0)
  2691. record_date, _ := c.GetInt64("record_date")
  2692. patient_id, _ := c.GetInt64("patient_id")
  2693. if origin != 2 {
  2694. groupno, _ := c.GetInt64("groupno", -1)
  2695. var ids []string
  2696. if groupno == 0 {
  2697. advice_ids := c.GetString("advice_id")
  2698. if advice_ids == "" {
  2699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2700. return
  2701. } else {
  2702. ids = strings.Split(advice_ids, ",")
  2703. if len(ids) <= 0 {
  2704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2705. return
  2706. }
  2707. }
  2708. }
  2709. if groupno < 0 {
  2710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2711. return
  2712. }
  2713. adminUserInfo := c.GetMobileAdminUserInfo()
  2714. var advice models.DoctorAdvice
  2715. if groupno > 0 {
  2716. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2717. for _, item := range advices {
  2718. if item.CheckState == 0 {
  2719. advice = item
  2720. }
  2721. //记录日志
  2722. byterequest, _ := json.Marshal(advices)
  2723. adviceLog := models.XtDoctorAdviceLog{
  2724. UserOrgId: adminUserInfo.Org.Id,
  2725. PatientId: item.PatientId,
  2726. AdminUserId: adminUserInfo.AdminUser.Id,
  2727. Module: 3,
  2728. ErrLog: string(byterequest),
  2729. Status: 1,
  2730. Ctime: time.Now().Unix(),
  2731. Mtime: 0,
  2732. Source: "手机端核对医嘱",
  2733. RecordDate: item.AdviceDate,
  2734. }
  2735. service.CreateDoctorAdviceLog(adviceLog)
  2736. }
  2737. if advice.CheckState == 1 {
  2738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2739. return
  2740. }
  2741. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2743. return
  2744. }
  2745. } else {
  2746. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2747. for _, item := range advices {
  2748. if item.CheckState == 0 {
  2749. advice = item
  2750. }
  2751. //记录日志
  2752. byterequest, _ := json.Marshal(advices)
  2753. adviceLog := models.XtDoctorAdviceLog{
  2754. UserOrgId: adminUserInfo.Org.Id,
  2755. PatientId: item.PatientId,
  2756. AdminUserId: adminUserInfo.AdminUser.Id,
  2757. Module: 3,
  2758. ErrLog: string(byterequest),
  2759. Status: 1,
  2760. Ctime: time.Now().Unix(),
  2761. Mtime: 0,
  2762. Source: "手机端核对医嘱",
  2763. RecordDate: item.AdviceDate,
  2764. }
  2765. service.CreateDoctorAdviceLog(adviceLog)
  2766. }
  2767. if advice.CheckState == 1 {
  2768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2769. return
  2770. }
  2771. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2773. return
  2774. }
  2775. }
  2776. checker := adminUserInfo.AdminUser.Id
  2777. theTime := time.Now()
  2778. advices := models.DoctorAdvice{
  2779. CheckTime: theTime.Unix(),
  2780. Checker: checker,
  2781. UpdatedTime: time.Now().Unix(),
  2782. }
  2783. var err error
  2784. if groupno > 0 {
  2785. // 查询信息规挡的设置天数
  2786. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2787. if infor.ID > 0 && infor.WeekDay > 0 {
  2788. var cha_time int64
  2789. timeNowStr := time.Now().Format("2006-01-02")
  2790. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2791. //今日的日期减去设置的日期
  2792. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2793. if cha_time >= record_date {
  2794. //查询审核是否允许
  2795. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  2796. //申请状态不允许的情况 拒绝修改
  2797. if infor.ApplicationStatus != 1 {
  2798. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2799. return
  2800. }
  2801. }
  2802. }
  2803. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  2804. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2805. redis := service.RedisClient()
  2806. //清空key 值
  2807. redis.Set(key, "", time.Second)
  2808. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2809. redis.Set(keyTwo, "", time.Second)
  2810. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2811. redis.Set(keyThree, "", time.Second)
  2812. recordDate := theTime.Format("2006-01-02")
  2813. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2814. redis.Set(keyFour, "", time.Second)
  2815. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2816. redis.Set(keyFive, "", time.Second)
  2817. defer redis.Close()
  2818. } else {
  2819. if len(ids[0]) <= 0 {
  2820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2821. return
  2822. } else {
  2823. //t := time.Now().Format("2006-01-02")/**/
  2824. //timeLayout2 := "2006-01-02"
  2825. //loc, _ := time.LoadLocation("Local")
  2826. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  2827. // 查询信息规挡的设置天数
  2828. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2829. if infor.ID > 0 {
  2830. var cha_time int64
  2831. timeNowStr := time.Now().Format("2006-01-02")
  2832. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2833. //今日的日期减去设置的日期
  2834. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2835. if cha_time >= advices.AdviceDate {
  2836. //查询审核是否允许
  2837. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2838. //申请状态不允许的情况 拒绝修改
  2839. if infor.ApplicationStatus != 1 {
  2840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2841. return
  2842. }
  2843. }
  2844. }
  2845. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  2846. //记录日志
  2847. byterequest, _ := json.Marshal(advices)
  2848. adviceLog := models.XtDoctorAdviceLog{
  2849. UserOrgId: adminUserInfo.Org.Id,
  2850. PatientId: advices.PatientId,
  2851. AdminUserId: advices.Checker,
  2852. Module: 3,
  2853. ErrLog: string(byterequest),
  2854. Status: 1,
  2855. Ctime: time.Now().Unix(),
  2856. Mtime: 0,
  2857. Source: "手机端核对医嘱",
  2858. RecordDate: advices.AdviceDate,
  2859. }
  2860. service.CreateDoctorAdviceLog(adviceLog)
  2861. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2862. redis := service.RedisClient()
  2863. //清空key 值
  2864. redis.Set(key, "", time.Second)
  2865. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2866. redis.Set(keyTwo, "", time.Second)
  2867. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2868. redis.Set(keyThree, "", time.Second)
  2869. recordDate := theTime.Format("2006-01-02")
  2870. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2871. redis.Set(keyFour, "", time.Second)
  2872. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2873. redis.Set(keyFive, "", time.Second)
  2874. defer redis.Close()
  2875. }
  2876. }
  2877. if err != nil {
  2878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2879. return
  2880. }
  2881. advice.Checker = checker
  2882. advice.CheckTime = theTime.Unix()
  2883. advice.CheckState = 1
  2884. c.ServeSuccessJSON(map[string]interface{}{
  2885. "msg": "ok",
  2886. "advice": advice,
  2887. })
  2888. } else if origin == 2 {
  2889. adminInfo := c.GetMobileAdminUserInfo()
  2890. var ids []string
  2891. advice_ids := c.GetString("advice_id")
  2892. ids = strings.Split(advice_ids, ",")
  2893. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  2894. var err error
  2895. for _, item := range advices {
  2896. if item.CheckState == 1 {
  2897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2898. return
  2899. }
  2900. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  2901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2902. return
  2903. }
  2904. item.Checker = adminInfo.AdminUser.Id
  2905. item.CheckTime = time.Now().Unix()
  2906. item.CheckState = 1
  2907. // 查询信息规挡的设置天数
  2908. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  2909. if infor.ID > 0 {
  2910. var cha_time int64
  2911. timeNowStr := time.Now().Format("2006-01-02")
  2912. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2913. //今日的日期减去设置的日期
  2914. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2915. if cha_time >= record_date {
  2916. //查询审核是否允许
  2917. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminInfo.Org.Id, 4)
  2918. //申请状态不允许的情况 拒绝修改
  2919. if infor.ApplicationStatus != 1 {
  2920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2921. return
  2922. }
  2923. }
  2924. }
  2925. err = service.SaveHisDoctorAdvice(item)
  2926. //记录日志
  2927. byterequest, _ := json.Marshal(advices)
  2928. adviceLog := models.XtDoctorAdviceLog{
  2929. UserOrgId: adminInfo.Org.Id,
  2930. PatientId: item.PatientId,
  2931. AdminUserId: item.Checker,
  2932. Module: 3,
  2933. ErrLog: string(byterequest),
  2934. Status: 1,
  2935. Ctime: time.Now().Unix(),
  2936. Mtime: 0,
  2937. Source: "手机端核对His医嘱",
  2938. RecordDate: item.AdviceDate,
  2939. }
  2940. service.CreateDoctorAdviceLog(adviceLog)
  2941. redis := service.RedisClient()
  2942. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2943. //清空key 值
  2944. redis.Set(key, "", time.Second)
  2945. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2946. redis.Set(keyTwo, "", time.Second)
  2947. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2948. redis.Set(keyThree, "", time.Second)
  2949. theTime := time.Now()
  2950. recordDate := theTime.Format("2006-01-02")
  2951. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  2952. redis.Set(keyFour, "", time.Second)
  2953. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2954. redis.Set(keyFive, "", time.Second)
  2955. defer redis.Close()
  2956. }
  2957. if err == nil {
  2958. c.ServeSuccessJSON(map[string]interface{}{
  2959. "msg": "ok",
  2960. "advice": advices,
  2961. })
  2962. } else {
  2963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2964. return
  2965. }
  2966. }
  2967. return
  2968. }
  2969. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  2970. id, _ := c.GetInt64("patient", 0)
  2971. assessmentDate := c.GetString("assessment_date", "")
  2972. if id <= 0 || len(assessmentDate) != 10 {
  2973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2974. return
  2975. }
  2976. timeLayout := "2006-01-02"
  2977. loc, _ := time.LoadLocation("Local")
  2978. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  2979. if err != nil {
  2980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2981. return
  2982. }
  2983. theAssessmentDateTime := theTime.Unix()
  2984. adminUserInfo := c.GetMobileAdminUserInfo()
  2985. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2986. if patient.ID == 0 {
  2987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2988. return
  2989. }
  2990. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  2991. if getPEErr != nil {
  2992. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  2993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2994. return
  2995. }
  2996. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2997. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2998. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2999. var evaluation models.PredialysisEvaluation
  3000. if theEvaluation != nil {
  3001. evaluation = *theEvaluation
  3002. }
  3003. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  3004. if code > 0 {
  3005. c.ServeFailJSONWithSGJErrorCode(code)
  3006. return
  3007. }
  3008. if theEvaluation == nil {
  3009. evaluation.CreatedTime = time.Now().Unix()
  3010. evaluation.Status = 1
  3011. evaluation.AssessmentDate = theAssessmentDateTime
  3012. evaluation.PatientId = id
  3013. evaluation.UserOrgId = adminUserInfo.Org.Id
  3014. if appRole.UserType == 2 || appRole.UserType == 1 {
  3015. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  3016. evaluation.AssessmentTime = time.Now().Unix()
  3017. } else {
  3018. evaluation.Creater = adminUserInfo.AdminUser.Id
  3019. }
  3020. } else {
  3021. evaluation.UpdatedTime = time.Now().Unix()
  3022. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  3023. if appRole.UserType == 2 || appRole.UserType == 1 {
  3024. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  3025. evaluation.AssessmentTime = time.Now().Unix()
  3026. } else {
  3027. evaluation.Modifier = adminUserInfo.AdminUser.Id
  3028. if evaluation.Creater == 0 {
  3029. evaluation.Creater = adminUserInfo.AdminUser.Id
  3030. }
  3031. }
  3032. }
  3033. //新增逻辑
  3034. var dewater_amount float64
  3035. dewater_amount = 0
  3036. if evaluation.DryWeight > 0 {
  3037. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3038. if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 34 || template.TemplateId == 32 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10551 || adminUserInfo.Org.Id == 10579 || adminUserInfo.Org.Id == 10580 || adminUserInfo.Org.Id == 10585 || adminUserInfo.Org.Id == 10635 || adminUserInfo.Org.Id == 10727 {
  3039. if adminUserInfo.Org.Id != 10551 && adminUserInfo.Org.Id != 10579 && adminUserInfo.Org.Id != 10580 && adminUserInfo.Org.Id != 10585 {
  3040. dewater_amount = dewater_amount * 1000
  3041. }
  3042. }
  3043. if adminUserInfo.Org.Id == 10727 {
  3044. dewater_amount = dewater_amount * 1000
  3045. }
  3046. if dewater_amount <= 0 {
  3047. dewater_amount = 0
  3048. }
  3049. } else {
  3050. dewater_amount = 0
  3051. }
  3052. // 计算透析处方的相关超滤量
  3053. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  3054. lastDialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient.ID, adminUserInfo.Org.Id)
  3055. var lastDialysisPrescribe *models.DialysisPrescription
  3056. var dialysisSolution *models.DialysisSolution
  3057. var dialysisPrescribe *models.DialysisPrescription
  3058. var system_dialysisPrescribe *models.SystemPrescription
  3059. var mode_id int64
  3060. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  3061. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  3062. if schedual != nil {
  3063. // 获取透析模版
  3064. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  3065. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  3066. mode_id = schedual.ModeId
  3067. } else {
  3068. // 获取透析模版
  3069. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  3070. if dialysisPrescribe == nil && dialysisSolution != nil {
  3071. mode_id = dialysisSolution.ModeId
  3072. }
  3073. if dialysisPrescribe == nil && dialysisSolution == nil {
  3074. mode_id = 0
  3075. }
  3076. }
  3077. // 插入透析处方
  3078. if dialysisPrescribe == nil && dialysisSolution != nil {
  3079. var newprescribe models.DialysisPrescription
  3080. newprescribe.UserOrgId = adminUserInfo.Org.Id
  3081. newprescribe.PatientId = id
  3082. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  3083. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  3084. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  3085. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  3086. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  3087. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  3088. newprescribe.ModeId = dialysisSolution.ModeId
  3089. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  3090. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  3091. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  3092. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  3093. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  3094. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  3095. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  3096. newprescribe.Glucose = dialysisSolution.Glucose
  3097. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  3098. newprescribe.Kalium = dialysisSolution.Kalium
  3099. newprescribe.Sodium = dialysisSolution.Sodium
  3100. newprescribe.Calcium = dialysisSolution.Calcium
  3101. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  3102. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  3103. newprescribe.Conductivity = dialysisSolution.Conductivity
  3104. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  3105. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  3106. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  3107. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  3108. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  3109. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  3110. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  3111. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  3112. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  3113. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  3114. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  3115. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  3116. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  3117. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  3118. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  3119. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  3120. newprescribe.CreatedTime = time.Now().Unix()
  3121. newprescribe.UpdatedTime = time.Now().Unix()
  3122. newprescribe.RecordDate = theAssessmentDateTime
  3123. newprescribe.DewaterAmount = dewater_amount
  3124. newprescribe.TargetUltrafiltration = dewater_amount
  3125. newprescribe.PrescriptionWater = dewater_amount
  3126. newprescribe.Status = 1
  3127. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  3128. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  3129. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  3130. newprescribe.Remark = lastDialysisPrescription.Remark
  3131. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  3132. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  3133. newprescribe.ID = dialysisPrescription.ID
  3134. if dialysisPrescription.ID == 0 {
  3135. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  3136. newprescribe.Sodium = 138
  3137. newprescribe.Bicarbonate = 31.1
  3138. newprescribe.DialysateFlow = 500
  3139. newprescribe.PrescribingNumber = 1
  3140. }
  3141. if adminUserInfo.Org.Id == 10579 {
  3142. newprescribe.Modifier = 0
  3143. newprescribe.Creater = 0
  3144. newprescribe.PrescriptionDoctor = 0
  3145. }
  3146. err := service.AddSigleRecord(&newprescribe)
  3147. //记录日志
  3148. byterequest, _ := json.Marshal(newprescribe)
  3149. prescriptionLog := models.XtDialysisPrescriptionLog{
  3150. UserOrgId: adminUserInfo.Org.Id,
  3151. Ctime: time.Now().Unix(),
  3152. Mtime: 0,
  3153. ErrLog: string(byterequest),
  3154. AdminUserId: adminUserInfo.AdminUser.Id,
  3155. RecordDate: newprescribe.RecordDate,
  3156. PatientId: id,
  3157. Source: "手机端新增透前评估插入处方",
  3158. Status: 1,
  3159. }
  3160. service.CreatePrescriptionLog(prescriptionLog)
  3161. //获取key,清空redis
  3162. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3163. redis := service.RedisClient()
  3164. //清空key 值
  3165. redis.Set(key, "", time.Second)
  3166. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3167. //清空key 值
  3168. redis.Set(keyOne, "", time.Second)
  3169. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3170. //清空key 值
  3171. redis.Set(keyTwo, "", time.Second)
  3172. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3173. redis.Set(keySix, "", time.Second)
  3174. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3175. redis.Set(keySeven, "", time.Second)
  3176. if err != nil {
  3177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3178. }
  3179. } else {
  3180. if adminUserInfo.Org.Id == 10340 {
  3181. newprescribe.Sodium = 138
  3182. newprescribe.Bicarbonate = 31.1
  3183. newprescribe.DialysateFlow = 500
  3184. }
  3185. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3186. //
  3187. if appRole.UserType == 2 || appRole.UserType == 1 {
  3188. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3189. if adminUserInfo.Org.Id == 9882 {
  3190. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3191. }
  3192. }
  3193. err := service.UpDateDialysisPrescription(&newprescribe)
  3194. //记录日志
  3195. byterequest, _ := json.Marshal(newprescribe)
  3196. prescriptionLog := models.XtDialysisPrescriptionLog{
  3197. UserOrgId: adminUserInfo.Org.Id,
  3198. Ctime: time.Now().Unix(),
  3199. Mtime: 0,
  3200. ErrLog: string(byterequest),
  3201. AdminUserId: adminUserInfo.AdminUser.Id,
  3202. RecordDate: newprescribe.RecordDate,
  3203. PatientId: id,
  3204. Source: "手机端新增透前评估插入处方",
  3205. Status: 1,
  3206. }
  3207. service.CreatePrescriptionLog(prescriptionLog)
  3208. //获取key,清空redis
  3209. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3210. redis := service.RedisClient()
  3211. //清空key 值
  3212. redis.Set(key, "", time.Second)
  3213. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3214. //清空key 值
  3215. redis.Set(keyOne, "", time.Second)
  3216. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3217. //清空key 值
  3218. redis.Set(keyTwo, "", time.Second)
  3219. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3220. redis.Set(keySix, "", time.Second)
  3221. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3222. redis.Set(keySeven, "", time.Second)
  3223. if err != nil {
  3224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3225. }
  3226. }
  3227. }
  3228. if dialysisPrescribe == nil && dialysisSolution == nil {
  3229. if lastDialysisPrescribe != nil {
  3230. var newprescribe models.DialysisPrescription
  3231. newprescribe.UserOrgId = adminUserInfo.Org.Id
  3232. newprescribe.PatientId = id
  3233. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  3234. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  3235. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  3236. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  3237. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  3238. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  3239. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  3240. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  3241. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  3242. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  3243. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  3244. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  3245. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  3246. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  3247. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  3248. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  3249. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  3250. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  3251. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  3252. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  3253. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  3254. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  3255. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  3256. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  3257. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  3258. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  3259. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  3260. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  3261. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  3262. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  3263. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  3264. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  3265. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  3266. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  3267. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  3268. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  3269. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  3270. newprescribe.CreatedTime = time.Now().Unix()
  3271. newprescribe.UpdatedTime = time.Now().Unix()
  3272. newprescribe.RecordDate = theAssessmentDateTime
  3273. newprescribe.DewaterAmount = dewater_amount
  3274. newprescribe.TargetUltrafiltration = dewater_amount
  3275. newprescribe.PrescriptionWater = dewater_amount
  3276. newprescribe.Status = 1
  3277. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  3278. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  3279. if dialysisSolution != nil && dialysisSolution.DialysisStrainer != "" {
  3280. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  3281. }
  3282. newprescribe.Remark = lastDialysisPrescription.Remark
  3283. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  3284. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  3285. newprescribe.ID = dialysisPrescription.ID
  3286. if dialysisPrescription.ID == 0 {
  3287. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  3288. newprescribe.Sodium = 138
  3289. newprescribe.Bicarbonate = 31.1
  3290. newprescribe.DialysateFlow = 500
  3291. }
  3292. if adminUserInfo.Org.Id == 10579 {
  3293. newprescribe.Modifier = 0
  3294. newprescribe.Creater = 0
  3295. newprescribe.PrescriptionDoctor = 0
  3296. }
  3297. err := service.AddSigleRecord(&newprescribe)
  3298. //记录日志
  3299. byterequest, _ := json.Marshal(newprescribe)
  3300. prescriptionLog := models.XtDialysisPrescriptionLog{
  3301. UserOrgId: adminUserInfo.Org.Id,
  3302. Ctime: time.Now().Unix(),
  3303. Mtime: 0,
  3304. ErrLog: string(byterequest),
  3305. AdminUserId: adminUserInfo.AdminUser.Id,
  3306. RecordDate: newprescribe.RecordDate,
  3307. PatientId: id,
  3308. Source: "手机端新增透前评估插入处方",
  3309. Status: 1,
  3310. }
  3311. service.CreatePrescriptionLog(prescriptionLog)
  3312. //获取key,清空redis
  3313. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3314. redis := service.RedisClient()
  3315. //清空key 值
  3316. redis.Set(key, "", time.Second)
  3317. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3318. //清空key 值
  3319. redis.Set(keyOne, "", time.Second)
  3320. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3321. //清空key 值
  3322. redis.Set(keyTwo, "", time.Second)
  3323. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3324. redis.Set(keySix, "", time.Second)
  3325. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3326. redis.Set(keySeven, "", time.Second)
  3327. if err != nil {
  3328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3329. }
  3330. } else {
  3331. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3332. //
  3333. if appRole.UserType == 2 || appRole.UserType == 1 {
  3334. if adminUserInfo.Org.Id == 10579 {
  3335. newprescribe.Modifier = 0
  3336. newprescribe.Creater = 0
  3337. newprescribe.PrescriptionDoctor = 0
  3338. } else {
  3339. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3340. }
  3341. if adminUserInfo.Org.Id == 9882 {
  3342. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3343. }
  3344. }
  3345. err := service.UpDateDialysisPrescription(&newprescribe)
  3346. //记录日志
  3347. byterequest, _ := json.Marshal(newprescribe)
  3348. prescriptionLog := models.XtDialysisPrescriptionLog{
  3349. UserOrgId: adminUserInfo.Org.Id,
  3350. Ctime: time.Now().Unix(),
  3351. Mtime: 0,
  3352. ErrLog: string(byterequest),
  3353. AdminUserId: adminUserInfo.AdminUser.Id,
  3354. RecordDate: newprescribe.RecordDate,
  3355. PatientId: id,
  3356. Source: "手机端新增透前评估插入处方",
  3357. Status: 1,
  3358. }
  3359. service.CreatePrescriptionLog(prescriptionLog)
  3360. //获取key,清空redis
  3361. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3362. redis := service.RedisClient()
  3363. //清空key 值
  3364. redis.Set(key, "", time.Second)
  3365. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3366. //清空key 值
  3367. redis.Set(keyOne, "", time.Second)
  3368. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3369. //清空key 值
  3370. redis.Set(keyTwo, "", time.Second)
  3371. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3372. redis.Set(keySix, "", time.Second)
  3373. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3374. redis.Set(keySeven, "", time.Second)
  3375. if err != nil {
  3376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3377. }
  3378. }
  3379. if err != nil {
  3380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3381. }
  3382. } else if system_dialysisPrescribe != nil {
  3383. var newprescribe models.DialysisPrescription
  3384. newprescribe.UserOrgId = adminUserInfo.Org.Id
  3385. newprescribe.PatientId = id
  3386. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  3387. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  3388. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  3389. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  3390. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  3391. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  3392. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  3393. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  3394. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  3395. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  3396. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  3397. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  3398. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  3399. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  3400. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  3401. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  3402. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  3403. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  3404. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  3405. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  3406. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  3407. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  3408. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  3409. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  3410. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  3411. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  3412. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  3413. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  3414. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  3415. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  3416. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  3417. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  3418. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  3419. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  3420. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  3421. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  3422. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  3423. newprescribe.CreatedTime = time.Now().Unix()
  3424. newprescribe.UpdatedTime = time.Now().Unix()
  3425. newprescribe.RecordDate = theAssessmentDateTime
  3426. newprescribe.DewaterAmount = dewater_amount
  3427. newprescribe.TargetUltrafiltration = dewater_amount
  3428. newprescribe.PrescriptionWater = dewater_amount
  3429. newprescribe.Status = 1
  3430. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  3431. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  3432. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  3433. newprescribe.Remark = lastDialysisPrescription.Remark
  3434. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  3435. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  3436. newprescribe.ID = dialysisPrescription.ID
  3437. if dialysisPrescription.ID == 0 {
  3438. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  3439. newprescribe.Sodium = 138
  3440. newprescribe.Bicarbonate = 31.1
  3441. newprescribe.DialysateFlow = 500
  3442. }
  3443. if adminUserInfo.Org.Id == 10579 {
  3444. newprescribe.Modifier = 0
  3445. newprescribe.Creater = 0
  3446. newprescribe.PrescriptionDoctor = 0
  3447. }
  3448. err := service.AddSigleRecord(&newprescribe)
  3449. //记录日志
  3450. byterequest, _ := json.Marshal(newprescribe)
  3451. prescriptionLog := models.XtDialysisPrescriptionLog{
  3452. UserOrgId: adminUserInfo.Org.Id,
  3453. Ctime: time.Now().Unix(),
  3454. Mtime: 0,
  3455. ErrLog: string(byterequest),
  3456. AdminUserId: adminUserInfo.AdminUser.Id,
  3457. RecordDate: newprescribe.RecordDate,
  3458. PatientId: id,
  3459. Source: "手机端新增透前评估插入处方",
  3460. Status: 1,
  3461. }
  3462. service.CreatePrescriptionLog(prescriptionLog)
  3463. //获取key,清空redis
  3464. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3465. redis := service.RedisClient()
  3466. //清空key 值
  3467. redis.Set(key, "", time.Second)
  3468. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3469. //清空key 值
  3470. redis.Set(keyOne, "", time.Second)
  3471. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3472. //清空key 值
  3473. redis.Set(keyTwo, "", time.Second)
  3474. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3475. redis.Set(keySix, "", time.Second)
  3476. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3477. redis.Set(keySeven, "", time.Second)
  3478. if err != nil {
  3479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3480. }
  3481. } else {
  3482. if adminUserInfo.Org.Id == 10340 {
  3483. newprescribe.Sodium = 138
  3484. newprescribe.Bicarbonate = 31.1
  3485. newprescribe.DialysateFlow = 500
  3486. }
  3487. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3488. //
  3489. if appRole.UserType == 2 || appRole.UserType == 1 {
  3490. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3491. if adminUserInfo.Org.Id == 9882 {
  3492. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3493. }
  3494. }
  3495. err := service.UpDateDialysisPrescription(&newprescribe)
  3496. //记录日志
  3497. byterequest, _ := json.Marshal(newprescribe)
  3498. prescriptionLog := models.XtDialysisPrescriptionLog{
  3499. UserOrgId: adminUserInfo.Org.Id,
  3500. Ctime: time.Now().Unix(),
  3501. Mtime: 0,
  3502. ErrLog: string(byterequest),
  3503. AdminUserId: adminUserInfo.AdminUser.Id,
  3504. RecordDate: newprescribe.RecordDate,
  3505. PatientId: id,
  3506. Source: "手机端新增透前评估插入处方",
  3507. Status: 1,
  3508. }
  3509. service.CreatePrescriptionLog(prescriptionLog)
  3510. //获取key,清空redis
  3511. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3512. redis := service.RedisClient()
  3513. //清空key 值
  3514. redis.Set(key, "", time.Second)
  3515. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3516. //清空key 值
  3517. redis.Set(keyOne, "", time.Second)
  3518. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3519. //清空key 值
  3520. redis.Set(keyTwo, "", time.Second)
  3521. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3522. redis.Set(keySix, "", time.Second)
  3523. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3524. redis.Set(keySeven, "", time.Second)
  3525. if err != nil {
  3526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3527. }
  3528. }
  3529. if err != nil {
  3530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3531. }
  3532. } else {
  3533. var newprescribe models.DialysisPrescription
  3534. newprescribe.UserOrgId = adminUserInfo.Org.Id
  3535. newprescribe.PatientId = id
  3536. newprescribe.ModeId = mode_id
  3537. newprescribe.CreatedTime = time.Now().Unix()
  3538. newprescribe.UpdatedTime = time.Now().Unix()
  3539. newprescribe.RecordDate = theAssessmentDateTime
  3540. newprescribe.DewaterAmount = dewater_amount
  3541. newprescribe.TargetUltrafiltration = dewater_amount
  3542. newprescribe.Status = 1
  3543. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  3544. if dialysisPrescription.ID > 0 {
  3545. newprescribe.ID = dialysisPrescription.ID
  3546. }
  3547. if dialysisPrescription.ID == 0 {
  3548. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10679 {
  3549. newprescribe.Sodium = 138
  3550. newprescribe.Bicarbonate = 31.1
  3551. newprescribe.DialysateFlow = 500
  3552. }
  3553. if adminUserInfo.Org.Id == 10579 {
  3554. newprescribe.Modifier = 0
  3555. newprescribe.Creater = 0
  3556. newprescribe.PrescriptionDoctor = 0
  3557. }
  3558. err := service.AddSigleRecord(&newprescribe)
  3559. //获取key,清空redis
  3560. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3561. redis := service.RedisClient()
  3562. //清空key 值
  3563. redis.Set(key, "", time.Second)
  3564. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3565. //清空key 值
  3566. redis.Set(keyOne, "", time.Second)
  3567. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3568. //清空key 值
  3569. redis.Set(keyTwo, "", time.Second)
  3570. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3571. redis.Set(keySix, "", time.Second)
  3572. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3573. redis.Set(keySeven, "", time.Second)
  3574. if err != nil {
  3575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3576. }
  3577. } else {
  3578. if adminUserInfo.Org.Id == 10340 {
  3579. newprescribe.Sodium = 138
  3580. newprescribe.Bicarbonate = 31.1
  3581. newprescribe.DialysateFlow = 500
  3582. }
  3583. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3584. //
  3585. if appRole.UserType == 2 || appRole.UserType == 1 {
  3586. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3587. if adminUserInfo.Org.Id == 9882 {
  3588. newprescribe.Creater = adminUserInfo.AdminUser.Id
  3589. }
  3590. }
  3591. if adminUserInfo.Org.Id == 10579 {
  3592. newprescribe.Modifier = 0
  3593. newprescribe.Creater = 0
  3594. newprescribe.PrescriptionDoctor = 0
  3595. }
  3596. err := service.UpDateDialysisPrescription(&newprescribe)
  3597. //记录日志
  3598. byterequest, _ := json.Marshal(newprescribe)
  3599. prescriptionLog := models.XtDialysisPrescriptionLog{
  3600. UserOrgId: adminUserInfo.Org.Id,
  3601. Ctime: time.Now().Unix(),
  3602. Mtime: 0,
  3603. ErrLog: string(byterequest),
  3604. AdminUserId: adminUserInfo.AdminUser.Id,
  3605. RecordDate: newprescribe.RecordDate,
  3606. PatientId: id,
  3607. Source: "手机端新增透前评估插入处方",
  3608. Status: 1,
  3609. }
  3610. service.CreatePrescriptionLog(prescriptionLog)
  3611. //获取key,清空redis
  3612. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3613. redis := service.RedisClient()
  3614. //清空key 值
  3615. redis.Set(key, "", time.Second)
  3616. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3617. //清空key 值
  3618. redis.Set(keyOne, "", time.Second)
  3619. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3620. //清空key 值
  3621. redis.Set(keyTwo, "", time.Second)
  3622. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3623. redis.Set(keySix, "", time.Second)
  3624. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3625. redis.Set(keySeven, "", time.Second)
  3626. if err != nil {
  3627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3628. }
  3629. }
  3630. if err != nil {
  3631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3632. }
  3633. }
  3634. }
  3635. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  3636. // if dialysisPrescribe != nil {
  3637. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  3638. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  3639. // dialysisPrescribe.DewaterAmount = dewater_amount
  3640. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  3641. // dialysisPrescribe.Status = 1
  3642. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  3643. // if updateErr != nil {
  3644. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3645. // }
  3646. // }
  3647. // 查询信息规挡的设置天数
  3648. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3649. if infor.ID > 0 && infor.WeekDay > 0 {
  3650. var cha_time int64
  3651. timeNowStr := time.Now().Format("2006-01-02")
  3652. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3653. //今日的日期减去设置的日期
  3654. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3655. if cha_time >= evaluation.AssessmentDate {
  3656. //查询审核是否允许
  3657. infor, _ := service.GetDialysisInformationByRecordDate(id, evaluation.AssessmentDate, adminUserInfo.Org.Id, 3)
  3658. //申请状态不允许的情况 拒绝修改
  3659. if infor.ApplicationStatus != 1 {
  3660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3661. return
  3662. }
  3663. }
  3664. }
  3665. //针对长沙南雅的问题
  3666. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10164 {
  3667. if len(evaluation.SymptomBeforeDialysis) == 0 {
  3668. predialysisEvaluation, _ := service.GetPredialysisEvaluation(id, adminUserInfo.Org.Id)
  3669. evaluation.SymptomBeforeDialysis = predialysisEvaluation.SymptomBeforeDialysis
  3670. }
  3671. }
  3672. //针对孝昌康桥超滤率计算问题
  3673. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10635 || adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10726 || adminUserInfo.Org.Id == 10164 {
  3674. if evaluation.ID == 0 {
  3675. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  3676. if dialysisPrescribeOne.ID > 0 && evaluation.ID > 0 {
  3677. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3678. service.UpdateMobileGetDialysisPrescribe(dialysisPrescribeOne.ID, dewater_amount)
  3679. }
  3680. }
  3681. if evaluation.ID > 0 {
  3682. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  3683. if dialysisPrescribeOne.ID > 0 && evaluation.ID > 0 {
  3684. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3685. service.UpdateMobileGetDialysisPrescribeOne(dialysisPrescribeOne.ID, dewater_amount)
  3686. }
  3687. }
  3688. }
  3689. //古镇乐生
  3690. if adminUserInfo.Org.Id == 10731 {
  3691. if evaluation.ID == 0 {
  3692. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  3693. if dialysisPrescribeOne.ID > 0 && evaluation.ID > 0 {
  3694. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3695. dewater_amount = dewater_amount * 1000
  3696. service.UpdateMobileGetDialysisPrescribe(dialysisPrescribeOne.ID, dewater_amount)
  3697. }
  3698. }
  3699. if evaluation.ID > 0 {
  3700. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  3701. if dialysisPrescribeOne.ID > 0 && evaluation.ID > 0 {
  3702. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3703. dewater_amount = dewater_amount * 1000
  3704. service.UpdateMobileGetDialysisPrescribeOne(dialysisPrescribeOne.ID, dewater_amount)
  3705. }
  3706. }
  3707. }
  3708. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3709. prescription, _ := service.GetTodayPrescription(id, adminUserInfo.Org.Id, theAssessmentDateTime)
  3710. if prescription.ID > 0 {
  3711. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  3712. if len(monitorList) > 0 {
  3713. var ultrafiltration_rate float64
  3714. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3715. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  3716. var replacement_rate float64
  3717. //乘10 除10是为了保留一位小数
  3718. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3719. var firstOpeateTime = monitorList[0].OperateTime
  3720. for _, item := range monitorList {
  3721. //超滤率
  3722. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  3723. //置换率
  3724. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  3725. //超滤量
  3726. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  3727. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  3728. //置换量
  3729. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  3730. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  3731. }
  3732. }
  3733. }
  3734. }
  3735. //揭阳
  3736. if adminUserInfo.Org.Id == 10597 {
  3737. if evaluation.ID == 0 {
  3738. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  3739. if dialysisPrescribeOne.ID > 0 && evaluation.ID > 0 {
  3740. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3741. service.UpdateMobileGetDialysisPrescribe(dialysisPrescribeOne.ID, dewater_amount)
  3742. }
  3743. }
  3744. }
  3745. err = service.UpadatePredialysisEvaluation(&evaluation)
  3746. //记录日志
  3747. byterequest, _ := json.Marshal(evaluation)
  3748. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  3749. UserOrgId: evaluation.UserOrgId,
  3750. AdminUserId: adminUserInfo.AdminUser.Id,
  3751. ErrLog: string(byterequest),
  3752. PatientId: evaluation.PatientId,
  3753. RecordDate: evaluation.AssessmentDate,
  3754. Ctime: time.Now().Unix(),
  3755. Mtime: 0,
  3756. Status: 1,
  3757. Source: "手机端保存透前评估",
  3758. }
  3759. service.CreateBeforLog(beforeDislysisLog)
  3760. finish := models.XtDialysisFinish{
  3761. IsFinish: 1,
  3762. UserOrgId: adminUserInfo.Org.Id,
  3763. Status: 1,
  3764. Ctime: time.Now().Unix(),
  3765. Mtime: 0,
  3766. Module: 3,
  3767. RecordDate: evaluation.AssessmentDate,
  3768. Sourse: 1,
  3769. PatientId: id,
  3770. }
  3771. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, evaluation.AssessmentDate, 3, id)
  3772. if dialysisFinish.ID == 0 {
  3773. service.CreateDialysisFinish(finish)
  3774. }
  3775. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  3776. redis := service.RedisClient()
  3777. defer redis.Close()
  3778. //清空key 值
  3779. redis.Set(key, "", time.Second)
  3780. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  3781. redis.Set(keyOne, "", time.Second)
  3782. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3783. redis.Set(keyTwo, "", time.Second)
  3784. if err != nil {
  3785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  3786. return
  3787. }
  3788. c.ServeSuccessJSON(map[string]interface{}{
  3789. "msg": "ok",
  3790. "evaluation": evaluation,
  3791. })
  3792. return
  3793. }
  3794. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3795. dataBody := make(map[string]interface{}, 0)
  3796. err := json.Unmarshal(data, &dataBody)
  3797. utils.InfoLog(string(data))
  3798. if err != nil {
  3799. utils.ErrorLog(err.Error())
  3800. code = enums.ErrorCodeParamWrong
  3801. return
  3802. }
  3803. // if method == "create" {
  3804. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  3805. utils.ErrorLog("mode")
  3806. code = enums.ErrorCodeParamWrong
  3807. return
  3808. }
  3809. mode := int64(dataBody["mode"].(float64))
  3810. if mode <= 0 {
  3811. utils.ErrorLog("mode <= 0")
  3812. code = enums.ErrorCodeParamWrong
  3813. return
  3814. }
  3815. solution.ModeId = mode
  3816. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  3817. utils.ErrorLog("mode_name")
  3818. code = enums.ErrorCodeParamWrong
  3819. return
  3820. }
  3821. modeName, _ := dataBody["mode_name"].(string)
  3822. if len(modeName) == 0 {
  3823. utils.ErrorLog("len(mode_name) == 0")
  3824. code = enums.ErrorCodeParamWrong
  3825. return
  3826. }
  3827. solution.ModeName = modeName
  3828. solution.Name = modeName
  3829. // }
  3830. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3831. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3832. solution.DialysisDuration = dialysisDuration
  3833. }
  3834. if dataBody["dialysis_duration"] != nil {
  3835. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3836. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3837. solution.DialysisDuration = dialysisDuration
  3838. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  3839. dialysisDuration := dataBody["dialysis_duration"].(float64)
  3840. solution.DialysisDuration = dialysisDuration
  3841. }
  3842. }
  3843. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  3844. dialyzer := int64(dataBody["dialyzer"].(float64))
  3845. solution.Dialyzer = dialyzer
  3846. }
  3847. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3848. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3849. solution.PerfusionApparatus = perfusionApparatus
  3850. }
  3851. if dataBody["blood_flow_volume"] != nil {
  3852. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3853. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3854. solution.BloodFlowVolume = bloodFlowVolume
  3855. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  3856. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  3857. solution.BloodFlowVolume = bloodFlowVolume
  3858. }
  3859. }
  3860. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3861. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3862. solution.HemodialysisMachine = hemodialysisMachine
  3863. }
  3864. if dataBody["dewater"] != nil {
  3865. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  3866. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  3867. solution.Dewater = dewater
  3868. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  3869. dewater := dataBody["dewater"].(float64)
  3870. solution.Dewater = dewater
  3871. }
  3872. }
  3873. if dataBody["replacement_total"] != nil {
  3874. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  3875. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  3876. solution.ReplacementTotal = replacementTotal
  3877. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  3878. replacementTotal := dataBody["replacement_total"].(float64)
  3879. solution.ReplacementTotal = replacementTotal
  3880. }
  3881. }
  3882. if dataBody["displace_liqui"] != nil {
  3883. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  3884. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  3885. solution.DisplaceLiqui = displaceLiqui
  3886. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  3887. displaceLiqui := dataBody["displace_liqui"].(float64)
  3888. solution.DisplaceLiqui = displaceLiqui
  3889. }
  3890. }
  3891. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3892. replacementWay := int64(dataBody["replacement_way"].(float64))
  3893. solution.ReplacementWay = replacementWay
  3894. }
  3895. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3896. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3897. solution.Anticoagulant = anticoagulant
  3898. }
  3899. if dataBody["anticoagulant_shouji"] != nil {
  3900. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3901. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3902. solution.AnticoagulantShouji = anticoagulantShouji
  3903. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  3904. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  3905. solution.AnticoagulantShouji = anticoagulantShouji
  3906. }
  3907. }
  3908. if dataBody["anticoagulant_weichi"] != nil {
  3909. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3910. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3911. solution.AnticoagulantWeichi = anticoagulantWeichi
  3912. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  3913. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  3914. solution.AnticoagulantWeichi = anticoagulantWeichi
  3915. }
  3916. }
  3917. if dataBody["anticoagulant_zongliang"] != nil {
  3918. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3919. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3920. solution.AnticoagulantZongliang = anticoagulantZongliang
  3921. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  3922. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  3923. solution.AnticoagulantZongliang = anticoagulantZongliang
  3924. }
  3925. }
  3926. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3927. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3928. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3929. }
  3930. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3931. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3932. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3933. }
  3934. if dataBody["kalium"] != nil {
  3935. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3936. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3937. solution.Kalium = kalium
  3938. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  3939. kalium := dataBody["kalium"].(float64)
  3940. solution.Kalium = kalium
  3941. }
  3942. }
  3943. if dataBody["sodium"] != nil {
  3944. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3945. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3946. solution.Sodium = sodium
  3947. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  3948. sodium := dataBody["sodium"].(float64)
  3949. solution.Sodium = sodium
  3950. }
  3951. }
  3952. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3953. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3954. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3955. solution.Calcium = calcium
  3956. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  3957. calcium := dataBody["calcium"].(float64)
  3958. solution.Calcium = calcium
  3959. }
  3960. }
  3961. if dataBody["bicarbonate"] != nil {
  3962. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3963. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3964. solution.Bicarbonate = bicarbonate
  3965. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  3966. bicarbonate := dataBody["bicarbonate"].(float64)
  3967. solution.Bicarbonate = bicarbonate
  3968. }
  3969. }
  3970. if dataBody["glucose"] != nil {
  3971. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  3972. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  3973. solution.Glucose = glucose
  3974. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  3975. glucose := dataBody["glucose"].(float64)
  3976. solution.Glucose = glucose
  3977. }
  3978. }
  3979. // if dataBody["dry_weight"] != nil {
  3980. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3981. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3982. // solution.DryWeight = dryWeight
  3983. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  3984. // dryWeight := dataBody["dry_weight"].(float64)
  3985. // solution.DryWeight = dryWeight
  3986. // }
  3987. // }
  3988. if dataBody["dialysate_flow"] != nil {
  3989. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3990. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3991. solution.DialysateFlow = dialysateFlow
  3992. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  3993. dialysateFlow := dataBody["dialysate_flow"].(float64)
  3994. solution.DialysateFlow = dialysateFlow
  3995. }
  3996. }
  3997. if dataBody["dialysate_temperature"] != nil {
  3998. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  3999. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  4000. solution.DialysateTemperature = dialysateTemperature
  4001. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  4002. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  4003. solution.DialysateTemperature = dialysateTemperature
  4004. }
  4005. }
  4006. if dataBody["conductivity"] != nil {
  4007. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  4008. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  4009. solution.Conductivity = conductivity
  4010. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  4011. conductivity := dataBody["conductivity"].(float64)
  4012. solution.Conductivity = conductivity
  4013. }
  4014. }
  4015. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4016. remark := dataBody["remark"].(string)
  4017. solution.Remark = remark
  4018. }
  4019. if dataBody["dialysis_duration_hour"] != nil {
  4020. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  4021. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  4022. solution.DialysisDurationHour = dialysisDurationHour
  4023. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  4024. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  4025. solution.DialysisDurationHour = int64(dialysisDurationHour)
  4026. }
  4027. }
  4028. if dataBody["dialysis_duration_minute"] != nil {
  4029. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  4030. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  4031. solution.DialysisDurationMinute = dialysisDurationMinute
  4032. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  4033. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  4034. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  4035. }
  4036. }
  4037. if dataBody["target_ultrafiltration"] != nil {
  4038. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  4039. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  4040. solution.TargetUltrafiltration = targetUltrafiltration
  4041. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  4042. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  4043. solution.TargetUltrafiltration = targetUltrafiltration
  4044. }
  4045. }
  4046. if dataBody["dialysate_formulation"] != nil {
  4047. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  4048. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  4049. solution.DialysateFormulation = dialysateFormulation
  4050. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  4051. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  4052. solution.DialysateFormulation = int64(dialysateFormulation)
  4053. }
  4054. }
  4055. return
  4056. }
  4057. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  4058. dataBody := make(map[string]interface{}, 0)
  4059. err := json.Unmarshal(data, &dataBody)
  4060. utils.InfoLog(string(data))
  4061. if err != nil {
  4062. utils.ErrorLog(err.Error())
  4063. code = enums.ErrorCodeParamWrong
  4064. return
  4065. }
  4066. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  4067. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  4068. evaluation.WeightBefore = weightVefore
  4069. }
  4070. // fmt.Println(dataBody["dry_weight"])
  4071. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  4072. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  4073. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  4074. fmt.Println(additionalWeight)
  4075. evaluation.DryWeight = additionalWeight
  4076. }
  4077. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  4078. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  4079. fmt.Println(additionalWeight)
  4080. evaluation.AdditionalWeight = additionalWeight
  4081. }
  4082. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  4083. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  4084. evaluation.Temperature = Temperature
  4085. }
  4086. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  4087. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  4088. evaluation.SystolicBloodPressure = systolicBloodPressure
  4089. }
  4090. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  4091. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  4092. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  4093. }
  4094. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  4095. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  4096. evaluation.PulseFrequency = pulseFrequency
  4097. }
  4098. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  4099. breathingRate := dataBody["breathing_rate"].(string)
  4100. evaluation.BreathingRate = breathingRate
  4101. }
  4102. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  4103. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  4104. evaluation.LastPostDialysis = lastPostDialysis
  4105. }
  4106. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  4107. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  4108. evaluation.DialysisInterphase = dialysisInterphase
  4109. }
  4110. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  4111. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  4112. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  4113. }
  4114. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  4115. catheter, _ := dataBody["catheter"].(string)
  4116. evaluation.Catheter = catheter
  4117. }
  4118. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  4119. catheter_bend := int(dataBody["catheter_bend"].(float64))
  4120. evaluation.CatheterBend = catheter_bend
  4121. }
  4122. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  4123. Complication, _ := dataBody["complication"].(string)
  4124. evaluation.Complication = Complication
  4125. }
  4126. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4127. remark := dataBody["remark"].(string)
  4128. evaluation.Remark = remark
  4129. }
  4130. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  4131. machine_type := dataBody["machine_type"].(string)
  4132. evaluation.MachineType = machine_type
  4133. }
  4134. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  4135. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  4136. evaluation.BloodAccessPartId = blood_access_part_id
  4137. }
  4138. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  4139. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  4140. // evaluation.BloodAccessPartId = blood_access_part_id
  4141. //}
  4142. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  4143. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  4144. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  4145. }
  4146. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  4147. internal_fistula, _ := dataBody["internal_fistula"].(string)
  4148. evaluation.InternalFistula = internal_fistula
  4149. }
  4150. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  4151. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  4152. evaluation.InternalFistulaSkin = internal_fistula_skin
  4153. }
  4154. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  4155. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  4156. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  4157. evaluation.IsHemorrhage = is_hemorrhage
  4158. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  4159. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  4160. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  4161. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  4162. is_hemorrhage = 0
  4163. }
  4164. evaluation.IsHemorrhage = is_hemorrhage
  4165. if is_hemorrhage == 1 {
  4166. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  4167. hemorrhage, _ := dataBody["hemorrhage"].(string)
  4168. evaluation.Hemorrhage = hemorrhage
  4169. }
  4170. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  4171. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  4172. evaluation.HemorrhageOther = hemorrhage_other
  4173. }
  4174. }
  4175. } else {
  4176. evaluation.IsHemorrhage = 0
  4177. }
  4178. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  4179. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  4180. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  4181. }
  4182. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  4183. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  4184. evaluation.InternalFistulaOther = internal_fistula_other
  4185. }
  4186. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  4187. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  4188. evaluation.BloodAccessNoise = blood_access_noise
  4189. }
  4190. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  4191. //puncture_way := int64(dataBody["puncture_way"].(float64))
  4192. puncture_way := dataBody["puncture_way"].(string)
  4193. evaluation.PunctureWay = puncture_way
  4194. }
  4195. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  4196. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  4197. evaluation.VenousCatheterization = venous_catheterization
  4198. }
  4199. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  4200. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  4201. evaluation.VenousCatheterizationPart = venous_catheterization_part
  4202. }
  4203. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  4204. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  4205. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  4206. }
  4207. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  4208. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  4209. evaluation.DuctusArantii = ductus_arantii
  4210. }
  4211. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  4212. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  4213. evaluation.EmergencyTreatment = emergency_treatment
  4214. }
  4215. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  4216. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  4217. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  4218. }
  4219. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  4220. dialysis_count, _ := dataBody["dialysis_count"].(string)
  4221. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  4222. evaluation.DialysisCount = dialysis_count
  4223. }
  4224. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  4225. is_infect, _ := dataBody["is_infect"].(string)
  4226. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  4227. evaluation.IsInfect = infect
  4228. }
  4229. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  4230. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  4231. evaluation.Exposed = exposed
  4232. }
  4233. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  4234. skin, _ := dataBody["skin"].(string)
  4235. //skins, _ := strconv.ParseInt(skin, 10, 64)
  4236. evaluation.Skin = skin
  4237. }
  4238. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  4239. skin_other, _ := dataBody["skin_other"].(string)
  4240. evaluation.SkinOther = skin_other
  4241. }
  4242. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  4243. infect_other, _ := dataBody["infect_other"].(string)
  4244. evaluation.InfectOther = infect_other
  4245. }
  4246. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  4247. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  4248. evaluation.DuctusArantiiOther = ductus_arantii_other
  4249. }
  4250. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  4251. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  4252. evaluation.PunctureNeedle = punctureNeedle
  4253. }
  4254. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  4255. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  4256. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  4257. }
  4258. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  4259. pinholing := dataBody["pinholing"].(string)
  4260. evaluation.Phinholing = pinholing
  4261. }
  4262. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  4263. catheter_suture := dataBody["catheter_suture"].(string)
  4264. evaluation.CatheterSuture = catheter_suture
  4265. }
  4266. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  4267. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  4268. evaluation.CatheterSutureOther = catheter_suture_other
  4269. }
  4270. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  4271. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  4272. evaluation.UrineVolume = urine_volume
  4273. }
  4274. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  4275. edema := dataBody["edema"].(string)
  4276. evaluation.Edema = edema
  4277. }
  4278. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  4279. specialTreatment := dataBody["special_treatment"].(string)
  4280. evaluation.SpecialTreatment = specialTreatment
  4281. }
  4282. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  4283. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  4284. evaluation.CatheterMaintenance = catheter_maintenance
  4285. }
  4286. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  4287. thromubusType := int64(dataBody["thromubus_type"].(float64))
  4288. evaluation.ThromubusType = thromubusType
  4289. }
  4290. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  4291. thrombus_av := dataBody["thrombus_av"].(string)
  4292. evaluation.ThrombusAv = thrombus_av
  4293. }
  4294. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  4295. thromubus_a := dataBody["thromubus_a"].(string)
  4296. evaluation.ThromubusA = thromubus_a
  4297. }
  4298. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  4299. thromubus_v := dataBody["thromubus_v"].(string)
  4300. evaluation.ThromubusV = thromubus_v
  4301. }
  4302. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  4303. dehydration := dataBody["dehydration"].(string)
  4304. evaluation.Dehydration = dehydration
  4305. }
  4306. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  4307. period := int64(dataBody["period"].(float64))
  4308. evaluation.Period = period
  4309. }
  4310. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  4311. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  4312. evaluation.EstimatedFoodIntake = estimated_food_intake
  4313. }
  4314. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  4315. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  4316. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  4317. }
  4318. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  4319. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  4320. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  4321. }
  4322. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  4323. urea_befor := dataBody["urea_befor"].(string)
  4324. evaluation.UreaBefor = urea_befor
  4325. }
  4326. if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
  4327. suction := dataBody["suction"].(string)
  4328. evaluation.Suction = suction
  4329. }
  4330. if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
  4331. weight_befor_remake := dataBody["weight_befor_remake"].(string)
  4332. evaluation.WeightBeforRemake = weight_befor_remake
  4333. }
  4334. if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
  4335. height := dataBody["height"].(string)
  4336. evaluation.Height = height
  4337. }
  4338. if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
  4339. age := dataBody["age"].(string)
  4340. evaluation.Age = age
  4341. }
  4342. if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
  4343. his_department := dataBody["his_department"].(string)
  4344. evaluation.HisDepartment = his_department
  4345. }
  4346. if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
  4347. his_bed := dataBody["his_bed"].(string)
  4348. evaluation.HisBed = his_bed
  4349. }
  4350. if dataBody["point_puncture"] != nil && reflect.TypeOf(dataBody["point_puncture"]).String() == "string" {
  4351. point_puncture := dataBody["point_puncture"].(string)
  4352. evaluation.PointPuncture = point_puncture
  4353. }
  4354. if dataBody["catheter_evaluation_program"] != nil && reflect.TypeOf(dataBody["catheter_evaluation_program"]).String() == "string" {
  4355. catheter_evaluation_program := dataBody["catheter_evaluation_program"].(string)
  4356. evaluation.CatheterEvaluationProgram = catheter_evaluation_program
  4357. }
  4358. if dataBody["skin_site_catheterization"] != nil && reflect.TypeOf(dataBody["skin_site_catheterization"]).String() == "string" {
  4359. skin_site_catheterization := dataBody["skin_site_catheterization"].(string)
  4360. evaluation.SkinSiteCatheterization = skin_site_catheterization
  4361. }
  4362. if dataBody["whether_unobstructed"] != nil && reflect.TypeOf(dataBody["whether_unobstructed"]).String() == "float64" {
  4363. whether_unobstructed := int64(dataBody["whether_unobstructed"].(float64))
  4364. evaluation.WhetherUnobstructed = whether_unobstructed
  4365. }
  4366. if dataBody["lien_necessary"] != nil && reflect.TypeOf(dataBody["lien_necessary"]).String() == "float64" {
  4367. lien_necessary := int64(dataBody["lien_necessary"].(float64))
  4368. evaluation.LienNecessary = lien_necessary
  4369. }
  4370. if dataBody["pathway_formation_time"] != nil && reflect.TypeOf(dataBody["pathway_formation_time"]).String() == "string" {
  4371. pathway_formation_time := dataBody["pathway_formation_time"].(string)
  4372. timeLayout := "2006-01-02"
  4373. loc, _ := time.LoadLocation("Local")
  4374. var startTime int64
  4375. if len(pathway_formation_time) > 0 {
  4376. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  4377. startTime = theTime.Unix()
  4378. }
  4379. evaluation.PathwayFormationTime = startTime
  4380. }
  4381. if dataBody["befor_symptoms"] != nil && reflect.TypeOf(dataBody["befor_symptoms"]).String() == "string" {
  4382. befor_symptoms := dataBody["befor_symptoms"].(string)
  4383. evaluation.BeforSymptoms = befor_symptoms
  4384. }
  4385. if dataBody["washing_time"] != nil && reflect.TypeOf(dataBody["washing_time"]).String() == "string" {
  4386. washing_time, _ := dataBody["washing_time"].(string)
  4387. evaluation.WashingTime = washing_time
  4388. }
  4389. if dataBody["warsh_count"] != nil && reflect.TypeOf(dataBody["warsh_count"]).String() == "string" {
  4390. warsh_count, _ := dataBody["warsh_count"].(string)
  4391. evaluation.WarshCount = warsh_count
  4392. }
  4393. if dataBody["puncture_needle_direction"] != nil && reflect.TypeOf(dataBody["puncture_needle_direction"]).String() == "string" {
  4394. puncture_needle_direction, _ := dataBody["puncture_needle_direction"].(string)
  4395. evaluation.PunctureNeedleDirection = puncture_needle_direction
  4396. }
  4397. if dataBody["symptom_before_dialysis_other"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis_other"]).String() == "string" {
  4398. symptom_before_dialysis_other, _ := dataBody["symptom_before_dialysis_other"].(string)
  4399. evaluation.SymptomBeforeDialysisOther = symptom_before_dialysis_other
  4400. }
  4401. return
  4402. }
  4403. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  4404. dataBody := make(map[string]interface{}, 0)
  4405. err := json.Unmarshal(data, &dataBody)
  4406. if err != nil {
  4407. utils.ErrorLog(err.Error())
  4408. code = enums.ErrorCodeParamWrong
  4409. return
  4410. }
  4411. timeLayout := "2006-01-02"
  4412. loc, _ := time.LoadLocation("Local")
  4413. isChild := false
  4414. if action == "create" {
  4415. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4416. utils.ErrorLog("advice_type")
  4417. code = enums.ErrorCodeParamWrong
  4418. return
  4419. }
  4420. adviceType := int64(dataBody["advice_type"].(float64))
  4421. if adviceType != 1 && adviceType != 2 {
  4422. utils.ErrorLog("advice_type != 1&&2")
  4423. code = enums.ErrorCodeParamWrong
  4424. return
  4425. }
  4426. advice.AdviceType = adviceType
  4427. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4428. utils.ErrorLog("advice_date")
  4429. code = enums.ErrorCodeParamWrong
  4430. return
  4431. }
  4432. adviceDate, _ := dataBody["advice_date"].(string)
  4433. if len(adviceDate) == 0 {
  4434. utils.ErrorLog("len(adviceDate) == 0")
  4435. code = enums.ErrorCodeParamWrong
  4436. return
  4437. }
  4438. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4439. if err != nil {
  4440. utils.ErrorLog(err.Error())
  4441. code = enums.ErrorCodeParamWrong
  4442. return
  4443. }
  4444. advice.AdviceDate = theTime.Unix()
  4445. advice.RecordDate = theTime.Unix()
  4446. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  4447. parentId := int64(dataBody["parent_id"].(float64))
  4448. advice.ParentId = parentId
  4449. if parentId > 0 {
  4450. isChild = true
  4451. }
  4452. }
  4453. } else {
  4454. isChild = advice.ParentId > 0
  4455. }
  4456. if !isChild {
  4457. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4458. utils.ErrorLog("start_time")
  4459. code = enums.ErrorCodeParamWrong
  4460. return
  4461. }
  4462. startTime, _ := dataBody["start_time"].(string)
  4463. if len(startTime) == 0 {
  4464. utils.ErrorLog("len(start_time) == 0")
  4465. code = enums.ErrorCodeParamWrong
  4466. return
  4467. }
  4468. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  4469. if err != nil {
  4470. utils.ErrorLog(err.Error())
  4471. code = enums.ErrorCodeParamWrong
  4472. return
  4473. }
  4474. advice.StartTime = theTime.Unix()
  4475. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  4476. deliveryWay, _ := dataBody["delivery_way"].(string)
  4477. advice.DeliveryWay = deliveryWay
  4478. }
  4479. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  4480. executionFrequency, _ := dataBody["execution_frequency"].(string)
  4481. advice.ExecutionFrequency = executionFrequency
  4482. }
  4483. }
  4484. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  4485. deliveryWay, _ := dataBody["delivery_way"].(string)
  4486. advice.DeliveryWay = deliveryWay
  4487. }
  4488. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  4489. executionFrequency, _ := dataBody["execution_frequency"].(string)
  4490. advice.ExecutionFrequency = executionFrequency
  4491. }
  4492. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  4493. utils.ErrorLog("advice_name")
  4494. code = enums.ErrorCodeParamWrong
  4495. return
  4496. }
  4497. adviceName, _ := dataBody["advice_name"].(string)
  4498. if len(adviceName) == 0 {
  4499. utils.ErrorLog("len(advice_name) == 0")
  4500. code = enums.ErrorCodeParamWrong
  4501. return
  4502. }
  4503. advice.AdviceName = adviceName
  4504. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  4505. adviceDsc, _ := dataBody["advice_desc"].(string)
  4506. advice.AdviceDesc = adviceDsc
  4507. }
  4508. if dataBody["way"] == nil {
  4509. advice.Way = 0
  4510. } else {
  4511. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  4512. way := int64(dataBody["way"].(float64))
  4513. advice.Way = way
  4514. }
  4515. }
  4516. if dataBody["drug_id"] == nil {
  4517. advice.DrugId = 0
  4518. } else {
  4519. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  4520. drug_id := int64(dataBody["drug_id"].(float64))
  4521. advice.DrugId = drug_id
  4522. }
  4523. }
  4524. if dataBody["drug_name_id"] == nil {
  4525. advice.DrugNameId = 0
  4526. } else {
  4527. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  4528. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  4529. advice.DrugNameId = drug_name_id
  4530. }
  4531. }
  4532. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  4533. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  4534. advice.SingleDose = singleDose
  4535. }
  4536. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  4537. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  4538. advice.SingleDoseUnit = singleDoseUnit
  4539. }
  4540. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  4541. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  4542. advice.DrugSpec = drugSpec
  4543. }
  4544. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  4545. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  4546. advice.DrugSpecUnit = drugSpecUnit
  4547. }
  4548. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  4549. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  4550. advice.PrescribingNumber = prescribingNumber
  4551. }
  4552. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  4553. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  4554. advice.PrescribingNumberUnit = prescribingNumberUnit
  4555. }
  4556. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4557. remark, _ := dataBody["remark"].(string)
  4558. advice.Remark = remark
  4559. }
  4560. return
  4561. }
  4562. func (c *PatientApiController) GetPatientEducation() {
  4563. patientID, _ := c.GetInt64("patient_id", 0)
  4564. page, _ := c.GetInt64("page", 0)
  4565. limit, _ := c.GetInt64("limit", 0)
  4566. startTime := c.GetString("start_time", "")
  4567. endTime := c.GetString("end_time", "")
  4568. if page <= 0 {
  4569. page = 1
  4570. }
  4571. if limit <= 0 {
  4572. limit = 10
  4573. }
  4574. if patientID <= 0 {
  4575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4576. return
  4577. }
  4578. timeLayout := "2006-01-02"
  4579. loc, _ := time.LoadLocation("Local")
  4580. var theStartTIme int64
  4581. if len(startTime) > 0 {
  4582. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4583. if err != nil {
  4584. theStartTIme = 0
  4585. }
  4586. theStartTIme = theTime.Unix()
  4587. }
  4588. var theEndtTIme int64
  4589. if len(endTime) > 0 {
  4590. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4591. if err != nil {
  4592. theEndtTIme = 0
  4593. }
  4594. theEndtTIme = theTime.Unix()
  4595. }
  4596. adminUserInfo := c.GetMobileAdminUserInfo()
  4597. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  4598. c.ServeSuccessJSON(map[string]interface{}{
  4599. "total": total,
  4600. "edus": edus,
  4601. })
  4602. return
  4603. }
  4604. func (c *PatientApiController) GetPatientSchedulesList() {
  4605. patientID, _ := c.GetInt64("patient_id", 0)
  4606. page, _ := c.GetInt64("page", 0)
  4607. limit, _ := c.GetInt64("limit", 0)
  4608. if patientID <= 0 {
  4609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4610. return
  4611. }
  4612. adminUserInfo := c.GetMobileAdminUserInfo()
  4613. todayTime := time.Now().Format("2006-01-02")
  4614. timeLayout := "2006-01-02 15:04:05"
  4615. loc, _ := time.LoadLocation("Local")
  4616. var theStartTime int64
  4617. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  4618. theStartTime = theTime.Unix()
  4619. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  4620. if len(schedules) > 0 {
  4621. for index, item := range schedules {
  4622. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  4623. schedules[index].Week = int64(week)
  4624. }
  4625. }
  4626. c.ServeSuccessJSON(map[string]interface{}{
  4627. "schedules": schedules,
  4628. })
  4629. return
  4630. }
  4631. func (c *PatientApiController) GetRecords() {
  4632. patientID, _ := c.GetInt64("patient_id", 0)
  4633. page, _ := c.GetInt64("page", 0)
  4634. limit, _ := c.GetInt64("limit", 0)
  4635. startTime := c.GetString("start_time", "")
  4636. endTime := c.GetString("end_time", "")
  4637. mode_id, _ := c.GetInt64("mode_id", 0)
  4638. if page <= 0 {
  4639. page = 1
  4640. }
  4641. if limit <= 0 {
  4642. limit = 10
  4643. }
  4644. if patientID <= 0 {
  4645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4646. return
  4647. }
  4648. timeLayout := "2006-01-02"
  4649. loc, _ := time.LoadLocation("Local")
  4650. var theStartTIme int64
  4651. if len(startTime) > 0 {
  4652. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4653. if err != nil {
  4654. theStartTIme = 0
  4655. }
  4656. theStartTIme = theTime.Unix()
  4657. }
  4658. var theEndtTIme int64
  4659. if len(endTime) > 0 {
  4660. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4661. if err != nil {
  4662. theEndtTIme = 0
  4663. }
  4664. theEndtTIme = theTime.Unix()
  4665. }
  4666. adminUserInfo := c.GetMobileAdminUserInfo()
  4667. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  4668. c.ServeSuccessJSON(map[string]interface{}{
  4669. "total": total,
  4670. "records": records,
  4671. })
  4672. return
  4673. }
  4674. func (c *PatientApiController) GetPatientMonitor() {
  4675. partition, _ := c.GetInt64("partition")
  4676. monitorDate := c.GetString("date")
  4677. patient_id, _ := c.GetInt64("patient_id")
  4678. timeLayout := "2006-01-02"
  4679. loc, _ := time.LoadLocation("Local")
  4680. var theStartTime int64
  4681. if len(monitorDate) > 0 {
  4682. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  4683. if err != nil {
  4684. theStartTime = 0
  4685. }
  4686. theStartTime = theTime.Unix()
  4687. }
  4688. adminInfo := c.GetMobileAdminUserInfo()
  4689. orgID := adminInfo.Org.Id
  4690. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  4691. if err != nil {
  4692. c.ErrorLog("获取排班信息失败:%v", err)
  4693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4694. } else {
  4695. if len(monitor) > 0 {
  4696. //获取所有床位
  4697. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  4698. //获取所有分区
  4699. zoneList, _ := service.GetAllZoneByList(orgID)
  4700. //获取透析处方
  4701. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  4702. //获取透前评估
  4703. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  4704. //获取上机
  4705. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  4706. //获取透后
  4707. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  4708. //获取透后监测
  4709. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  4710. //获取所有的患者
  4711. patients, _ := service.GetAllPatientListByListOne(orgID)
  4712. for _, it := range patients {
  4713. if orgID == 10445 {
  4714. if theStartTime <= 1703952000 {
  4715. listOne, _ := service.GetDialysisOrderCountTwentyEight(orgID, it.ID, theStartTime)
  4716. it.TotalDialysis = listOne.Count
  4717. }
  4718. if theStartTime >= 1704038400 {
  4719. listOrder, _ := service.GetDialysisOrderCountTenEight(it.ID, theStartTime)
  4720. it.TotalDialysis = listOrder.Count
  4721. }
  4722. }
  4723. }
  4724. //获取所有透析模式
  4725. treatments, _ := service.GetAllTreatModeByList(orgID)
  4726. for key, item := range monitor {
  4727. // 获取床位信息
  4728. for _, it := range numberList {
  4729. if item.BedId == it.ID {
  4730. monitor[key].DeviceNumber = it
  4731. break
  4732. }
  4733. }
  4734. //获取分区信息
  4735. for _, it := range zoneList {
  4736. if item.PartitionId == it.ID {
  4737. monitor[key].DeviceZone = it
  4738. }
  4739. }
  4740. for _, prescription := range prescriptions {
  4741. if item.PatientId == prescription.PatientId {
  4742. monitor[key].Prescription = prescription
  4743. break
  4744. }
  4745. }
  4746. // 透前评估
  4747. for _, assessmentBefore := range assessmentBefores {
  4748. if item.PatientId == assessmentBefore.PatientId {
  4749. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  4750. break
  4751. }
  4752. }
  4753. // 透析上下机
  4754. for _, dialysisOrder := range dialysisOrders {
  4755. if item.PatientId == dialysisOrder.PatientId {
  4756. monitor[key].DialysisOrder = dialysisOrder
  4757. break
  4758. }
  4759. }
  4760. // 治疗小节
  4761. for _, afterDislysis := range AssessmentAfterDislysis {
  4762. if item.PatientId == afterDislysis.PatientId {
  4763. monitor[key].AssessmentAfterDislysis = afterDislysis
  4764. break
  4765. }
  4766. }
  4767. for _, it := range monitorlist {
  4768. if item.PatientId == it.PatientId {
  4769. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  4770. }
  4771. }
  4772. for _, patient := range patients {
  4773. if item.PatientId == patient.ID {
  4774. monitor[key].MonitorPatients = patient
  4775. break
  4776. }
  4777. }
  4778. for _, treatment := range treatments {
  4779. if item.ModeId == treatment.ID {
  4780. monitor[key].TreatmentMode = treatment
  4781. break
  4782. }
  4783. }
  4784. }
  4785. }
  4786. }
  4787. //获取患者的透析次数
  4788. //count, err := service.GetDialysisCount(orgID, partition)
  4789. patients, err := service.GetAllpatientFourty(orgID)
  4790. if err == nil {
  4791. c.ServeSuccessJSON(map[string]interface{}{
  4792. "monitor": monitor,
  4793. //"patientCount": count,
  4794. "patients": patients,
  4795. })
  4796. } else {
  4797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4798. }
  4799. }
  4800. // /m/api/monitor/patient [get] 搜索病人的测量记录
  4801. // @param keyword:string 病人姓名或透析号
  4802. // @param page:int
  4803. func (this *PatientApiController) SearchMonitorPatient() {
  4804. keyword := this.GetString("keyword")
  4805. page, _ := this.GetInt("page")
  4806. if page <= 0 {
  4807. page = 1
  4808. }
  4809. if len(keyword) == 0 {
  4810. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4811. return
  4812. }
  4813. adminUserInfo := this.GetMobileAdminUserInfo()
  4814. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  4815. if getMonitorErr != nil {
  4816. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4817. return
  4818. } else {
  4819. this.ServeSuccessJSON(map[string]interface{}{
  4820. "monitor": monitors,
  4821. })
  4822. }
  4823. }
  4824. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  4825. id, _ := c.GetInt64("id", 0)
  4826. page, _ := c.GetInt64("page", 0)
  4827. limit, _ := c.GetInt64("limit", 0)
  4828. if id <= 0 {
  4829. c.ServeSuccessJSON(map[string]interface{}{
  4830. "solutions": nil,
  4831. })
  4832. return
  4833. }
  4834. if page <= 0 {
  4835. page = 1
  4836. }
  4837. if limit <= 0 {
  4838. limit = 10
  4839. }
  4840. adminInfo := c.GetMobileAdminUserInfo()
  4841. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  4842. c.ServeSuccessJSON(map[string]interface{}{
  4843. "solutions": solutions,
  4844. "total": total,
  4845. })
  4846. return
  4847. }
  4848. // GetDoctorAdvices 医嘱列表
  4849. func (c *PatientApiController) GetDoctorAdvices() {
  4850. id, _ := c.GetInt64("id", 0)
  4851. adviceType, _ := c.GetInt64("advice_type", 0)
  4852. stopType, _ := c.GetInt64("stop_state", 0)
  4853. startTime := c.GetString("start_time", "")
  4854. endTime := c.GetString("end_time", "")
  4855. keywords := c.GetString("keywords", "")
  4856. need, _ := c.GetInt64("need_doctor", 0)
  4857. adminUserInfo := c.GetMobileAdminUserInfo()
  4858. timeLayout := "2006-01-02"
  4859. loc, _ := time.LoadLocation("Local")
  4860. var theStartTIme int64
  4861. if len(startTime) > 0 {
  4862. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4863. if err != nil {
  4864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4865. return
  4866. }
  4867. theStartTIme = theTime.Unix()
  4868. }
  4869. var theEndtTIme int64
  4870. if len(endTime) > 0 {
  4871. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4872. if err != nil {
  4873. utils.ErrorLog(err.Error())
  4874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4875. return
  4876. }
  4877. theEndtTIme = theTime.Unix()
  4878. }
  4879. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  4880. if need == 1 {
  4881. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4882. c.ServeSuccessJSON(map[string]interface{}{
  4883. "advices": advices,
  4884. "total": total,
  4885. "users": users,
  4886. })
  4887. } else {
  4888. c.ServeSuccessJSON(map[string]interface{}{
  4889. "advices": advices,
  4890. "total": total,
  4891. "users": []string{},
  4892. })
  4893. }
  4894. return
  4895. }
  4896. func (c *PatientApiController) GetPrintDialysisOrder() {
  4897. xtno := c.GetString("xtno")
  4898. xtdate := c.GetString("xtdate")
  4899. timeLayout := "2006-01-02"
  4900. loc, _ := time.LoadLocation("Local")
  4901. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  4902. if err != nil {
  4903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4904. return
  4905. }
  4906. xttime := theTime.Unix()
  4907. //获取当前日期月份的第一天
  4908. firstmonth := service.GetFirstDateOfMonth(theTime)
  4909. firstMonthDate := firstmonth.Unix()
  4910. operatorIDs := make([]int64, 0)
  4911. adminUserInfo := c.GetMobileAdminUserInfo()
  4912. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4913. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  4914. //透析单
  4915. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4916. if dialysisOrder != nil {
  4917. if dialysisOrder.FinishNurse > 0 {
  4918. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  4919. }
  4920. if dialysisOrder.StartNurse > 0 {
  4921. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  4922. }
  4923. }
  4924. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4925. //透前评估
  4926. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4927. //透后评估
  4928. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4929. if AssessmentAfterDislysis.Modifier > 0 {
  4930. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  4931. }
  4932. //透析处方
  4933. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4934. if dialysisPrescription.PrescriptionDoctor > 0 {
  4935. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  4936. }
  4937. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4938. patientInfo.TotalDialysis = dialysis_count
  4939. //临时医嘱
  4940. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4941. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4942. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  4943. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  4944. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4945. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4946. if adminUserInfo.Org.Id != 10489 {
  4947. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  4948. for _, item := range projects {
  4949. cnt, _ := strconv.ParseFloat(item.Count, 64)
  4950. var advice models.HisDoctorAdviceInfo
  4951. advice.ID = item.ID
  4952. advice.Checker = item.Checker
  4953. advice.CheckTime = item.CheckTime
  4954. advice.CheckState = item.CheckState
  4955. advice.ExecutionState = item.ExecutionState
  4956. advice.ExecutionStaff = item.ExecutionStaff
  4957. //advice.PrescribingNumber = float64(item.Count)
  4958. advice.PrescribingNumber = cnt
  4959. advice.PrescribingNumberUnit = item.Unit
  4960. advice.AdviceDoctor = item.Doctor
  4961. advice.Remark = item.Remark
  4962. if item.Type == 3 {
  4963. advice.AdviceName = item.GoodInfo.GoodName
  4964. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  4965. } else if item.Type == 2 {
  4966. advice.AdviceName = item.HisProject.ProjectName
  4967. }
  4968. advice.StartTime = item.StartTime
  4969. hisAdvice = append(hisAdvice, &advice)
  4970. }
  4971. }
  4972. }
  4973. if len(DoctorAdvice) > 0 {
  4974. for _, item := range DoctorAdvice {
  4975. if item.AdviceDoctor > 0 {
  4976. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  4977. }
  4978. if item.ExecutionStaff > 0 {
  4979. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  4980. }
  4981. if item.Checker > 0 {
  4982. operatorIDs = append(operatorIDs, item.Checker)
  4983. }
  4984. }
  4985. }
  4986. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4987. //透析监测
  4988. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4989. //透析小结
  4990. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4991. //接诊评估
  4992. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4993. if receiverTreatmentAccess.Condition == 1 {
  4994. if len(receiverTreatmentAccess.AdmissionNumber) == 0 || receiverTreatmentAccess.AdmissionNumber == "" {
  4995. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, patientInfo.ID)
  4996. receiverTreatmentAccess.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  4997. receiverTreatmentAccess.HisDepartment = lastAcceptTreatment.HisDepartment
  4998. receiverTreatmentAccess.HisBed = lastAcceptTreatment.HisBed
  4999. }
  5000. }
  5001. //相关操作对应的操作人
  5002. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  5003. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  5004. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  5005. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5006. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  5007. lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5008. numberList, _ := service.GetAllBedNumberList(adminUserInfo.Org.Id)
  5009. if config.IsOpen == 1 {
  5010. c.ServeSuccessJSON(map[string]interface{}{
  5011. "users": adminUser,
  5012. "patientInfo": patientInfo,
  5013. "PredialysisEvaluation": PredialysisEvaluation,
  5014. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  5015. "dialysisPrescription": dialysisPrescription,
  5016. "advices": hisAdvice,
  5017. "monitors": Record,
  5018. "summary": TreatmentSummary,
  5019. "receiverTreatmentAccess": receiverTreatmentAccess,
  5020. "dialysisOrder": dialysisOrder,
  5021. "operators": operators,
  5022. "org_template_info": templateInfo,
  5023. "check": check,
  5024. "dialysiscount": dialysiscount,
  5025. "last_order": last_order,
  5026. "projects": projects,
  5027. "project_config": project_config,
  5028. "lastWeight": lastWeight,
  5029. "lastSchedule": lastSchedule,
  5030. "DoctorAdvice": DoctorAdvice,
  5031. "hisAdvice": hisAdvice,
  5032. "numberList": numberList,
  5033. })
  5034. }
  5035. if config.IsOpen == 0 || config.IsOpen == 2 {
  5036. c.ServeSuccessJSON(map[string]interface{}{
  5037. "users": adminUser,
  5038. "patientInfo": patientInfo,
  5039. "PredialysisEvaluation": PredialysisEvaluation,
  5040. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  5041. "dialysisPrescription": dialysisPrescription,
  5042. "advices": DoctorAdvice,
  5043. "monitors": Record,
  5044. "summary": TreatmentSummary,
  5045. "receiverTreatmentAccess": receiverTreatmentAccess,
  5046. "dialysisOrder": dialysisOrder,
  5047. "operators": operators,
  5048. "org_template_info": templateInfo,
  5049. "check": check,
  5050. "dialysiscount": dialysiscount,
  5051. "last_order": last_order,
  5052. "projects": projects,
  5053. "project_config": project_config,
  5054. "lastWeight": lastWeight,
  5055. "lastSchedule": lastSchedule,
  5056. "DoctorAdvice": DoctorAdvice,
  5057. "hisAdvice": hisAdvice,
  5058. "numberList": numberList,
  5059. })
  5060. }
  5061. }
  5062. func (c *PatientApiController) CreateGroupAdvice() {
  5063. is_child, _ := c.GetInt64("is_child", 0)
  5064. if is_child == 1 {
  5065. patient, _ := c.GetInt64("id", 0)
  5066. if patient <= 0 {
  5067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5068. return
  5069. }
  5070. adminUserInfo := c.GetMobileAdminUserInfo()
  5071. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  5072. if patientInfo.ID == 0 {
  5073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5074. return
  5075. }
  5076. group_no, _ := c.GetInt64("group_no")
  5077. if group_no <= 0 {
  5078. group_no = 0
  5079. }
  5080. dataBody := make(map[string]interface{}, 0)
  5081. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5082. if err != nil {
  5083. utils.ErrorLog(err.Error())
  5084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5085. return
  5086. }
  5087. timeLayout := "2006-01-02"
  5088. loc, _ := time.LoadLocation("Local")
  5089. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5090. utils.ErrorLog("advice_type")
  5091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5092. return
  5093. }
  5094. adviceType := int64(dataBody["advice_type"].(float64))
  5095. if adviceType != 1 && adviceType != 2 {
  5096. utils.ErrorLog("advice_type != 1&&2")
  5097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5098. return
  5099. }
  5100. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5101. utils.ErrorLog("start_time")
  5102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5103. return
  5104. }
  5105. startTime2, _ := dataBody["start_time"].(string)
  5106. time_arr := strings.Split(startTime2, " ")
  5107. if len(time_arr) > 0 {
  5108. startTime2 = time_arr[0]
  5109. }
  5110. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5111. utils.ErrorLog("advice_date")
  5112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5113. return
  5114. }
  5115. advice_date, _ := dataBody["advice_date"].(string)
  5116. var advicedateunix int64
  5117. if len(advice_date) > 0 {
  5118. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  5119. if err != nil {
  5120. fmt.Println(err)
  5121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5122. return
  5123. }
  5124. advicedateunix = theTime.Unix()
  5125. }
  5126. adviceDate := startTime2
  5127. if len(adviceDate) == 0 {
  5128. utils.ErrorLog("len(adviceDate) == 0")
  5129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5130. return
  5131. }
  5132. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  5133. if err != nil {
  5134. utils.ErrorLog(err.Error())
  5135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5136. return
  5137. }
  5138. AdviceDate := advicedateunix
  5139. RecordDate := advicedateunix
  5140. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5141. utils.ErrorLog("start_time")
  5142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5143. return
  5144. }
  5145. startTime, _ := dataBody["start_time"].(string)
  5146. if len(startTime) == 0 {
  5147. utils.ErrorLog("len(start_time) == 0")
  5148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5149. return
  5150. }
  5151. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  5152. theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
  5153. if err != nil {
  5154. utils.ErrorLog(err.Error())
  5155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5156. return
  5157. }
  5158. StartTime := theTime.Unix()
  5159. Remark := ""
  5160. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5161. remark, _ := dataBody["remark"].(string)
  5162. Remark = remark
  5163. }
  5164. Startdate := int64(dataBody["record_date"].(float64))
  5165. var advices []*models.GroupAdvice
  5166. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  5167. utils.ErrorLog("adviceNames")
  5168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5169. return
  5170. }
  5171. adviceNames := dataBody["adviceNames"].([]interface{})
  5172. for _, adviceNameMap := range adviceNames {
  5173. adviceNameM := adviceNameMap.(map[string]interface{})
  5174. var advice models.GroupAdvice
  5175. advice.Remark = Remark
  5176. advice.AdviceType = adviceType
  5177. advice.StartTime = StartTime
  5178. if adminUserInfo.Org.Id == 10340 {
  5179. advice.AdviceDate = AdviceDate
  5180. advice.RecordDate = RecordDate
  5181. }
  5182. if adminUserInfo.Org.Id != 10340 {
  5183. advice.AdviceDate = theTimeOne.Unix()
  5184. advice.RecordDate = theTimeOne.Unix()
  5185. }
  5186. advice.Status = 1
  5187. advice.CreatedTime = time.Now().Unix()
  5188. advice.UpdatedTime = time.Now().Unix()
  5189. advice.StopState = 2
  5190. advice.ExecutionState = 2
  5191. advice.UserOrgId = adminUserInfo.Org.Id
  5192. advice.PatientId = patientInfo.ID
  5193. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5194. advice.IsSettle = 2
  5195. //入口
  5196. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  5197. if errcode > 0 {
  5198. c.ServeFailJSONWithSGJErrorCode(errcode)
  5199. return
  5200. }
  5201. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  5202. subdrugs := adviceNameM["subdrugs"].([]interface{})
  5203. if len(subdrugs) > 0 {
  5204. for _, subdrug := range subdrugs {
  5205. var s models.GroupAdvice
  5206. s.Remark = Remark
  5207. s.AdviceType = adviceType
  5208. s.StartTime = StartTime
  5209. s.AdviceDate = AdviceDate
  5210. s.RecordDate = RecordDate
  5211. s.Status = 1
  5212. s.CreatedTime = time.Now().Unix()
  5213. s.UpdatedTime = time.Now().Unix()
  5214. s.StopState = 2
  5215. s.ExecutionState = 2
  5216. s.UserOrgId = adminUserInfo.Org.Id
  5217. s.PatientId = patientInfo.ID
  5218. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  5219. s.IsSettle = 2
  5220. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  5221. if errcode > 0 {
  5222. c.ServeFailJSONWithSGJErrorCode(errcode)
  5223. return
  5224. }
  5225. advice.Children = append(advice.Children, &s)
  5226. }
  5227. }
  5228. }
  5229. //长沙南雅
  5230. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  5231. //查询该患者今日有没有双人核对
  5232. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
  5233. if check.ID > 0 {
  5234. advice.Checker = check.Modifier
  5235. advice.CheckState = 1
  5236. advice.CheckTime = time.Now().Unix()
  5237. }
  5238. }
  5239. advices = append(advices, &advice)
  5240. }
  5241. // 查询信息规挡的设置天数
  5242. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5243. if infor.ID > 0 && infor.WeekDay > 0 {
  5244. var cha_time int64
  5245. timeNowStr := time.Now().Format("2006-01-02")
  5246. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5247. //今日的日期减去设置的日期
  5248. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5249. if cha_time >= Startdate {
  5250. //查询审核是否允许
  5251. infor, _ := service.GetDialysisInformationByRecordDate(patient, Startdate, adminUserInfo.Org.Id, 5)
  5252. //申请状态不允许的情况 拒绝修改
  5253. if infor.ApplicationStatus != 1 {
  5254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5255. return
  5256. }
  5257. }
  5258. }
  5259. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  5260. for _, item := range advices {
  5261. //记录日志
  5262. byterequest, _ := json.Marshal(item)
  5263. adviceLog := models.XtDoctorAdviceLog{
  5264. UserOrgId: item.UserOrgId,
  5265. PatientId: item.PatientId,
  5266. AdminUserId: adminUserInfo.AdminUser.Id,
  5267. Module: 1,
  5268. ErrLog: string(byterequest),
  5269. Status: 1,
  5270. Ctime: time.Now().Unix(),
  5271. Mtime: 0,
  5272. Source: "手机端新增医嘱",
  5273. RecordDate: item.AdviceDate,
  5274. }
  5275. service.CreateDoctorAdviceLog(adviceLog)
  5276. }
  5277. finish := models.XtDialysisFinish{
  5278. IsFinish: 1,
  5279. UserOrgId: adminUserInfo.Org.Id,
  5280. Status: 1,
  5281. Ctime: time.Now().Unix(),
  5282. Mtime: 0,
  5283. Module: 4,
  5284. RecordDate: advicedateunix,
  5285. Sourse: 1,
  5286. PatientId: patient,
  5287. }
  5288. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, advicedateunix, 4, patient)
  5289. if dialysisFinish.ID == 0 {
  5290. service.CreateDialysisFinish(finish)
  5291. }
  5292. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  5293. redis := service.RedisClient()
  5294. //清空key 值
  5295. redis.Set(key, "", time.Second)
  5296. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5297. redis.Set(keyOne, "", time.Second)
  5298. defer redis.Close()
  5299. if createErr != nil {
  5300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5301. return
  5302. }
  5303. c.ServeSuccessJSON(map[string]interface{}{
  5304. "msg": "ok",
  5305. "advices": newAdvices,
  5306. })
  5307. return
  5308. } else if is_child == 2 {
  5309. patient, _ := c.GetInt64("id", 0)
  5310. if patient <= 0 {
  5311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5312. return
  5313. }
  5314. adminUserInfo := c.GetMobileAdminUserInfo()
  5315. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  5316. if patientInfo.ID == 0 {
  5317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5318. return
  5319. }
  5320. var advice models.DoctorAdvice
  5321. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  5322. if code > 0 {
  5323. c.ServeFailJSONWithSGJErrorCode(code)
  5324. return
  5325. }
  5326. if advice.ParentId > 0 {
  5327. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  5328. if old.ID == 0 || old.PatientId != patient {
  5329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  5330. return
  5331. }
  5332. if old.StopState == 1 || old.ExecutionState == 1 {
  5333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  5334. return
  5335. }
  5336. if old.ParentId > 0 {
  5337. advice.ParentId = old.ParentId
  5338. }
  5339. advice.StartTime = old.StartTime
  5340. advice.AdviceDoctor = old.AdviceDoctor
  5341. advice.DeliveryWay = old.DeliveryWay
  5342. advice.ExecutionFrequency = old.ExecutionFrequency
  5343. advice.GroupNo = old.GroupNo
  5344. }
  5345. advice.Status = 1
  5346. advice.CreatedTime = time.Now().Unix()
  5347. advice.UpdatedTime = time.Now().Unix()
  5348. advice.StopState = 2
  5349. advice.ExecutionState = 2
  5350. advice.UserOrgId = adminUserInfo.Org.Id
  5351. advice.PatientId = patient
  5352. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5353. advice.IsSettle = 2
  5354. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  5355. if advice.PrescribingNumber == 0 {
  5356. advice.PrescribingNumber = 1
  5357. }
  5358. //查询该患者今日有没有双人核对
  5359. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, advice.AdviceDate)
  5360. if check.ID > 0 {
  5361. advice.Checker = check.Modifier
  5362. advice.CheckState = 1
  5363. advice.CheckTime = time.Now().Unix()
  5364. }
  5365. }
  5366. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5367. if infor.ID > 0 {
  5368. var cha_time int64
  5369. timeNowStr := time.Now().Format("2006-01-02")
  5370. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5371. //今日的日期减去设置的日期
  5372. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5373. if cha_time >= advice.RecordDate {
  5374. //查询审核是否允许
  5375. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.RecordDate, adminUserInfo.Org.Id, 4)
  5376. //申请状态不允许的情况 拒绝修改
  5377. if infor.ApplicationStatus != 1 {
  5378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5379. return
  5380. }
  5381. }
  5382. }
  5383. err := service.CreateDoctorAdvice(&advice)
  5384. //记录日志
  5385. byterequest, _ := json.Marshal(advice)
  5386. adviceLog := models.XtDoctorAdviceLog{
  5387. UserOrgId: advice.UserOrgId,
  5388. PatientId: advice.PatientId,
  5389. AdminUserId: adminUserInfo.Org.Id,
  5390. Module: 1,
  5391. ErrLog: string(byterequest),
  5392. Status: 1,
  5393. Ctime: time.Now().Unix(),
  5394. Mtime: 0,
  5395. Source: "手机端新增医嘱",
  5396. RecordDate: advice.AdviceDate,
  5397. }
  5398. service.CreateDoctorAdviceLog(adviceLog)
  5399. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  5400. redis := service.RedisClient()
  5401. //清空key 值
  5402. redis.Set(key, "", time.Second)
  5403. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  5404. redis.Set(keyOne, "", time.Second)
  5405. defer redis.Close()
  5406. if err != nil {
  5407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5408. return
  5409. }
  5410. c.ServeSuccessJSON(map[string]interface{}{
  5411. "msg": "ok",
  5412. "advice": advice,
  5413. })
  5414. return
  5415. }
  5416. }
  5417. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  5418. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  5419. utils.ErrorLog("advice_name")
  5420. return enums.ErrorCodeParamWrong
  5421. }
  5422. adviceName, _ := json["advice_name"].(string)
  5423. if len(adviceName) == 0 {
  5424. utils.ErrorLog("len(advice_name) == 0")
  5425. return enums.ErrorCodeParamWrong
  5426. }
  5427. advice.AdviceName = adviceName
  5428. adviceDesc, _ := json["advice_desc"].(string)
  5429. advice.AdviceDesc = adviceDesc
  5430. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5431. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5432. advice.DrugSpec = drugSpec
  5433. }
  5434. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5435. remark, _ := json["remark"].(string)
  5436. advice.Remark = remark
  5437. }
  5438. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  5439. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  5440. // advice.Way = src_type
  5441. //}
  5442. if json["way"] == nil {
  5443. advice.Way = 0
  5444. } else {
  5445. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  5446. way := int64(json["way"].(float64))
  5447. advice.Way = way
  5448. }
  5449. }
  5450. if json["drug_id"] == nil {
  5451. advice.DrugId = 0
  5452. } else {
  5453. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  5454. drug_id := int64(json["drug_id"].(float64))
  5455. advice.DrugId = drug_id
  5456. }
  5457. }
  5458. if json["drug_name_id"] == nil {
  5459. advice.DrugNameId = 0
  5460. } else {
  5461. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  5462. drug_name_id := int64(json["drug_name_id"].(float64))
  5463. advice.DrugNameId = drug_name_id
  5464. }
  5465. }
  5466. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  5467. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  5468. advice.DrugSpecUnit = drugSpecUnit
  5469. }
  5470. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5471. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5472. advice.SingleDose = singleDose
  5473. }
  5474. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5475. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5476. advice.SingleDoseUnit = singleDoseUnit
  5477. }
  5478. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5479. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5480. advice.PrescribingNumber = prescribingNumber
  5481. }
  5482. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5483. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5484. advice.PrescribingNumberUnit = prescribingNumberUnit
  5485. }
  5486. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5487. deliveryWay, _ := json["delivery_way"].(string)
  5488. advice.DeliveryWay = deliveryWay
  5489. }
  5490. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5491. executionFrequency, _ := json["execution_frequency"].(string)
  5492. advice.ExecutionFrequency = executionFrequency
  5493. }
  5494. return 0
  5495. }
  5496. func (c *PatientApiController) DelDoctorAdvice() {
  5497. groupno, _ := c.GetInt64("groupno", -1)
  5498. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  5499. patient_id, _ := c.GetInt64("patient_id")
  5500. doc_advice_date, _ := c.GetInt64("advice_date")
  5501. redis := service.RedisClient()
  5502. if is_sub == 1 { //是
  5503. advice_id, _ := c.GetInt64("advice_id")
  5504. adminUserInfo := c.GetMobileAdminUserInfo()
  5505. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  5506. if advice.ID == 0 {
  5507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5508. return
  5509. }
  5510. advice.Status = 0
  5511. advice.UpdatedTime = time.Now().Unix()
  5512. advice.Modifier = adminUserInfo.AdminUser.Id
  5513. // 查询信息规挡的设置天数
  5514. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5515. if infor.ID > 0 && infor.WeekDay > 0 {
  5516. var cha_time int64
  5517. timeNowStr := time.Now().Format("2006-01-02")
  5518. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5519. //今日的日期减去设置的日期
  5520. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5521. if cha_time >= advice.AdviceDate {
  5522. //查询审核是否允许
  5523. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5524. //申请状态不允许的情况 拒绝修改
  5525. if infor.ApplicationStatus != 1 {
  5526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5527. return
  5528. }
  5529. }
  5530. }
  5531. //自备药
  5532. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5533. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5534. //查询库存是否是自备药
  5535. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  5536. if selfBasedrug.IsSelfDrug == 1 {
  5537. creater := adminUserInfo.AdminUser.Id
  5538. //退库
  5539. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  5540. }
  5541. }
  5542. err := service.DeleteDoctorAdvice(&advice)
  5543. //记录日志
  5544. byterequest, _ := json.Marshal(advice)
  5545. adviceLog := models.XtDoctorAdviceLog{
  5546. UserOrgId: advice.UserOrgId,
  5547. PatientId: advice.PatientId,
  5548. AdminUserId: adminUserInfo.AdminUser.Id,
  5549. Module: 4,
  5550. ErrLog: string(byterequest),
  5551. Status: 1,
  5552. Ctime: time.Now().Unix(),
  5553. Mtime: 0,
  5554. Source: "手机端删除医嘱",
  5555. RecordDate: advice.RecordDate,
  5556. }
  5557. service.CreateDoctorAdviceLog(adviceLog)
  5558. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5559. redis.Set(key, "", time.Second)
  5560. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5561. redis.Set(keyTwo, "", time.Second)
  5562. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5563. redis.Set(keyThree, "", time.Second)
  5564. redis.Close()
  5565. if err != nil {
  5566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5567. return
  5568. }
  5569. c.ServeSuccessJSON(map[string]interface{}{
  5570. "msg": "ok",
  5571. })
  5572. return
  5573. } else { //
  5574. var ids []string
  5575. if groupno == 0 {
  5576. advice_id := c.GetString("advice_id")
  5577. ids = strings.Split(advice_id, ",")
  5578. if len(ids) <= 0 {
  5579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5580. return
  5581. }
  5582. }
  5583. if groupno < 0 {
  5584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5585. return
  5586. }
  5587. adminUserInfo := c.GetMobileAdminUserInfo()
  5588. var advice models.DoctorAdvice
  5589. if groupno > 0 {
  5590. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  5591. if advice.ID == 0 {
  5592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5593. return
  5594. }
  5595. } else {
  5596. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  5597. for _, item := range advices {
  5598. if item.ID == 0 {
  5599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5600. return
  5601. }
  5602. }
  5603. }
  5604. advice.UpdatedTime = time.Now().Unix()
  5605. advice.Status = 0
  5606. advice.GroupNo = groupno
  5607. advice.Modifier = adminUserInfo.AdminUser.Id
  5608. var err error
  5609. if groupno > 0 {
  5610. // 查询信息规挡的设置天数
  5611. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5612. if infor.ID > 0 {
  5613. var cha_time int64
  5614. timeNowStr := time.Now().Format("2006-01-02")
  5615. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5616. //今日的日期减去设置的日期
  5617. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5618. if cha_time >= advice.AdviceDate {
  5619. //查询审核是否允许
  5620. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5621. //申请状态不允许的情况 拒绝修改
  5622. if infor.ApplicationStatus != 1 {
  5623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5624. return
  5625. }
  5626. }
  5627. }
  5628. //自备药
  5629. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5630. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5631. //查询库存是否是自备药
  5632. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  5633. if selfBasedrug.IsSelfDrug == 1 {
  5634. creater := adminUserInfo.AdminUser.Id
  5635. //退库
  5636. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  5637. }
  5638. }
  5639. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  5640. //记录日志
  5641. byterequest, _ := json.Marshal(advice)
  5642. adviceLog := models.XtDoctorAdviceLog{
  5643. UserOrgId: advice.UserOrgId,
  5644. PatientId: advice.PatientId,
  5645. AdminUserId: adminUserInfo.AdminUser.Id,
  5646. Module: 4,
  5647. ErrLog: string(byterequest),
  5648. Status: 1,
  5649. Ctime: time.Now().Unix(),
  5650. Mtime: 0,
  5651. Source: "手机端删除医嘱",
  5652. RecordDate: advice.RecordDate,
  5653. }
  5654. service.CreateDoctorAdviceLog(adviceLog)
  5655. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5656. redis.Set(key, "", time.Second)
  5657. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5658. redis.Set(keyTwo, "", time.Second)
  5659. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5660. redis.Set(keyThree, "", time.Second)
  5661. } else {
  5662. // 查询信息规挡的设置天数
  5663. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5664. if infor.ID > 0 {
  5665. var cha_time int64
  5666. timeNowStr := time.Now().Format("2006-01-02")
  5667. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5668. //今日的日期减去设置的日期
  5669. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5670. if cha_time >= advice.AdviceDate {
  5671. //查询审核是否允许
  5672. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5673. //申请状态不允许的情况 拒绝修改
  5674. if infor.ApplicationStatus != 1 {
  5675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5676. return
  5677. }
  5678. }
  5679. }
  5680. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  5681. advicelist, _ := service.GetBatchDoctorAdviceList(ids, adminUserInfo.Org.Id)
  5682. for _, item := range advicelist {
  5683. //自备药
  5684. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5685. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5686. //查询库存是否是自备药
  5687. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(item.DrugId, item.UserOrgId)
  5688. if selfBasedrug.IsSelfDrug == 1 {
  5689. creater := adminUserInfo.AdminUser.Id
  5690. //退库
  5691. service.SelfDrugAutoAddCancelInfoOne(item, creater)
  5692. }
  5693. }
  5694. //记录日志
  5695. byterequest, _ := json.Marshal(item)
  5696. adviceLog := models.XtDoctorAdviceLog{
  5697. UserOrgId: item.UserOrgId,
  5698. PatientId: item.PatientId,
  5699. AdminUserId: adminUserInfo.AdminUser.Id,
  5700. Module: 4,
  5701. ErrLog: string(byterequest),
  5702. Status: 1,
  5703. Ctime: time.Now().Unix(),
  5704. Mtime: 0,
  5705. Source: "手机端批量删除医嘱",
  5706. RecordDate: item.RecordDate,
  5707. }
  5708. service.CreateDoctorAdviceLog(adviceLog)
  5709. }
  5710. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5711. redis.Set(key, "", time.Second)
  5712. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5713. redis.Set(keyTwo, "", time.Second)
  5714. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5715. redis.Set(keyThree, "", time.Second)
  5716. redis.Close()
  5717. }
  5718. if err != nil {
  5719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5720. return
  5721. }
  5722. c.ServeSuccessJSON(map[string]interface{}{
  5723. "msg": "ok",
  5724. })
  5725. return
  5726. }
  5727. }
  5728. // /m/api/advice/group/modify_starttime [post]
  5729. // @param group_no:int
  5730. // @param start_time:string yyyy-MM-dd hh:mm:ss
  5731. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  5732. group_no, _ := this.GetInt64("group_no")
  5733. start_time_str := this.GetString("start_time")
  5734. if group_no <= 0 || len(start_time_str) == 0 {
  5735. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5736. return
  5737. }
  5738. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  5739. if parseTimeErr != nil {
  5740. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  5741. return
  5742. }
  5743. adminUserInfo := this.GetMobileAdminUserInfo()
  5744. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  5745. if updateStartTimeErr != nil {
  5746. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  5747. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5748. return
  5749. }
  5750. this.ServeSuccessJSON(map[string]interface{}{
  5751. "start_time": startTime.Unix(),
  5752. })
  5753. }
  5754. func (this *PatientApiController) DelSubDoctorAdvice() {
  5755. advice_id, _ := this.GetInt64("advice_id")
  5756. adminUserInfo := this.GetMobileAdminUserInfo()
  5757. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  5758. if advice.ID == 0 {
  5759. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5760. return
  5761. }
  5762. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  5763. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  5764. // return
  5765. //}
  5766. advice.Status = 0
  5767. advice.UpdatedTime = time.Now().Unix()
  5768. advice.Modifier = adminUserInfo.AdminUser.Id
  5769. err := service.DeleteDoctorAdvice(&advice)
  5770. if err != nil {
  5771. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5772. return
  5773. }
  5774. this.ServeSuccessJSON(map[string]interface{}{
  5775. "msg": "ok",
  5776. })
  5777. return
  5778. }
  5779. func (this *PatientApiController) GetAdviceUnReadMessage() {
  5780. //adminUserInfo := this.GetMobileAdminUserInfo()
  5781. //service.FindUnReadDoctorAdviceMessage()
  5782. }
  5783. func (this *PatientApiController) GetPatientsByKeyWord() {
  5784. keyWord := this.GetString("keyword")
  5785. adminUserInfo := this.GetMobileAdminUserInfo()
  5786. today := utils.ZeroHourTimeOfDay(time.Now())
  5787. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  5788. if err != nil {
  5789. utils.ErrorLog(err.Error())
  5790. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5791. return
  5792. }
  5793. this.ServeSuccessJSON(map[string]interface{}{
  5794. "patient": patient,
  5795. })
  5796. }
  5797. func (this *PatientApiController) GetSearchPatient() {
  5798. keyWord := this.GetString("keyword")
  5799. adminUserInfo := this.GetMobileAdminUserInfo()
  5800. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  5801. if err != nil {
  5802. utils.ErrorLog(err.Error())
  5803. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5804. return
  5805. }
  5806. this.ServeSuccessJSON(map[string]interface{}{
  5807. "patient": patient,
  5808. })
  5809. }
  5810. func (c *PatientApiController) ExecProject() {
  5811. execution_time := c.GetString("execution_time")
  5812. project_id, _ := c.GetInt64("project_id")
  5813. team_id, _ := c.GetInt64("team_id")
  5814. is_check_team, _ := c.GetInt64("is_check_team")
  5815. record_date, _ := c.GetInt64("record_date")
  5816. patient_id, _ := c.GetInt64("patient_id")
  5817. if len(execution_time) <= 0 {
  5818. utils.ErrorLog("execution_time")
  5819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5820. return
  5821. }
  5822. timeLayout2 := "2006-01-02 15:04:05"
  5823. loc, _ := time.LoadLocation("Local")
  5824. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  5825. if errs != nil {
  5826. utils.ErrorLog(errs.Error())
  5827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5828. return
  5829. }
  5830. adminInfo := c.GetMobileAdminUserInfo()
  5831. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  5832. //针对舒和
  5833. if adminInfo.Org.Id == 10644 {
  5834. if project.StartTime > theTime.Unix() {
  5835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  5836. return
  5837. }
  5838. }
  5839. if project.Type == 3 {
  5840. good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
  5841. if good.IsUser != 1 {
  5842. //查询开关是否开启
  5843. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  5844. //开关已经开启
  5845. if stockSetting.IsType == 1 {
  5846. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  5847. scheduleDateStart := theTime.Format("2006-01-02")
  5848. timeLayout3 := "2006-01-02"
  5849. loc, _ := time.LoadLocation("Local")
  5850. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  5851. //查询该耗材是否已经出库
  5852. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  5853. if auto.ID == 0 {
  5854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  5855. return
  5856. }
  5857. }
  5858. }
  5859. if good.IsUser == 1 && good.IsWarehouse == 1 {
  5860. //查询开关是否开启
  5861. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  5862. //开关已经开启
  5863. if stockSetting.IsType == 1 {
  5864. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  5865. scheduleDateStart := theTime.Format("2006-01-02")
  5866. timeLayout3 := "2006-01-02"
  5867. loc, _ := time.LoadLocation("Local")
  5868. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  5869. //查询该耗材是否已经出库
  5870. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  5871. if auto.ID == 0 {
  5872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  5873. return
  5874. }
  5875. }
  5876. }
  5877. }
  5878. if project.ExecutionState == 1 {
  5879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  5880. return
  5881. }
  5882. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  5883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  5884. return
  5885. }
  5886. project.ExecutionState = 1
  5887. project.ExecutionStaff = adminInfo.AdminUser.Id
  5888. project.ExecutionTime = theTime.Unix()
  5889. if team_id == 0 {
  5890. // 查询信息规挡的设置天数
  5891. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5892. if infor.ID > 0 {
  5893. var cha_time int64
  5894. timeNowStr := time.Now().Format("2006-01-02")
  5895. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5896. //今日的日期减去设置的日期
  5897. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5898. if cha_time >= project.RecordDate {
  5899. //查询审核是否允许
  5900. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5901. //申请状态不允许的情况 拒绝修改
  5902. if infor.ApplicationStatus != 1 {
  5903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5904. return
  5905. }
  5906. }
  5907. }
  5908. err := service.SaveHisProject(&project)
  5909. if err == nil {
  5910. c.ServeSuccessJSON(map[string]interface{}{
  5911. "project": project,
  5912. })
  5913. } else {
  5914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5915. return
  5916. }
  5917. } else {
  5918. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  5919. // 查询信息规挡的设置天数
  5920. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5921. if infor.ID > 0 {
  5922. var cha_time int64
  5923. timeNowStr := time.Now().Format("2006-01-02")
  5924. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5925. //今日的日期减去设置的日期
  5926. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5927. if cha_time >= project.RecordDate {
  5928. //查询审核是否允许
  5929. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5930. //申请状态不允许的情况 拒绝修改
  5931. if infor.ApplicationStatus != 1 {
  5932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5933. return
  5934. }
  5935. }
  5936. }
  5937. err := service.SaveHisProject(&project)
  5938. if err == nil {
  5939. c.ServeSuccessJSON(map[string]interface{}{
  5940. "project": project,
  5941. })
  5942. } else {
  5943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5944. return
  5945. }
  5946. } else {
  5947. // 查询信息规挡的设置天数
  5948. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5949. if infor.ID > 0 {
  5950. var cha_time int64
  5951. timeNowStr := time.Now().Format("2006-01-02")
  5952. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5953. //今日的日期减去设置的日期
  5954. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5955. if cha_time >= project.RecordDate {
  5956. //查询审核是否允许
  5957. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5958. //申请状态不允许的情况 拒绝修改
  5959. if infor.ApplicationStatus != 1 {
  5960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5961. return
  5962. }
  5963. }
  5964. }
  5965. ps, _ := service.GetCheckTeamProjectOne(team_id, patient_id, record_date, adminInfo.Org.Id)
  5966. var ids []int64
  5967. for _, items := range ps {
  5968. ids = append(ids, items.ID)
  5969. }
  5970. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  5971. if err == nil {
  5972. c.ServeSuccessJSON(map[string]interface{}{
  5973. "project": project,
  5974. })
  5975. } else {
  5976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5977. return
  5978. }
  5979. }
  5980. }
  5981. }
  5982. func (c *PatientApiController) CheckProject() {
  5983. adminInfo := c.GetMobileAdminUserInfo()
  5984. project_id, _ := c.GetInt64("project_id")
  5985. team_id, _ := c.GetInt64("team_id")
  5986. is_check_team, _ := c.GetInt64("is_check_team")
  5987. record_date, _ := c.GetInt64("record_date")
  5988. patient_id, _ := c.GetInt64("patient_id")
  5989. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  5990. if project.CheckState == 1 {
  5991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  5992. return
  5993. }
  5994. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  5995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  5996. return
  5997. }
  5998. project.Checker = adminInfo.AdminUser.Id
  5999. project.CheckTime = time.Now().Unix()
  6000. project.CheckState = 1
  6001. if team_id == 0 {
  6002. // 查询信息规挡的设置天数
  6003. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  6004. if infor.ID > 0 {
  6005. var cha_time int64
  6006. timeNowStr := time.Now().Format("2006-01-02")
  6007. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6008. //今日的日期减去设置的日期
  6009. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6010. if cha_time >= project.RecordDate {
  6011. //查询审核是否允许
  6012. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  6013. //申请状态不允许的情况 拒绝修改
  6014. if infor.ApplicationStatus != 1 {
  6015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6016. return
  6017. }
  6018. }
  6019. }
  6020. err := service.SaveHisProject(&project)
  6021. if err == nil {
  6022. c.ServeSuccessJSON(map[string]interface{}{
  6023. "msg": "ok",
  6024. "project": project,
  6025. })
  6026. } else {
  6027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6028. return
  6029. }
  6030. } else {
  6031. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  6032. // 查询信息规挡的设置天数
  6033. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  6034. if infor.ID > 0 {
  6035. var cha_time int64
  6036. timeNowStr := time.Now().Format("2006-01-02")
  6037. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6038. //今日的日期减去设置的日期
  6039. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6040. if cha_time >= project.RecordDate {
  6041. //查询审核是否允许
  6042. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  6043. //申请状态不允许的情况 拒绝修改
  6044. if infor.ApplicationStatus != 1 {
  6045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6046. return
  6047. }
  6048. }
  6049. }
  6050. err := service.SaveHisProject(&project)
  6051. if err == nil {
  6052. c.ServeSuccessJSON(map[string]interface{}{
  6053. "msg": "ok",
  6054. "project": project,
  6055. })
  6056. } else {
  6057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6058. return
  6059. }
  6060. } else {
  6061. // 查询信息规挡的设置天数
  6062. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  6063. if infor.ID > 0 {
  6064. var cha_time int64
  6065. timeNowStr := time.Now().Format("2006-01-02")
  6066. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6067. //今日的日期减去设置的日期
  6068. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6069. if cha_time >= project.RecordDate {
  6070. //查询审核是否允许
  6071. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  6072. //申请状态不允许的情况 拒绝修改
  6073. if infor.ApplicationStatus != 1 {
  6074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6075. return
  6076. }
  6077. }
  6078. }
  6079. ps, _ := service.GetCheckTeamProjectOne(team_id, patient_id, record_date, adminInfo.Org.Id)
  6080. var ids []int64
  6081. for _, items := range ps {
  6082. ids = append(ids, items.ID)
  6083. }
  6084. err := service.UpdateTeamProjectCheckStatus(ids, patient_id, record_date, adminInfo.Org.Id, adminInfo.AdminUser.Id, time.Now().Unix())
  6085. if err == nil {
  6086. c.ServeSuccessJSON(map[string]interface{}{
  6087. "project": project,
  6088. })
  6089. } else {
  6090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6091. return
  6092. }
  6093. }
  6094. }
  6095. }