patient_api_controller.go 256KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147
  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. if adminUserInfo.Org.Id == 10597 {
  3746. if evaluation.ID > 0 {
  3747. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  3748. if dialysisPrescribeOne.ID > 0 && evaluation.ID > 0 {
  3749. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3750. service.UpdateMobileGetDialysisPrescribeOne(dialysisPrescribeOne.ID, dewater_amount)
  3751. }
  3752. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  3753. redis := service.RedisClient()
  3754. //清空key 值
  3755. redis.Set(keyThree, "", time.Second)
  3756. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  3757. //清空key 值
  3758. redis.Set(keyFour, "", time.Second)
  3759. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":schedual_detail"
  3760. redis.Set(keyFive, "", time.Second)
  3761. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  3762. redis.Set(keySix, "", time.Second)
  3763. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  3764. redis.Set(keySeven, "", time.Second)
  3765. keyNight := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3766. redis.Set(keyNight, "", time.Second)
  3767. var recordDateStr = time.Now().Format("2006-01-02")
  3768. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3769. //清空key 值
  3770. redis.Set(keyOne, "", time.Second)
  3771. }
  3772. }
  3773. err = service.UpadatePredialysisEvaluation(&evaluation)
  3774. //记录日志
  3775. byterequest, _ := json.Marshal(evaluation)
  3776. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  3777. UserOrgId: evaluation.UserOrgId,
  3778. AdminUserId: adminUserInfo.AdminUser.Id,
  3779. ErrLog: string(byterequest),
  3780. PatientId: evaluation.PatientId,
  3781. RecordDate: evaluation.AssessmentDate,
  3782. Ctime: time.Now().Unix(),
  3783. Mtime: 0,
  3784. Status: 1,
  3785. Source: "手机端保存透前评估",
  3786. }
  3787. service.CreateBeforLog(beforeDislysisLog)
  3788. finish := models.XtDialysisFinish{
  3789. IsFinish: 1,
  3790. UserOrgId: adminUserInfo.Org.Id,
  3791. Status: 1,
  3792. Ctime: time.Now().Unix(),
  3793. Mtime: 0,
  3794. Module: 3,
  3795. RecordDate: evaluation.AssessmentDate,
  3796. Sourse: 1,
  3797. PatientId: id,
  3798. }
  3799. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, evaluation.AssessmentDate, 3, id)
  3800. if dialysisFinish.ID == 0 {
  3801. service.CreateDialysisFinish(finish)
  3802. }
  3803. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  3804. redis := service.RedisClient()
  3805. defer redis.Close()
  3806. //清空key 值
  3807. redis.Set(key, "", time.Second)
  3808. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  3809. redis.Set(keyOne, "", time.Second)
  3810. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3811. redis.Set(keyTwo, "", time.Second)
  3812. if err != nil {
  3813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  3814. return
  3815. }
  3816. c.ServeSuccessJSON(map[string]interface{}{
  3817. "msg": "ok",
  3818. "evaluation": evaluation,
  3819. })
  3820. return
  3821. }
  3822. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3823. dataBody := make(map[string]interface{}, 0)
  3824. err := json.Unmarshal(data, &dataBody)
  3825. utils.InfoLog(string(data))
  3826. if err != nil {
  3827. utils.ErrorLog(err.Error())
  3828. code = enums.ErrorCodeParamWrong
  3829. return
  3830. }
  3831. // if method == "create" {
  3832. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  3833. utils.ErrorLog("mode")
  3834. code = enums.ErrorCodeParamWrong
  3835. return
  3836. }
  3837. mode := int64(dataBody["mode"].(float64))
  3838. if mode <= 0 {
  3839. utils.ErrorLog("mode <= 0")
  3840. code = enums.ErrorCodeParamWrong
  3841. return
  3842. }
  3843. solution.ModeId = mode
  3844. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  3845. utils.ErrorLog("mode_name")
  3846. code = enums.ErrorCodeParamWrong
  3847. return
  3848. }
  3849. modeName, _ := dataBody["mode_name"].(string)
  3850. if len(modeName) == 0 {
  3851. utils.ErrorLog("len(mode_name) == 0")
  3852. code = enums.ErrorCodeParamWrong
  3853. return
  3854. }
  3855. solution.ModeName = modeName
  3856. solution.Name = modeName
  3857. // }
  3858. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3859. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3860. solution.DialysisDuration = dialysisDuration
  3861. }
  3862. if dataBody["dialysis_duration"] != nil {
  3863. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3864. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3865. solution.DialysisDuration = dialysisDuration
  3866. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  3867. dialysisDuration := dataBody["dialysis_duration"].(float64)
  3868. solution.DialysisDuration = dialysisDuration
  3869. }
  3870. }
  3871. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  3872. dialyzer := int64(dataBody["dialyzer"].(float64))
  3873. solution.Dialyzer = dialyzer
  3874. }
  3875. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3876. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3877. solution.PerfusionApparatus = perfusionApparatus
  3878. }
  3879. if dataBody["blood_flow_volume"] != nil {
  3880. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3881. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3882. solution.BloodFlowVolume = bloodFlowVolume
  3883. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  3884. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  3885. solution.BloodFlowVolume = bloodFlowVolume
  3886. }
  3887. }
  3888. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3889. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3890. solution.HemodialysisMachine = hemodialysisMachine
  3891. }
  3892. if dataBody["dewater"] != nil {
  3893. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  3894. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  3895. solution.Dewater = dewater
  3896. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  3897. dewater := dataBody["dewater"].(float64)
  3898. solution.Dewater = dewater
  3899. }
  3900. }
  3901. if dataBody["replacement_total"] != nil {
  3902. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  3903. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  3904. solution.ReplacementTotal = replacementTotal
  3905. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  3906. replacementTotal := dataBody["replacement_total"].(float64)
  3907. solution.ReplacementTotal = replacementTotal
  3908. }
  3909. }
  3910. if dataBody["displace_liqui"] != nil {
  3911. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  3912. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  3913. solution.DisplaceLiqui = displaceLiqui
  3914. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  3915. displaceLiqui := dataBody["displace_liqui"].(float64)
  3916. solution.DisplaceLiqui = displaceLiqui
  3917. }
  3918. }
  3919. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3920. replacementWay := int64(dataBody["replacement_way"].(float64))
  3921. solution.ReplacementWay = replacementWay
  3922. }
  3923. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3924. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3925. solution.Anticoagulant = anticoagulant
  3926. }
  3927. if dataBody["anticoagulant_shouji"] != nil {
  3928. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3929. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3930. solution.AnticoagulantShouji = anticoagulantShouji
  3931. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  3932. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  3933. solution.AnticoagulantShouji = anticoagulantShouji
  3934. }
  3935. }
  3936. if dataBody["anticoagulant_weichi"] != nil {
  3937. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3938. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3939. solution.AnticoagulantWeichi = anticoagulantWeichi
  3940. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  3941. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  3942. solution.AnticoagulantWeichi = anticoagulantWeichi
  3943. }
  3944. }
  3945. if dataBody["anticoagulant_zongliang"] != nil {
  3946. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3947. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3948. solution.AnticoagulantZongliang = anticoagulantZongliang
  3949. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  3950. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  3951. solution.AnticoagulantZongliang = anticoagulantZongliang
  3952. }
  3953. }
  3954. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3955. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3956. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3957. }
  3958. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3959. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3960. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3961. }
  3962. if dataBody["kalium"] != nil {
  3963. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3964. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3965. solution.Kalium = kalium
  3966. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  3967. kalium := dataBody["kalium"].(float64)
  3968. solution.Kalium = kalium
  3969. }
  3970. }
  3971. if dataBody["sodium"] != nil {
  3972. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3973. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3974. solution.Sodium = sodium
  3975. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  3976. sodium := dataBody["sodium"].(float64)
  3977. solution.Sodium = sodium
  3978. }
  3979. }
  3980. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3981. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3982. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3983. solution.Calcium = calcium
  3984. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  3985. calcium := dataBody["calcium"].(float64)
  3986. solution.Calcium = calcium
  3987. }
  3988. }
  3989. if dataBody["bicarbonate"] != nil {
  3990. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3991. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3992. solution.Bicarbonate = bicarbonate
  3993. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  3994. bicarbonate := dataBody["bicarbonate"].(float64)
  3995. solution.Bicarbonate = bicarbonate
  3996. }
  3997. }
  3998. if dataBody["glucose"] != nil {
  3999. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  4000. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  4001. solution.Glucose = glucose
  4002. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  4003. glucose := dataBody["glucose"].(float64)
  4004. solution.Glucose = glucose
  4005. }
  4006. }
  4007. // if dataBody["dry_weight"] != nil {
  4008. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  4009. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  4010. // solution.DryWeight = dryWeight
  4011. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  4012. // dryWeight := dataBody["dry_weight"].(float64)
  4013. // solution.DryWeight = dryWeight
  4014. // }
  4015. // }
  4016. if dataBody["dialysate_flow"] != nil {
  4017. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  4018. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  4019. solution.DialysateFlow = dialysateFlow
  4020. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  4021. dialysateFlow := dataBody["dialysate_flow"].(float64)
  4022. solution.DialysateFlow = dialysateFlow
  4023. }
  4024. }
  4025. if dataBody["dialysate_temperature"] != nil {
  4026. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  4027. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  4028. solution.DialysateTemperature = dialysateTemperature
  4029. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  4030. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  4031. solution.DialysateTemperature = dialysateTemperature
  4032. }
  4033. }
  4034. if dataBody["conductivity"] != nil {
  4035. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  4036. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  4037. solution.Conductivity = conductivity
  4038. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  4039. conductivity := dataBody["conductivity"].(float64)
  4040. solution.Conductivity = conductivity
  4041. }
  4042. }
  4043. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4044. remark := dataBody["remark"].(string)
  4045. solution.Remark = remark
  4046. }
  4047. if dataBody["dialysis_duration_hour"] != nil {
  4048. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  4049. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  4050. solution.DialysisDurationHour = dialysisDurationHour
  4051. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  4052. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  4053. solution.DialysisDurationHour = int64(dialysisDurationHour)
  4054. }
  4055. }
  4056. if dataBody["dialysis_duration_minute"] != nil {
  4057. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  4058. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  4059. solution.DialysisDurationMinute = dialysisDurationMinute
  4060. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  4061. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  4062. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  4063. }
  4064. }
  4065. if dataBody["target_ultrafiltration"] != nil {
  4066. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  4067. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  4068. solution.TargetUltrafiltration = targetUltrafiltration
  4069. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  4070. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  4071. solution.TargetUltrafiltration = targetUltrafiltration
  4072. }
  4073. }
  4074. if dataBody["dialysate_formulation"] != nil {
  4075. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  4076. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  4077. solution.DialysateFormulation = dialysateFormulation
  4078. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  4079. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  4080. solution.DialysateFormulation = int64(dialysateFormulation)
  4081. }
  4082. }
  4083. return
  4084. }
  4085. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  4086. dataBody := make(map[string]interface{}, 0)
  4087. err := json.Unmarshal(data, &dataBody)
  4088. utils.InfoLog(string(data))
  4089. if err != nil {
  4090. utils.ErrorLog(err.Error())
  4091. code = enums.ErrorCodeParamWrong
  4092. return
  4093. }
  4094. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  4095. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  4096. evaluation.WeightBefore = weightVefore
  4097. }
  4098. // fmt.Println(dataBody["dry_weight"])
  4099. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  4100. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  4101. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  4102. fmt.Println(additionalWeight)
  4103. evaluation.DryWeight = additionalWeight
  4104. }
  4105. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  4106. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  4107. fmt.Println(additionalWeight)
  4108. evaluation.AdditionalWeight = additionalWeight
  4109. }
  4110. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  4111. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  4112. evaluation.Temperature = Temperature
  4113. }
  4114. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  4115. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  4116. evaluation.SystolicBloodPressure = systolicBloodPressure
  4117. }
  4118. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  4119. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  4120. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  4121. }
  4122. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  4123. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  4124. evaluation.PulseFrequency = pulseFrequency
  4125. }
  4126. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  4127. breathingRate := dataBody["breathing_rate"].(string)
  4128. evaluation.BreathingRate = breathingRate
  4129. }
  4130. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  4131. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  4132. evaluation.LastPostDialysis = lastPostDialysis
  4133. }
  4134. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  4135. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  4136. evaluation.DialysisInterphase = dialysisInterphase
  4137. }
  4138. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  4139. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  4140. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  4141. }
  4142. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  4143. catheter, _ := dataBody["catheter"].(string)
  4144. evaluation.Catheter = catheter
  4145. }
  4146. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  4147. catheter_bend := int(dataBody["catheter_bend"].(float64))
  4148. evaluation.CatheterBend = catheter_bend
  4149. }
  4150. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  4151. Complication, _ := dataBody["complication"].(string)
  4152. evaluation.Complication = Complication
  4153. }
  4154. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4155. remark := dataBody["remark"].(string)
  4156. evaluation.Remark = remark
  4157. }
  4158. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  4159. machine_type := dataBody["machine_type"].(string)
  4160. evaluation.MachineType = machine_type
  4161. }
  4162. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  4163. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  4164. evaluation.BloodAccessPartId = blood_access_part_id
  4165. }
  4166. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  4167. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  4168. // evaluation.BloodAccessPartId = blood_access_part_id
  4169. //}
  4170. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  4171. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  4172. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  4173. }
  4174. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  4175. internal_fistula, _ := dataBody["internal_fistula"].(string)
  4176. evaluation.InternalFistula = internal_fistula
  4177. }
  4178. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  4179. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  4180. evaluation.InternalFistulaSkin = internal_fistula_skin
  4181. }
  4182. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  4183. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  4184. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  4185. evaluation.IsHemorrhage = is_hemorrhage
  4186. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  4187. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  4188. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  4189. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  4190. is_hemorrhage = 0
  4191. }
  4192. evaluation.IsHemorrhage = is_hemorrhage
  4193. if is_hemorrhage == 1 {
  4194. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  4195. hemorrhage, _ := dataBody["hemorrhage"].(string)
  4196. evaluation.Hemorrhage = hemorrhage
  4197. }
  4198. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  4199. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  4200. evaluation.HemorrhageOther = hemorrhage_other
  4201. }
  4202. }
  4203. } else {
  4204. evaluation.IsHemorrhage = 0
  4205. }
  4206. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  4207. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  4208. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  4209. }
  4210. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  4211. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  4212. evaluation.InternalFistulaOther = internal_fistula_other
  4213. }
  4214. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  4215. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  4216. evaluation.BloodAccessNoise = blood_access_noise
  4217. }
  4218. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  4219. //puncture_way := int64(dataBody["puncture_way"].(float64))
  4220. puncture_way := dataBody["puncture_way"].(string)
  4221. evaluation.PunctureWay = puncture_way
  4222. }
  4223. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  4224. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  4225. evaluation.VenousCatheterization = venous_catheterization
  4226. }
  4227. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  4228. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  4229. evaluation.VenousCatheterizationPart = venous_catheterization_part
  4230. }
  4231. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  4232. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  4233. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  4234. }
  4235. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  4236. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  4237. evaluation.DuctusArantii = ductus_arantii
  4238. }
  4239. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  4240. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  4241. evaluation.EmergencyTreatment = emergency_treatment
  4242. }
  4243. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  4244. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  4245. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  4246. }
  4247. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  4248. dialysis_count, _ := dataBody["dialysis_count"].(string)
  4249. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  4250. evaluation.DialysisCount = dialysis_count
  4251. }
  4252. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  4253. is_infect, _ := dataBody["is_infect"].(string)
  4254. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  4255. evaluation.IsInfect = infect
  4256. }
  4257. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  4258. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  4259. evaluation.Exposed = exposed
  4260. }
  4261. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  4262. skin, _ := dataBody["skin"].(string)
  4263. //skins, _ := strconv.ParseInt(skin, 10, 64)
  4264. evaluation.Skin = skin
  4265. }
  4266. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  4267. skin_other, _ := dataBody["skin_other"].(string)
  4268. evaluation.SkinOther = skin_other
  4269. }
  4270. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  4271. infect_other, _ := dataBody["infect_other"].(string)
  4272. evaluation.InfectOther = infect_other
  4273. }
  4274. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  4275. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  4276. evaluation.DuctusArantiiOther = ductus_arantii_other
  4277. }
  4278. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  4279. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  4280. evaluation.PunctureNeedle = punctureNeedle
  4281. }
  4282. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  4283. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  4284. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  4285. }
  4286. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  4287. pinholing := dataBody["pinholing"].(string)
  4288. evaluation.Phinholing = pinholing
  4289. }
  4290. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  4291. catheter_suture := dataBody["catheter_suture"].(string)
  4292. evaluation.CatheterSuture = catheter_suture
  4293. }
  4294. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  4295. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  4296. evaluation.CatheterSutureOther = catheter_suture_other
  4297. }
  4298. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  4299. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  4300. evaluation.UrineVolume = urine_volume
  4301. }
  4302. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  4303. edema := dataBody["edema"].(string)
  4304. evaluation.Edema = edema
  4305. }
  4306. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  4307. specialTreatment := dataBody["special_treatment"].(string)
  4308. evaluation.SpecialTreatment = specialTreatment
  4309. }
  4310. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  4311. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  4312. evaluation.CatheterMaintenance = catheter_maintenance
  4313. }
  4314. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  4315. thromubusType := int64(dataBody["thromubus_type"].(float64))
  4316. evaluation.ThromubusType = thromubusType
  4317. }
  4318. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  4319. thrombus_av := dataBody["thrombus_av"].(string)
  4320. evaluation.ThrombusAv = thrombus_av
  4321. }
  4322. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  4323. thromubus_a := dataBody["thromubus_a"].(string)
  4324. evaluation.ThromubusA = thromubus_a
  4325. }
  4326. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  4327. thromubus_v := dataBody["thromubus_v"].(string)
  4328. evaluation.ThromubusV = thromubus_v
  4329. }
  4330. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  4331. dehydration := dataBody["dehydration"].(string)
  4332. evaluation.Dehydration = dehydration
  4333. }
  4334. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  4335. period := int64(dataBody["period"].(float64))
  4336. evaluation.Period = period
  4337. }
  4338. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  4339. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  4340. evaluation.EstimatedFoodIntake = estimated_food_intake
  4341. }
  4342. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  4343. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  4344. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  4345. }
  4346. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  4347. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  4348. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  4349. }
  4350. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  4351. urea_befor := dataBody["urea_befor"].(string)
  4352. evaluation.UreaBefor = urea_befor
  4353. }
  4354. if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
  4355. suction := dataBody["suction"].(string)
  4356. evaluation.Suction = suction
  4357. }
  4358. if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
  4359. weight_befor_remake := dataBody["weight_befor_remake"].(string)
  4360. evaluation.WeightBeforRemake = weight_befor_remake
  4361. }
  4362. if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
  4363. height := dataBody["height"].(string)
  4364. evaluation.Height = height
  4365. }
  4366. if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
  4367. age := dataBody["age"].(string)
  4368. evaluation.Age = age
  4369. }
  4370. if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
  4371. his_department := dataBody["his_department"].(string)
  4372. evaluation.HisDepartment = his_department
  4373. }
  4374. if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
  4375. his_bed := dataBody["his_bed"].(string)
  4376. evaluation.HisBed = his_bed
  4377. }
  4378. if dataBody["point_puncture"] != nil && reflect.TypeOf(dataBody["point_puncture"]).String() == "string" {
  4379. point_puncture := dataBody["point_puncture"].(string)
  4380. evaluation.PointPuncture = point_puncture
  4381. }
  4382. if dataBody["catheter_evaluation_program"] != nil && reflect.TypeOf(dataBody["catheter_evaluation_program"]).String() == "string" {
  4383. catheter_evaluation_program := dataBody["catheter_evaluation_program"].(string)
  4384. evaluation.CatheterEvaluationProgram = catheter_evaluation_program
  4385. }
  4386. if dataBody["skin_site_catheterization"] != nil && reflect.TypeOf(dataBody["skin_site_catheterization"]).String() == "string" {
  4387. skin_site_catheterization := dataBody["skin_site_catheterization"].(string)
  4388. evaluation.SkinSiteCatheterization = skin_site_catheterization
  4389. }
  4390. if dataBody["whether_unobstructed"] != nil && reflect.TypeOf(dataBody["whether_unobstructed"]).String() == "float64" {
  4391. whether_unobstructed := int64(dataBody["whether_unobstructed"].(float64))
  4392. evaluation.WhetherUnobstructed = whether_unobstructed
  4393. }
  4394. if dataBody["lien_necessary"] != nil && reflect.TypeOf(dataBody["lien_necessary"]).String() == "float64" {
  4395. lien_necessary := int64(dataBody["lien_necessary"].(float64))
  4396. evaluation.LienNecessary = lien_necessary
  4397. }
  4398. if dataBody["pathway_formation_time"] != nil && reflect.TypeOf(dataBody["pathway_formation_time"]).String() == "string" {
  4399. pathway_formation_time := dataBody["pathway_formation_time"].(string)
  4400. timeLayout := "2006-01-02"
  4401. loc, _ := time.LoadLocation("Local")
  4402. var startTime int64
  4403. if len(pathway_formation_time) > 0 {
  4404. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  4405. startTime = theTime.Unix()
  4406. }
  4407. evaluation.PathwayFormationTime = startTime
  4408. }
  4409. if dataBody["befor_symptoms"] != nil && reflect.TypeOf(dataBody["befor_symptoms"]).String() == "string" {
  4410. befor_symptoms := dataBody["befor_symptoms"].(string)
  4411. evaluation.BeforSymptoms = befor_symptoms
  4412. }
  4413. if dataBody["washing_time"] != nil && reflect.TypeOf(dataBody["washing_time"]).String() == "string" {
  4414. washing_time, _ := dataBody["washing_time"].(string)
  4415. evaluation.WashingTime = washing_time
  4416. }
  4417. if dataBody["warsh_count"] != nil && reflect.TypeOf(dataBody["warsh_count"]).String() == "string" {
  4418. warsh_count, _ := dataBody["warsh_count"].(string)
  4419. evaluation.WarshCount = warsh_count
  4420. }
  4421. if dataBody["puncture_needle_direction"] != nil && reflect.TypeOf(dataBody["puncture_needle_direction"]).String() == "string" {
  4422. puncture_needle_direction, _ := dataBody["puncture_needle_direction"].(string)
  4423. evaluation.PunctureNeedleDirection = puncture_needle_direction
  4424. }
  4425. if dataBody["symptom_before_dialysis_other"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis_other"]).String() == "string" {
  4426. symptom_before_dialysis_other, _ := dataBody["symptom_before_dialysis_other"].(string)
  4427. evaluation.SymptomBeforeDialysisOther = symptom_before_dialysis_other
  4428. }
  4429. return
  4430. }
  4431. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  4432. dataBody := make(map[string]interface{}, 0)
  4433. err := json.Unmarshal(data, &dataBody)
  4434. if err != nil {
  4435. utils.ErrorLog(err.Error())
  4436. code = enums.ErrorCodeParamWrong
  4437. return
  4438. }
  4439. timeLayout := "2006-01-02"
  4440. loc, _ := time.LoadLocation("Local")
  4441. isChild := false
  4442. if action == "create" {
  4443. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4444. utils.ErrorLog("advice_type")
  4445. code = enums.ErrorCodeParamWrong
  4446. return
  4447. }
  4448. adviceType := int64(dataBody["advice_type"].(float64))
  4449. if adviceType != 1 && adviceType != 2 {
  4450. utils.ErrorLog("advice_type != 1&&2")
  4451. code = enums.ErrorCodeParamWrong
  4452. return
  4453. }
  4454. advice.AdviceType = adviceType
  4455. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4456. utils.ErrorLog("advice_date")
  4457. code = enums.ErrorCodeParamWrong
  4458. return
  4459. }
  4460. adviceDate, _ := dataBody["advice_date"].(string)
  4461. if len(adviceDate) == 0 {
  4462. utils.ErrorLog("len(adviceDate) == 0")
  4463. code = enums.ErrorCodeParamWrong
  4464. return
  4465. }
  4466. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4467. if err != nil {
  4468. utils.ErrorLog(err.Error())
  4469. code = enums.ErrorCodeParamWrong
  4470. return
  4471. }
  4472. advice.AdviceDate = theTime.Unix()
  4473. advice.RecordDate = theTime.Unix()
  4474. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  4475. parentId := int64(dataBody["parent_id"].(float64))
  4476. advice.ParentId = parentId
  4477. if parentId > 0 {
  4478. isChild = true
  4479. }
  4480. }
  4481. } else {
  4482. isChild = advice.ParentId > 0
  4483. }
  4484. if !isChild {
  4485. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4486. utils.ErrorLog("start_time")
  4487. code = enums.ErrorCodeParamWrong
  4488. return
  4489. }
  4490. startTime, _ := dataBody["start_time"].(string)
  4491. if len(startTime) == 0 {
  4492. utils.ErrorLog("len(start_time) == 0")
  4493. code = enums.ErrorCodeParamWrong
  4494. return
  4495. }
  4496. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  4497. if err != nil {
  4498. utils.ErrorLog(err.Error())
  4499. code = enums.ErrorCodeParamWrong
  4500. return
  4501. }
  4502. advice.StartTime = theTime.Unix()
  4503. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  4504. deliveryWay, _ := dataBody["delivery_way"].(string)
  4505. advice.DeliveryWay = deliveryWay
  4506. }
  4507. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  4508. executionFrequency, _ := dataBody["execution_frequency"].(string)
  4509. advice.ExecutionFrequency = executionFrequency
  4510. }
  4511. }
  4512. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  4513. deliveryWay, _ := dataBody["delivery_way"].(string)
  4514. advice.DeliveryWay = deliveryWay
  4515. }
  4516. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  4517. executionFrequency, _ := dataBody["execution_frequency"].(string)
  4518. advice.ExecutionFrequency = executionFrequency
  4519. }
  4520. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  4521. utils.ErrorLog("advice_name")
  4522. code = enums.ErrorCodeParamWrong
  4523. return
  4524. }
  4525. adviceName, _ := dataBody["advice_name"].(string)
  4526. if len(adviceName) == 0 {
  4527. utils.ErrorLog("len(advice_name) == 0")
  4528. code = enums.ErrorCodeParamWrong
  4529. return
  4530. }
  4531. advice.AdviceName = adviceName
  4532. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  4533. adviceDsc, _ := dataBody["advice_desc"].(string)
  4534. advice.AdviceDesc = adviceDsc
  4535. }
  4536. if dataBody["way"] == nil {
  4537. advice.Way = 0
  4538. } else {
  4539. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  4540. way := int64(dataBody["way"].(float64))
  4541. advice.Way = way
  4542. }
  4543. }
  4544. if dataBody["drug_id"] == nil {
  4545. advice.DrugId = 0
  4546. } else {
  4547. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  4548. drug_id := int64(dataBody["drug_id"].(float64))
  4549. advice.DrugId = drug_id
  4550. }
  4551. }
  4552. if dataBody["drug_name_id"] == nil {
  4553. advice.DrugNameId = 0
  4554. } else {
  4555. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  4556. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  4557. advice.DrugNameId = drug_name_id
  4558. }
  4559. }
  4560. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  4561. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  4562. advice.SingleDose = singleDose
  4563. }
  4564. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  4565. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  4566. advice.SingleDoseUnit = singleDoseUnit
  4567. }
  4568. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  4569. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  4570. advice.DrugSpec = drugSpec
  4571. }
  4572. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  4573. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  4574. advice.DrugSpecUnit = drugSpecUnit
  4575. }
  4576. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  4577. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  4578. advice.PrescribingNumber = prescribingNumber
  4579. }
  4580. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  4581. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  4582. advice.PrescribingNumberUnit = prescribingNumberUnit
  4583. }
  4584. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4585. remark, _ := dataBody["remark"].(string)
  4586. advice.Remark = remark
  4587. }
  4588. return
  4589. }
  4590. func (c *PatientApiController) GetPatientEducation() {
  4591. patientID, _ := c.GetInt64("patient_id", 0)
  4592. page, _ := c.GetInt64("page", 0)
  4593. limit, _ := c.GetInt64("limit", 0)
  4594. startTime := c.GetString("start_time", "")
  4595. endTime := c.GetString("end_time", "")
  4596. if page <= 0 {
  4597. page = 1
  4598. }
  4599. if limit <= 0 {
  4600. limit = 10
  4601. }
  4602. if patientID <= 0 {
  4603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4604. return
  4605. }
  4606. timeLayout := "2006-01-02"
  4607. loc, _ := time.LoadLocation("Local")
  4608. var theStartTIme int64
  4609. if len(startTime) > 0 {
  4610. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4611. if err != nil {
  4612. theStartTIme = 0
  4613. }
  4614. theStartTIme = theTime.Unix()
  4615. }
  4616. var theEndtTIme int64
  4617. if len(endTime) > 0 {
  4618. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4619. if err != nil {
  4620. theEndtTIme = 0
  4621. }
  4622. theEndtTIme = theTime.Unix()
  4623. }
  4624. adminUserInfo := c.GetMobileAdminUserInfo()
  4625. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  4626. c.ServeSuccessJSON(map[string]interface{}{
  4627. "total": total,
  4628. "edus": edus,
  4629. })
  4630. return
  4631. }
  4632. func (c *PatientApiController) GetPatientSchedulesList() {
  4633. patientID, _ := c.GetInt64("patient_id", 0)
  4634. page, _ := c.GetInt64("page", 0)
  4635. limit, _ := c.GetInt64("limit", 0)
  4636. if patientID <= 0 {
  4637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4638. return
  4639. }
  4640. adminUserInfo := c.GetMobileAdminUserInfo()
  4641. todayTime := time.Now().Format("2006-01-02")
  4642. timeLayout := "2006-01-02 15:04:05"
  4643. loc, _ := time.LoadLocation("Local")
  4644. var theStartTime int64
  4645. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  4646. theStartTime = theTime.Unix()
  4647. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  4648. if len(schedules) > 0 {
  4649. for index, item := range schedules {
  4650. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  4651. schedules[index].Week = int64(week)
  4652. }
  4653. }
  4654. c.ServeSuccessJSON(map[string]interface{}{
  4655. "schedules": schedules,
  4656. })
  4657. return
  4658. }
  4659. func (c *PatientApiController) GetRecords() {
  4660. patientID, _ := c.GetInt64("patient_id", 0)
  4661. page, _ := c.GetInt64("page", 0)
  4662. limit, _ := c.GetInt64("limit", 0)
  4663. startTime := c.GetString("start_time", "")
  4664. endTime := c.GetString("end_time", "")
  4665. mode_id, _ := c.GetInt64("mode_id", 0)
  4666. if page <= 0 {
  4667. page = 1
  4668. }
  4669. if limit <= 0 {
  4670. limit = 10
  4671. }
  4672. if patientID <= 0 {
  4673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4674. return
  4675. }
  4676. timeLayout := "2006-01-02"
  4677. loc, _ := time.LoadLocation("Local")
  4678. var theStartTIme int64
  4679. if len(startTime) > 0 {
  4680. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4681. if err != nil {
  4682. theStartTIme = 0
  4683. }
  4684. theStartTIme = theTime.Unix()
  4685. }
  4686. var theEndtTIme int64
  4687. if len(endTime) > 0 {
  4688. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4689. if err != nil {
  4690. theEndtTIme = 0
  4691. }
  4692. theEndtTIme = theTime.Unix()
  4693. }
  4694. adminUserInfo := c.GetMobileAdminUserInfo()
  4695. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  4696. c.ServeSuccessJSON(map[string]interface{}{
  4697. "total": total,
  4698. "records": records,
  4699. })
  4700. return
  4701. }
  4702. func (c *PatientApiController) GetPatientMonitor() {
  4703. partition, _ := c.GetInt64("partition")
  4704. monitorDate := c.GetString("date")
  4705. patient_id, _ := c.GetInt64("patient_id")
  4706. timeLayout := "2006-01-02"
  4707. loc, _ := time.LoadLocation("Local")
  4708. var theStartTime int64
  4709. if len(monitorDate) > 0 {
  4710. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  4711. if err != nil {
  4712. theStartTime = 0
  4713. }
  4714. theStartTime = theTime.Unix()
  4715. }
  4716. adminInfo := c.GetMobileAdminUserInfo()
  4717. orgID := adminInfo.Org.Id
  4718. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  4719. if err != nil {
  4720. c.ErrorLog("获取排班信息失败:%v", err)
  4721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4722. } else {
  4723. if len(monitor) > 0 {
  4724. //获取所有床位
  4725. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  4726. //获取所有分区
  4727. zoneList, _ := service.GetAllZoneByList(orgID)
  4728. //获取透析处方
  4729. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  4730. //获取透前评估
  4731. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  4732. //获取上机
  4733. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  4734. //获取透后
  4735. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  4736. //获取透后监测
  4737. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  4738. //获取所有的患者
  4739. patients, _ := service.GetAllPatientListByListOne(orgID)
  4740. for _, it := range patients {
  4741. if orgID == 10445 {
  4742. if theStartTime <= 1703952000 {
  4743. listOne, _ := service.GetDialysisOrderCountTwentyEight(orgID, it.ID, theStartTime)
  4744. it.TotalDialysis = listOne.Count
  4745. }
  4746. if theStartTime >= 1704038400 {
  4747. listOrder, _ := service.GetDialysisOrderCountTenEight(it.ID, theStartTime)
  4748. it.TotalDialysis = listOrder.Count
  4749. }
  4750. }
  4751. }
  4752. //获取所有透析模式
  4753. treatments, _ := service.GetAllTreatModeByList(orgID)
  4754. for key, item := range monitor {
  4755. // 获取床位信息
  4756. for _, it := range numberList {
  4757. if item.BedId == it.ID {
  4758. monitor[key].DeviceNumber = it
  4759. break
  4760. }
  4761. }
  4762. //获取分区信息
  4763. for _, it := range zoneList {
  4764. if item.PartitionId == it.ID {
  4765. monitor[key].DeviceZone = it
  4766. }
  4767. }
  4768. for _, prescription := range prescriptions {
  4769. if item.PatientId == prescription.PatientId {
  4770. monitor[key].Prescription = prescription
  4771. break
  4772. }
  4773. }
  4774. // 透前评估
  4775. for _, assessmentBefore := range assessmentBefores {
  4776. if item.PatientId == assessmentBefore.PatientId {
  4777. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  4778. break
  4779. }
  4780. }
  4781. // 透析上下机
  4782. for _, dialysisOrder := range dialysisOrders {
  4783. if item.PatientId == dialysisOrder.PatientId {
  4784. monitor[key].DialysisOrder = dialysisOrder
  4785. break
  4786. }
  4787. }
  4788. // 治疗小节
  4789. for _, afterDislysis := range AssessmentAfterDislysis {
  4790. if item.PatientId == afterDislysis.PatientId {
  4791. monitor[key].AssessmentAfterDislysis = afterDislysis
  4792. break
  4793. }
  4794. }
  4795. for _, it := range monitorlist {
  4796. if item.PatientId == it.PatientId {
  4797. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  4798. }
  4799. }
  4800. for _, patient := range patients {
  4801. if item.PatientId == patient.ID {
  4802. monitor[key].MonitorPatients = patient
  4803. break
  4804. }
  4805. }
  4806. for _, treatment := range treatments {
  4807. if item.ModeId == treatment.ID {
  4808. monitor[key].TreatmentMode = treatment
  4809. break
  4810. }
  4811. }
  4812. }
  4813. }
  4814. }
  4815. //获取患者的透析次数
  4816. //count, err := service.GetDialysisCount(orgID, partition)
  4817. patients, err := service.GetAllpatientFourty(orgID)
  4818. if err == nil {
  4819. c.ServeSuccessJSON(map[string]interface{}{
  4820. "monitor": monitor,
  4821. //"patientCount": count,
  4822. "patients": patients,
  4823. })
  4824. } else {
  4825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4826. }
  4827. }
  4828. // /m/api/monitor/patient [get] 搜索病人的测量记录
  4829. // @param keyword:string 病人姓名或透析号
  4830. // @param page:int
  4831. func (this *PatientApiController) SearchMonitorPatient() {
  4832. keyword := this.GetString("keyword")
  4833. page, _ := this.GetInt("page")
  4834. if page <= 0 {
  4835. page = 1
  4836. }
  4837. if len(keyword) == 0 {
  4838. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4839. return
  4840. }
  4841. adminUserInfo := this.GetMobileAdminUserInfo()
  4842. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  4843. if getMonitorErr != nil {
  4844. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4845. return
  4846. } else {
  4847. this.ServeSuccessJSON(map[string]interface{}{
  4848. "monitor": monitors,
  4849. })
  4850. }
  4851. }
  4852. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  4853. id, _ := c.GetInt64("id", 0)
  4854. page, _ := c.GetInt64("page", 0)
  4855. limit, _ := c.GetInt64("limit", 0)
  4856. if id <= 0 {
  4857. c.ServeSuccessJSON(map[string]interface{}{
  4858. "solutions": nil,
  4859. })
  4860. return
  4861. }
  4862. if page <= 0 {
  4863. page = 1
  4864. }
  4865. if limit <= 0 {
  4866. limit = 10
  4867. }
  4868. adminInfo := c.GetMobileAdminUserInfo()
  4869. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  4870. c.ServeSuccessJSON(map[string]interface{}{
  4871. "solutions": solutions,
  4872. "total": total,
  4873. })
  4874. return
  4875. }
  4876. // GetDoctorAdvices 医嘱列表
  4877. func (c *PatientApiController) GetDoctorAdvices() {
  4878. id, _ := c.GetInt64("id", 0)
  4879. adviceType, _ := c.GetInt64("advice_type", 0)
  4880. stopType, _ := c.GetInt64("stop_state", 0)
  4881. startTime := c.GetString("start_time", "")
  4882. endTime := c.GetString("end_time", "")
  4883. keywords := c.GetString("keywords", "")
  4884. need, _ := c.GetInt64("need_doctor", 0)
  4885. adminUserInfo := c.GetMobileAdminUserInfo()
  4886. timeLayout := "2006-01-02"
  4887. loc, _ := time.LoadLocation("Local")
  4888. var theStartTIme int64
  4889. if len(startTime) > 0 {
  4890. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4891. if err != nil {
  4892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4893. return
  4894. }
  4895. theStartTIme = theTime.Unix()
  4896. }
  4897. var theEndtTIme int64
  4898. if len(endTime) > 0 {
  4899. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  4900. if err != nil {
  4901. utils.ErrorLog(err.Error())
  4902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4903. return
  4904. }
  4905. theEndtTIme = theTime.Unix()
  4906. }
  4907. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  4908. if need == 1 {
  4909. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4910. c.ServeSuccessJSON(map[string]interface{}{
  4911. "advices": advices,
  4912. "total": total,
  4913. "users": users,
  4914. })
  4915. } else {
  4916. c.ServeSuccessJSON(map[string]interface{}{
  4917. "advices": advices,
  4918. "total": total,
  4919. "users": []string{},
  4920. })
  4921. }
  4922. return
  4923. }
  4924. func (c *PatientApiController) GetPrintDialysisOrder() {
  4925. xtno := c.GetString("xtno")
  4926. xtdate := c.GetString("xtdate")
  4927. timeLayout := "2006-01-02"
  4928. loc, _ := time.LoadLocation("Local")
  4929. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  4930. if err != nil {
  4931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4932. return
  4933. }
  4934. xttime := theTime.Unix()
  4935. //获取当前日期月份的第一天
  4936. firstmonth := service.GetFirstDateOfMonth(theTime)
  4937. firstMonthDate := firstmonth.Unix()
  4938. operatorIDs := make([]int64, 0)
  4939. adminUserInfo := c.GetMobileAdminUserInfo()
  4940. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4941. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  4942. //透析单
  4943. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4944. if dialysisOrder != nil {
  4945. if dialysisOrder.FinishNurse > 0 {
  4946. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  4947. }
  4948. if dialysisOrder.StartNurse > 0 {
  4949. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  4950. }
  4951. }
  4952. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4953. //透前评估
  4954. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4955. //透后评估
  4956. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4957. if AssessmentAfterDislysis.Modifier > 0 {
  4958. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  4959. }
  4960. //透析处方
  4961. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4962. if dialysisPrescription.PrescriptionDoctor > 0 {
  4963. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  4964. }
  4965. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4966. patientInfo.TotalDialysis = dialysis_count
  4967. //临时医嘱
  4968. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4969. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4970. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  4971. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  4972. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4973. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4974. if adminUserInfo.Org.Id != 10489 {
  4975. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  4976. for _, item := range projects {
  4977. cnt, _ := strconv.ParseFloat(item.Count, 64)
  4978. var advice models.HisDoctorAdviceInfo
  4979. advice.ID = item.ID
  4980. advice.Checker = item.Checker
  4981. advice.CheckTime = item.CheckTime
  4982. advice.CheckState = item.CheckState
  4983. advice.ExecutionState = item.ExecutionState
  4984. advice.ExecutionStaff = item.ExecutionStaff
  4985. //advice.PrescribingNumber = float64(item.Count)
  4986. advice.PrescribingNumber = cnt
  4987. advice.PrescribingNumberUnit = item.Unit
  4988. advice.AdviceDoctor = item.Doctor
  4989. advice.Remark = item.Remark
  4990. if item.Type == 3 {
  4991. advice.AdviceName = item.GoodInfo.GoodName
  4992. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  4993. } else if item.Type == 2 {
  4994. advice.AdviceName = item.HisProject.ProjectName
  4995. }
  4996. advice.StartTime = item.StartTime
  4997. hisAdvice = append(hisAdvice, &advice)
  4998. }
  4999. }
  5000. }
  5001. if len(DoctorAdvice) > 0 {
  5002. for _, item := range DoctorAdvice {
  5003. if item.AdviceDoctor > 0 {
  5004. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  5005. }
  5006. if item.ExecutionStaff > 0 {
  5007. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  5008. }
  5009. if item.Checker > 0 {
  5010. operatorIDs = append(operatorIDs, item.Checker)
  5011. }
  5012. }
  5013. }
  5014. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5015. //透析监测
  5016. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5017. //透析小结
  5018. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5019. //接诊评估
  5020. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5021. if receiverTreatmentAccess.Condition == 1 {
  5022. if len(receiverTreatmentAccess.AdmissionNumber) == 0 || receiverTreatmentAccess.AdmissionNumber == "" {
  5023. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, patientInfo.ID)
  5024. receiverTreatmentAccess.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  5025. receiverTreatmentAccess.HisDepartment = lastAcceptTreatment.HisDepartment
  5026. receiverTreatmentAccess.HisBed = lastAcceptTreatment.HisBed
  5027. }
  5028. }
  5029. //相关操作对应的操作人
  5030. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  5031. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  5032. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  5033. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5034. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  5035. lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  5036. numberList, _ := service.GetAllBedNumberList(adminUserInfo.Org.Id)
  5037. if config.IsOpen == 1 {
  5038. c.ServeSuccessJSON(map[string]interface{}{
  5039. "users": adminUser,
  5040. "patientInfo": patientInfo,
  5041. "PredialysisEvaluation": PredialysisEvaluation,
  5042. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  5043. "dialysisPrescription": dialysisPrescription,
  5044. "advices": hisAdvice,
  5045. "monitors": Record,
  5046. "summary": TreatmentSummary,
  5047. "receiverTreatmentAccess": receiverTreatmentAccess,
  5048. "dialysisOrder": dialysisOrder,
  5049. "operators": operators,
  5050. "org_template_info": templateInfo,
  5051. "check": check,
  5052. "dialysiscount": dialysiscount,
  5053. "last_order": last_order,
  5054. "projects": projects,
  5055. "project_config": project_config,
  5056. "lastWeight": lastWeight,
  5057. "lastSchedule": lastSchedule,
  5058. "DoctorAdvice": DoctorAdvice,
  5059. "hisAdvice": hisAdvice,
  5060. "numberList": numberList,
  5061. })
  5062. }
  5063. if config.IsOpen == 0 || config.IsOpen == 2 {
  5064. c.ServeSuccessJSON(map[string]interface{}{
  5065. "users": adminUser,
  5066. "patientInfo": patientInfo,
  5067. "PredialysisEvaluation": PredialysisEvaluation,
  5068. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  5069. "dialysisPrescription": dialysisPrescription,
  5070. "advices": DoctorAdvice,
  5071. "monitors": Record,
  5072. "summary": TreatmentSummary,
  5073. "receiverTreatmentAccess": receiverTreatmentAccess,
  5074. "dialysisOrder": dialysisOrder,
  5075. "operators": operators,
  5076. "org_template_info": templateInfo,
  5077. "check": check,
  5078. "dialysiscount": dialysiscount,
  5079. "last_order": last_order,
  5080. "projects": projects,
  5081. "project_config": project_config,
  5082. "lastWeight": lastWeight,
  5083. "lastSchedule": lastSchedule,
  5084. "DoctorAdvice": DoctorAdvice,
  5085. "hisAdvice": hisAdvice,
  5086. "numberList": numberList,
  5087. })
  5088. }
  5089. }
  5090. func (c *PatientApiController) CreateGroupAdvice() {
  5091. is_child, _ := c.GetInt64("is_child", 0)
  5092. if is_child == 1 {
  5093. patient, _ := c.GetInt64("id", 0)
  5094. if patient <= 0 {
  5095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5096. return
  5097. }
  5098. adminUserInfo := c.GetMobileAdminUserInfo()
  5099. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  5100. if patientInfo.ID == 0 {
  5101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5102. return
  5103. }
  5104. group_no, _ := c.GetInt64("group_no")
  5105. if group_no <= 0 {
  5106. group_no = 0
  5107. }
  5108. dataBody := make(map[string]interface{}, 0)
  5109. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5110. if err != nil {
  5111. utils.ErrorLog(err.Error())
  5112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5113. return
  5114. }
  5115. timeLayout := "2006-01-02"
  5116. loc, _ := time.LoadLocation("Local")
  5117. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5118. utils.ErrorLog("advice_type")
  5119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5120. return
  5121. }
  5122. adviceType := int64(dataBody["advice_type"].(float64))
  5123. if adviceType != 1 && adviceType != 2 {
  5124. utils.ErrorLog("advice_type != 1&&2")
  5125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5126. return
  5127. }
  5128. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5129. utils.ErrorLog("start_time")
  5130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5131. return
  5132. }
  5133. startTime2, _ := dataBody["start_time"].(string)
  5134. time_arr := strings.Split(startTime2, " ")
  5135. if len(time_arr) > 0 {
  5136. startTime2 = time_arr[0]
  5137. }
  5138. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5139. utils.ErrorLog("advice_date")
  5140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5141. return
  5142. }
  5143. advice_date, _ := dataBody["advice_date"].(string)
  5144. var advicedateunix int64
  5145. if len(advice_date) > 0 {
  5146. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  5147. if err != nil {
  5148. fmt.Println(err)
  5149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5150. return
  5151. }
  5152. advicedateunix = theTime.Unix()
  5153. }
  5154. adviceDate := startTime2
  5155. if len(adviceDate) == 0 {
  5156. utils.ErrorLog("len(adviceDate) == 0")
  5157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5158. return
  5159. }
  5160. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  5161. if err != nil {
  5162. utils.ErrorLog(err.Error())
  5163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5164. return
  5165. }
  5166. AdviceDate := advicedateunix
  5167. RecordDate := advicedateunix
  5168. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5169. utils.ErrorLog("start_time")
  5170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5171. return
  5172. }
  5173. startTime, _ := dataBody["start_time"].(string)
  5174. if len(startTime) == 0 {
  5175. utils.ErrorLog("len(start_time) == 0")
  5176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5177. return
  5178. }
  5179. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  5180. theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
  5181. if err != nil {
  5182. utils.ErrorLog(err.Error())
  5183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5184. return
  5185. }
  5186. StartTime := theTime.Unix()
  5187. Remark := ""
  5188. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5189. remark, _ := dataBody["remark"].(string)
  5190. Remark = remark
  5191. }
  5192. Startdate := int64(dataBody["record_date"].(float64))
  5193. var advices []*models.GroupAdvice
  5194. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  5195. utils.ErrorLog("adviceNames")
  5196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5197. return
  5198. }
  5199. adviceNames := dataBody["adviceNames"].([]interface{})
  5200. for _, adviceNameMap := range adviceNames {
  5201. adviceNameM := adviceNameMap.(map[string]interface{})
  5202. var advice models.GroupAdvice
  5203. advice.Remark = Remark
  5204. advice.AdviceType = adviceType
  5205. advice.StartTime = StartTime
  5206. if adminUserInfo.Org.Id == 10340 {
  5207. advice.AdviceDate = AdviceDate
  5208. advice.RecordDate = RecordDate
  5209. }
  5210. if adminUserInfo.Org.Id != 10340 {
  5211. advice.AdviceDate = theTimeOne.Unix()
  5212. advice.RecordDate = theTimeOne.Unix()
  5213. }
  5214. advice.Status = 1
  5215. advice.CreatedTime = time.Now().Unix()
  5216. advice.UpdatedTime = time.Now().Unix()
  5217. advice.StopState = 2
  5218. advice.ExecutionState = 2
  5219. advice.UserOrgId = adminUserInfo.Org.Id
  5220. advice.PatientId = patientInfo.ID
  5221. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5222. advice.IsSettle = 2
  5223. //入口
  5224. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  5225. if errcode > 0 {
  5226. c.ServeFailJSONWithSGJErrorCode(errcode)
  5227. return
  5228. }
  5229. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  5230. subdrugs := adviceNameM["subdrugs"].([]interface{})
  5231. if len(subdrugs) > 0 {
  5232. for _, subdrug := range subdrugs {
  5233. var s models.GroupAdvice
  5234. s.Remark = Remark
  5235. s.AdviceType = adviceType
  5236. s.StartTime = StartTime
  5237. s.AdviceDate = AdviceDate
  5238. s.RecordDate = RecordDate
  5239. s.Status = 1
  5240. s.CreatedTime = time.Now().Unix()
  5241. s.UpdatedTime = time.Now().Unix()
  5242. s.StopState = 2
  5243. s.ExecutionState = 2
  5244. s.UserOrgId = adminUserInfo.Org.Id
  5245. s.PatientId = patientInfo.ID
  5246. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  5247. s.IsSettle = 2
  5248. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  5249. if errcode > 0 {
  5250. c.ServeFailJSONWithSGJErrorCode(errcode)
  5251. return
  5252. }
  5253. advice.Children = append(advice.Children, &s)
  5254. }
  5255. }
  5256. }
  5257. //长沙南雅
  5258. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  5259. //查询该患者今日有没有双人核对
  5260. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
  5261. if check.ID > 0 {
  5262. advice.Checker = check.Modifier
  5263. advice.CheckState = 1
  5264. advice.CheckTime = time.Now().Unix()
  5265. }
  5266. }
  5267. advices = append(advices, &advice)
  5268. }
  5269. // 查询信息规挡的设置天数
  5270. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5271. if infor.ID > 0 && infor.WeekDay > 0 {
  5272. var cha_time int64
  5273. timeNowStr := time.Now().Format("2006-01-02")
  5274. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5275. //今日的日期减去设置的日期
  5276. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5277. if cha_time >= Startdate {
  5278. //查询审核是否允许
  5279. infor, _ := service.GetDialysisInformationByRecordDate(patient, Startdate, adminUserInfo.Org.Id, 5)
  5280. //申请状态不允许的情况 拒绝修改
  5281. if infor.ApplicationStatus != 1 {
  5282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5283. return
  5284. }
  5285. }
  5286. }
  5287. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  5288. for _, item := range advices {
  5289. //记录日志
  5290. byterequest, _ := json.Marshal(item)
  5291. adviceLog := models.XtDoctorAdviceLog{
  5292. UserOrgId: item.UserOrgId,
  5293. PatientId: item.PatientId,
  5294. AdminUserId: adminUserInfo.AdminUser.Id,
  5295. Module: 1,
  5296. ErrLog: string(byterequest),
  5297. Status: 1,
  5298. Ctime: time.Now().Unix(),
  5299. Mtime: 0,
  5300. Source: "手机端新增医嘱",
  5301. RecordDate: item.AdviceDate,
  5302. }
  5303. service.CreateDoctorAdviceLog(adviceLog)
  5304. }
  5305. finish := models.XtDialysisFinish{
  5306. IsFinish: 1,
  5307. UserOrgId: adminUserInfo.Org.Id,
  5308. Status: 1,
  5309. Ctime: time.Now().Unix(),
  5310. Mtime: 0,
  5311. Module: 4,
  5312. RecordDate: advicedateunix,
  5313. Sourse: 1,
  5314. PatientId: patient,
  5315. }
  5316. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, advicedateunix, 4, patient)
  5317. if dialysisFinish.ID == 0 {
  5318. service.CreateDialysisFinish(finish)
  5319. }
  5320. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  5321. redis := service.RedisClient()
  5322. //清空key 值
  5323. redis.Set(key, "", time.Second)
  5324. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5325. redis.Set(keyOne, "", time.Second)
  5326. defer redis.Close()
  5327. if createErr != nil {
  5328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5329. return
  5330. }
  5331. c.ServeSuccessJSON(map[string]interface{}{
  5332. "msg": "ok",
  5333. "advices": newAdvices,
  5334. })
  5335. return
  5336. } else if is_child == 2 {
  5337. patient, _ := c.GetInt64("id", 0)
  5338. if patient <= 0 {
  5339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5340. return
  5341. }
  5342. adminUserInfo := c.GetMobileAdminUserInfo()
  5343. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  5344. if patientInfo.ID == 0 {
  5345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5346. return
  5347. }
  5348. var advice models.DoctorAdvice
  5349. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  5350. if code > 0 {
  5351. c.ServeFailJSONWithSGJErrorCode(code)
  5352. return
  5353. }
  5354. if advice.ParentId > 0 {
  5355. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  5356. if old.ID == 0 || old.PatientId != patient {
  5357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  5358. return
  5359. }
  5360. if old.StopState == 1 || old.ExecutionState == 1 {
  5361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  5362. return
  5363. }
  5364. if old.ParentId > 0 {
  5365. advice.ParentId = old.ParentId
  5366. }
  5367. advice.StartTime = old.StartTime
  5368. advice.AdviceDoctor = old.AdviceDoctor
  5369. advice.DeliveryWay = old.DeliveryWay
  5370. advice.ExecutionFrequency = old.ExecutionFrequency
  5371. advice.GroupNo = old.GroupNo
  5372. }
  5373. advice.Status = 1
  5374. advice.CreatedTime = time.Now().Unix()
  5375. advice.UpdatedTime = time.Now().Unix()
  5376. advice.StopState = 2
  5377. advice.ExecutionState = 2
  5378. advice.UserOrgId = adminUserInfo.Org.Id
  5379. advice.PatientId = patient
  5380. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5381. advice.IsSettle = 2
  5382. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  5383. if advice.PrescribingNumber == 0 {
  5384. advice.PrescribingNumber = 1
  5385. }
  5386. //查询该患者今日有没有双人核对
  5387. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, advice.AdviceDate)
  5388. if check.ID > 0 {
  5389. advice.Checker = check.Modifier
  5390. advice.CheckState = 1
  5391. advice.CheckTime = time.Now().Unix()
  5392. }
  5393. }
  5394. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5395. if infor.ID > 0 {
  5396. var cha_time int64
  5397. timeNowStr := time.Now().Format("2006-01-02")
  5398. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5399. //今日的日期减去设置的日期
  5400. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5401. if cha_time >= advice.RecordDate {
  5402. //查询审核是否允许
  5403. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.RecordDate, adminUserInfo.Org.Id, 4)
  5404. //申请状态不允许的情况 拒绝修改
  5405. if infor.ApplicationStatus != 1 {
  5406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5407. return
  5408. }
  5409. }
  5410. }
  5411. err := service.CreateDoctorAdvice(&advice)
  5412. //记录日志
  5413. byterequest, _ := json.Marshal(advice)
  5414. adviceLog := models.XtDoctorAdviceLog{
  5415. UserOrgId: advice.UserOrgId,
  5416. PatientId: advice.PatientId,
  5417. AdminUserId: adminUserInfo.Org.Id,
  5418. Module: 1,
  5419. ErrLog: string(byterequest),
  5420. Status: 1,
  5421. Ctime: time.Now().Unix(),
  5422. Mtime: 0,
  5423. Source: "手机端新增医嘱",
  5424. RecordDate: advice.AdviceDate,
  5425. }
  5426. service.CreateDoctorAdviceLog(adviceLog)
  5427. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  5428. redis := service.RedisClient()
  5429. //清空key 值
  5430. redis.Set(key, "", time.Second)
  5431. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  5432. redis.Set(keyOne, "", time.Second)
  5433. defer redis.Close()
  5434. if err != nil {
  5435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5436. return
  5437. }
  5438. c.ServeSuccessJSON(map[string]interface{}{
  5439. "msg": "ok",
  5440. "advice": advice,
  5441. })
  5442. return
  5443. }
  5444. }
  5445. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  5446. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  5447. utils.ErrorLog("advice_name")
  5448. return enums.ErrorCodeParamWrong
  5449. }
  5450. adviceName, _ := json["advice_name"].(string)
  5451. if len(adviceName) == 0 {
  5452. utils.ErrorLog("len(advice_name) == 0")
  5453. return enums.ErrorCodeParamWrong
  5454. }
  5455. advice.AdviceName = adviceName
  5456. adviceDesc, _ := json["advice_desc"].(string)
  5457. advice.AdviceDesc = adviceDesc
  5458. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5459. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5460. advice.DrugSpec = drugSpec
  5461. }
  5462. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5463. remark, _ := json["remark"].(string)
  5464. advice.Remark = remark
  5465. }
  5466. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  5467. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  5468. // advice.Way = src_type
  5469. //}
  5470. if json["way"] == nil {
  5471. advice.Way = 0
  5472. } else {
  5473. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  5474. way := int64(json["way"].(float64))
  5475. advice.Way = way
  5476. }
  5477. }
  5478. if json["drug_id"] == nil {
  5479. advice.DrugId = 0
  5480. } else {
  5481. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  5482. drug_id := int64(json["drug_id"].(float64))
  5483. advice.DrugId = drug_id
  5484. }
  5485. }
  5486. if json["drug_name_id"] == nil {
  5487. advice.DrugNameId = 0
  5488. } else {
  5489. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  5490. drug_name_id := int64(json["drug_name_id"].(float64))
  5491. advice.DrugNameId = drug_name_id
  5492. }
  5493. }
  5494. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  5495. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  5496. advice.DrugSpecUnit = drugSpecUnit
  5497. }
  5498. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5499. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5500. advice.SingleDose = singleDose
  5501. }
  5502. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5503. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5504. advice.SingleDoseUnit = singleDoseUnit
  5505. }
  5506. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5507. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5508. advice.PrescribingNumber = prescribingNumber
  5509. }
  5510. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5511. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5512. advice.PrescribingNumberUnit = prescribingNumberUnit
  5513. }
  5514. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5515. deliveryWay, _ := json["delivery_way"].(string)
  5516. advice.DeliveryWay = deliveryWay
  5517. }
  5518. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5519. executionFrequency, _ := json["execution_frequency"].(string)
  5520. advice.ExecutionFrequency = executionFrequency
  5521. }
  5522. return 0
  5523. }
  5524. func (c *PatientApiController) DelDoctorAdvice() {
  5525. groupno, _ := c.GetInt64("groupno", -1)
  5526. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  5527. patient_id, _ := c.GetInt64("patient_id")
  5528. doc_advice_date, _ := c.GetInt64("advice_date")
  5529. redis := service.RedisClient()
  5530. if is_sub == 1 { //是
  5531. advice_id, _ := c.GetInt64("advice_id")
  5532. adminUserInfo := c.GetMobileAdminUserInfo()
  5533. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  5534. if advice.ID == 0 {
  5535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5536. return
  5537. }
  5538. advice.Status = 0
  5539. advice.UpdatedTime = time.Now().Unix()
  5540. advice.Modifier = adminUserInfo.AdminUser.Id
  5541. // 查询信息规挡的设置天数
  5542. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5543. if infor.ID > 0 && infor.WeekDay > 0 {
  5544. var cha_time int64
  5545. timeNowStr := time.Now().Format("2006-01-02")
  5546. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5547. //今日的日期减去设置的日期
  5548. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5549. if cha_time >= advice.AdviceDate {
  5550. //查询审核是否允许
  5551. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5552. //申请状态不允许的情况 拒绝修改
  5553. if infor.ApplicationStatus != 1 {
  5554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5555. return
  5556. }
  5557. }
  5558. }
  5559. //自备药
  5560. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5561. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5562. //查询库存是否是自备药
  5563. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  5564. if selfBasedrug.IsSelfDrug == 1 {
  5565. creater := adminUserInfo.AdminUser.Id
  5566. //退库
  5567. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  5568. }
  5569. }
  5570. err := service.DeleteDoctorAdvice(&advice)
  5571. //记录日志
  5572. byterequest, _ := json.Marshal(advice)
  5573. adviceLog := models.XtDoctorAdviceLog{
  5574. UserOrgId: advice.UserOrgId,
  5575. PatientId: advice.PatientId,
  5576. AdminUserId: adminUserInfo.AdminUser.Id,
  5577. Module: 4,
  5578. ErrLog: string(byterequest),
  5579. Status: 1,
  5580. Ctime: time.Now().Unix(),
  5581. Mtime: 0,
  5582. Source: "手机端删除医嘱",
  5583. RecordDate: advice.RecordDate,
  5584. }
  5585. service.CreateDoctorAdviceLog(adviceLog)
  5586. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5587. redis.Set(key, "", time.Second)
  5588. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5589. redis.Set(keyTwo, "", time.Second)
  5590. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5591. redis.Set(keyThree, "", time.Second)
  5592. redis.Close()
  5593. if err != nil {
  5594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5595. return
  5596. }
  5597. c.ServeSuccessJSON(map[string]interface{}{
  5598. "msg": "ok",
  5599. })
  5600. return
  5601. } else { //
  5602. var ids []string
  5603. if groupno == 0 {
  5604. advice_id := c.GetString("advice_id")
  5605. ids = strings.Split(advice_id, ",")
  5606. if len(ids) <= 0 {
  5607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5608. return
  5609. }
  5610. }
  5611. if groupno < 0 {
  5612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5613. return
  5614. }
  5615. adminUserInfo := c.GetMobileAdminUserInfo()
  5616. var advice models.DoctorAdvice
  5617. if groupno > 0 {
  5618. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  5619. if advice.ID == 0 {
  5620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5621. return
  5622. }
  5623. } else {
  5624. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  5625. for _, item := range advices {
  5626. if item.ID == 0 {
  5627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5628. return
  5629. }
  5630. }
  5631. }
  5632. advice.UpdatedTime = time.Now().Unix()
  5633. advice.Status = 0
  5634. advice.GroupNo = groupno
  5635. advice.Modifier = adminUserInfo.AdminUser.Id
  5636. var err error
  5637. if groupno > 0 {
  5638. // 查询信息规挡的设置天数
  5639. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5640. if infor.ID > 0 {
  5641. var cha_time int64
  5642. timeNowStr := time.Now().Format("2006-01-02")
  5643. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5644. //今日的日期减去设置的日期
  5645. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5646. if cha_time >= advice.AdviceDate {
  5647. //查询审核是否允许
  5648. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5649. //申请状态不允许的情况 拒绝修改
  5650. if infor.ApplicationStatus != 1 {
  5651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5652. return
  5653. }
  5654. }
  5655. }
  5656. //自备药
  5657. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5658. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5659. //查询库存是否是自备药
  5660. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
  5661. if selfBasedrug.IsSelfDrug == 1 {
  5662. creater := adminUserInfo.AdminUser.Id
  5663. //退库
  5664. service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
  5665. }
  5666. }
  5667. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  5668. //记录日志
  5669. byterequest, _ := json.Marshal(advice)
  5670. adviceLog := models.XtDoctorAdviceLog{
  5671. UserOrgId: advice.UserOrgId,
  5672. PatientId: advice.PatientId,
  5673. AdminUserId: adminUserInfo.AdminUser.Id,
  5674. Module: 4,
  5675. ErrLog: string(byterequest),
  5676. Status: 1,
  5677. Ctime: time.Now().Unix(),
  5678. Mtime: 0,
  5679. Source: "手机端删除医嘱",
  5680. RecordDate: advice.RecordDate,
  5681. }
  5682. service.CreateDoctorAdviceLog(adviceLog)
  5683. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5684. redis.Set(key, "", time.Second)
  5685. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5686. redis.Set(keyTwo, "", time.Second)
  5687. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5688. redis.Set(keyThree, "", time.Second)
  5689. } else {
  5690. // 查询信息规挡的设置天数
  5691. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5692. if infor.ID > 0 {
  5693. var cha_time int64
  5694. timeNowStr := time.Now().Format("2006-01-02")
  5695. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5696. //今日的日期减去设置的日期
  5697. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5698. if cha_time >= advice.AdviceDate {
  5699. //查询审核是否允许
  5700. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  5701. //申请状态不允许的情况 拒绝修改
  5702. if infor.ApplicationStatus != 1 {
  5703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5704. return
  5705. }
  5706. }
  5707. }
  5708. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  5709. advicelist, _ := service.GetBatchDoctorAdviceList(ids, adminUserInfo.Org.Id)
  5710. for _, item := range advicelist {
  5711. //自备药
  5712. selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
  5713. if selfPrescriptionOutOpenOne.IsOpen == 1 {
  5714. //查询库存是否是自备药
  5715. selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(item.DrugId, item.UserOrgId)
  5716. if selfBasedrug.IsSelfDrug == 1 {
  5717. creater := adminUserInfo.AdminUser.Id
  5718. //退库
  5719. service.SelfDrugAutoAddCancelInfoOne(item, creater)
  5720. }
  5721. }
  5722. //记录日志
  5723. byterequest, _ := json.Marshal(item)
  5724. adviceLog := models.XtDoctorAdviceLog{
  5725. UserOrgId: item.UserOrgId,
  5726. PatientId: item.PatientId,
  5727. AdminUserId: adminUserInfo.AdminUser.Id,
  5728. Module: 4,
  5729. ErrLog: string(byterequest),
  5730. Status: 1,
  5731. Ctime: time.Now().Unix(),
  5732. Mtime: 0,
  5733. Source: "手机端批量删除医嘱",
  5734. RecordDate: item.RecordDate,
  5735. }
  5736. service.CreateDoctorAdviceLog(adviceLog)
  5737. }
  5738. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  5739. redis.Set(key, "", time.Second)
  5740. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  5741. redis.Set(keyTwo, "", time.Second)
  5742. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  5743. redis.Set(keyThree, "", time.Second)
  5744. redis.Close()
  5745. }
  5746. if err != nil {
  5747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5748. return
  5749. }
  5750. c.ServeSuccessJSON(map[string]interface{}{
  5751. "msg": "ok",
  5752. })
  5753. return
  5754. }
  5755. }
  5756. // /m/api/advice/group/modify_starttime [post]
  5757. // @param group_no:int
  5758. // @param start_time:string yyyy-MM-dd hh:mm:ss
  5759. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  5760. group_no, _ := this.GetInt64("group_no")
  5761. start_time_str := this.GetString("start_time")
  5762. if group_no <= 0 || len(start_time_str) == 0 {
  5763. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5764. return
  5765. }
  5766. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  5767. if parseTimeErr != nil {
  5768. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  5769. return
  5770. }
  5771. adminUserInfo := this.GetMobileAdminUserInfo()
  5772. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  5773. if updateStartTimeErr != nil {
  5774. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  5775. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5776. return
  5777. }
  5778. this.ServeSuccessJSON(map[string]interface{}{
  5779. "start_time": startTime.Unix(),
  5780. })
  5781. }
  5782. func (this *PatientApiController) DelSubDoctorAdvice() {
  5783. advice_id, _ := this.GetInt64("advice_id")
  5784. adminUserInfo := this.GetMobileAdminUserInfo()
  5785. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  5786. if advice.ID == 0 {
  5787. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  5788. return
  5789. }
  5790. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  5791. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  5792. // return
  5793. //}
  5794. advice.Status = 0
  5795. advice.UpdatedTime = time.Now().Unix()
  5796. advice.Modifier = adminUserInfo.AdminUser.Id
  5797. err := service.DeleteDoctorAdvice(&advice)
  5798. if err != nil {
  5799. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  5800. return
  5801. }
  5802. this.ServeSuccessJSON(map[string]interface{}{
  5803. "msg": "ok",
  5804. })
  5805. return
  5806. }
  5807. func (this *PatientApiController) GetAdviceUnReadMessage() {
  5808. //adminUserInfo := this.GetMobileAdminUserInfo()
  5809. //service.FindUnReadDoctorAdviceMessage()
  5810. }
  5811. func (this *PatientApiController) GetPatientsByKeyWord() {
  5812. keyWord := this.GetString("keyword")
  5813. adminUserInfo := this.GetMobileAdminUserInfo()
  5814. today := utils.ZeroHourTimeOfDay(time.Now())
  5815. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  5816. if err != nil {
  5817. utils.ErrorLog(err.Error())
  5818. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5819. return
  5820. }
  5821. this.ServeSuccessJSON(map[string]interface{}{
  5822. "patient": patient,
  5823. })
  5824. }
  5825. func (this *PatientApiController) GetSearchPatient() {
  5826. keyWord := this.GetString("keyword")
  5827. adminUserInfo := this.GetMobileAdminUserInfo()
  5828. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  5829. if err != nil {
  5830. utils.ErrorLog(err.Error())
  5831. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5832. return
  5833. }
  5834. this.ServeSuccessJSON(map[string]interface{}{
  5835. "patient": patient,
  5836. })
  5837. }
  5838. func (c *PatientApiController) ExecProject() {
  5839. execution_time := c.GetString("execution_time")
  5840. project_id, _ := c.GetInt64("project_id")
  5841. team_id, _ := c.GetInt64("team_id")
  5842. is_check_team, _ := c.GetInt64("is_check_team")
  5843. record_date, _ := c.GetInt64("record_date")
  5844. patient_id, _ := c.GetInt64("patient_id")
  5845. if len(execution_time) <= 0 {
  5846. utils.ErrorLog("execution_time")
  5847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5848. return
  5849. }
  5850. timeLayout2 := "2006-01-02 15:04:05"
  5851. loc, _ := time.LoadLocation("Local")
  5852. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  5853. if errs != nil {
  5854. utils.ErrorLog(errs.Error())
  5855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5856. return
  5857. }
  5858. adminInfo := c.GetMobileAdminUserInfo()
  5859. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  5860. //针对舒和
  5861. if adminInfo.Org.Id == 10644 {
  5862. if project.StartTime > theTime.Unix() {
  5863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  5864. return
  5865. }
  5866. }
  5867. if project.Type == 3 {
  5868. good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
  5869. if good.IsUser != 1 {
  5870. //查询开关是否开启
  5871. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  5872. //开关已经开启
  5873. if stockSetting.IsType == 1 {
  5874. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  5875. scheduleDateStart := theTime.Format("2006-01-02")
  5876. timeLayout3 := "2006-01-02"
  5877. loc, _ := time.LoadLocation("Local")
  5878. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  5879. //查询该耗材是否已经出库
  5880. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  5881. if auto.ID == 0 {
  5882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  5883. return
  5884. }
  5885. }
  5886. }
  5887. if good.IsUser == 1 && good.IsWarehouse == 1 {
  5888. //查询开关是否开启
  5889. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  5890. //开关已经开启
  5891. if stockSetting.IsType == 1 {
  5892. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  5893. scheduleDateStart := theTime.Format("2006-01-02")
  5894. timeLayout3 := "2006-01-02"
  5895. loc, _ := time.LoadLocation("Local")
  5896. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  5897. //查询该耗材是否已经出库
  5898. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  5899. if auto.ID == 0 {
  5900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  5901. return
  5902. }
  5903. }
  5904. }
  5905. }
  5906. if project.ExecutionState == 1 {
  5907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  5908. return
  5909. }
  5910. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  5911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  5912. return
  5913. }
  5914. project.ExecutionState = 1
  5915. project.ExecutionStaff = adminInfo.AdminUser.Id
  5916. project.ExecutionTime = theTime.Unix()
  5917. if team_id == 0 {
  5918. // 查询信息规挡的设置天数
  5919. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5920. if infor.ID > 0 {
  5921. var cha_time int64
  5922. timeNowStr := time.Now().Format("2006-01-02")
  5923. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5924. //今日的日期减去设置的日期
  5925. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5926. if cha_time >= project.RecordDate {
  5927. //查询审核是否允许
  5928. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5929. //申请状态不允许的情况 拒绝修改
  5930. if infor.ApplicationStatus != 1 {
  5931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5932. return
  5933. }
  5934. }
  5935. }
  5936. err := service.SaveHisProject(&project)
  5937. if err == nil {
  5938. c.ServeSuccessJSON(map[string]interface{}{
  5939. "project": project,
  5940. })
  5941. } else {
  5942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5943. return
  5944. }
  5945. } else {
  5946. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  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. err := service.SaveHisProject(&project)
  5966. if err == nil {
  5967. c.ServeSuccessJSON(map[string]interface{}{
  5968. "project": project,
  5969. })
  5970. } else {
  5971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5972. return
  5973. }
  5974. } else {
  5975. // 查询信息规挡的设置天数
  5976. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5977. if infor.ID > 0 {
  5978. var cha_time int64
  5979. timeNowStr := time.Now().Format("2006-01-02")
  5980. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5981. //今日的日期减去设置的日期
  5982. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5983. if cha_time >= project.RecordDate {
  5984. //查询审核是否允许
  5985. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5986. //申请状态不允许的情况 拒绝修改
  5987. if infor.ApplicationStatus != 1 {
  5988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5989. return
  5990. }
  5991. }
  5992. }
  5993. ps, _ := service.GetCheckTeamProjectOne(team_id, patient_id, record_date, adminInfo.Org.Id)
  5994. var ids []int64
  5995. for _, items := range ps {
  5996. ids = append(ids, items.ID)
  5997. }
  5998. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  5999. if err == nil {
  6000. c.ServeSuccessJSON(map[string]interface{}{
  6001. "project": project,
  6002. })
  6003. } else {
  6004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6005. return
  6006. }
  6007. }
  6008. }
  6009. }
  6010. func (c *PatientApiController) CheckProject() {
  6011. adminInfo := c.GetMobileAdminUserInfo()
  6012. project_id, _ := c.GetInt64("project_id")
  6013. team_id, _ := c.GetInt64("team_id")
  6014. is_check_team, _ := c.GetInt64("is_check_team")
  6015. record_date, _ := c.GetInt64("record_date")
  6016. patient_id, _ := c.GetInt64("patient_id")
  6017. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  6018. if project.CheckState == 1 {
  6019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  6020. return
  6021. }
  6022. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  6023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  6024. return
  6025. }
  6026. project.Checker = adminInfo.AdminUser.Id
  6027. project.CheckTime = time.Now().Unix()
  6028. project.CheckState = 1
  6029. if team_id == 0 {
  6030. // 查询信息规挡的设置天数
  6031. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  6032. if infor.ID > 0 {
  6033. var cha_time int64
  6034. timeNowStr := time.Now().Format("2006-01-02")
  6035. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6036. //今日的日期减去设置的日期
  6037. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6038. if cha_time >= project.RecordDate {
  6039. //查询审核是否允许
  6040. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  6041. //申请状态不允许的情况 拒绝修改
  6042. if infor.ApplicationStatus != 1 {
  6043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6044. return
  6045. }
  6046. }
  6047. }
  6048. err := service.SaveHisProject(&project)
  6049. if err == nil {
  6050. c.ServeSuccessJSON(map[string]interface{}{
  6051. "msg": "ok",
  6052. "project": project,
  6053. })
  6054. } else {
  6055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6056. return
  6057. }
  6058. } else {
  6059. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  6060. // 查询信息规挡的设置天数
  6061. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  6062. if infor.ID > 0 {
  6063. var cha_time int64
  6064. timeNowStr := time.Now().Format("2006-01-02")
  6065. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6066. //今日的日期减去设置的日期
  6067. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6068. if cha_time >= project.RecordDate {
  6069. //查询审核是否允许
  6070. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  6071. //申请状态不允许的情况 拒绝修改
  6072. if infor.ApplicationStatus != 1 {
  6073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6074. return
  6075. }
  6076. }
  6077. }
  6078. err := service.SaveHisProject(&project)
  6079. if err == nil {
  6080. c.ServeSuccessJSON(map[string]interface{}{
  6081. "msg": "ok",
  6082. "project": project,
  6083. })
  6084. } else {
  6085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6086. return
  6087. }
  6088. } else {
  6089. // 查询信息规挡的设置天数
  6090. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  6091. if infor.ID > 0 {
  6092. var cha_time int64
  6093. timeNowStr := time.Now().Format("2006-01-02")
  6094. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6095. //今日的日期减去设置的日期
  6096. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6097. if cha_time >= project.RecordDate {
  6098. //查询审核是否允许
  6099. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  6100. //申请状态不允许的情况 拒绝修改
  6101. if infor.ApplicationStatus != 1 {
  6102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6103. return
  6104. }
  6105. }
  6106. }
  6107. ps, _ := service.GetCheckTeamProjectOne(team_id, patient_id, record_date, adminInfo.Org.Id)
  6108. var ids []int64
  6109. for _, items := range ps {
  6110. ids = append(ids, items.ID)
  6111. }
  6112. err := service.UpdateTeamProjectCheckStatus(ids, patient_id, record_date, adminInfo.Org.Id, adminInfo.AdminUser.Id, time.Now().Unix())
  6113. if err == nil {
  6114. c.ServeSuccessJSON(map[string]interface{}{
  6115. "project": project,
  6116. })
  6117. } else {
  6118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6119. return
  6120. }
  6121. }
  6122. }
  6123. }